Commit 76ef0094 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Use schemas to test github endpoints response

parent 40cdfc12
{
"type": "array",
"properties" : {
"name": { "type": "string" },
"commit": {
"type": "object",
"required": ["sha", "type"],
"properties" : {
"sha": { "type": "string" },
"type": { "type": "string" }
},
"additionalProperties": false
},
"additionalProperties": false
}
}
{
"type": "object",
"properties" : {
"sha": { "type": "string" },
"parents": {
"type": "array",
"properties": {
"sha": { "type": "string" }
},
"additionalProperties": false
},
"author": {
"type": "object",
"required": ["login", "email"],
"properties" : {
"login": { "type": ["string", "null"] },
"email": { "type": "string" }
},
"additionalProperties": false
},
"committer": {
"type": "object",
"required": ["login", "email"],
"properties" : {
"login": { "type": ["string", "null"] },
"email": { "type": "string" }
},
"additionalProperties": false
},
"commit": {
"type": "object",
"properties": {
"message": { "type": "string" },
"author": {
"type": "object",
"required": ["name", "email", "date", "type"],
"properties" : {
"name": { "type": "string" },
"email": { "type": "string" },
"date": { "type": "date" },
"type": { "type": "string" }
},
"additionalProperties": false
},
"committer": {
"type": "object",
"required": ["name", "email", "date", "type"],
"properties" : {
"name": { "type": "string" },
"email": { "type": "string" },
"date": { "type": "date" },
"type": { "type": "string" }
},
"additionalProperties": false
},
"additionalProperties": false
}
},
"additionalProperties": false
}
}
{
"type": "array",
"properties" : {
"id": { "type": "integer" },
"name": { "type": "string" },
"owner": {
"type": "object",
"required": ["login"],
"properties" : {
"login": { "type": "string" }
},
"additionalProperties": false
},
"additionalProperties": false
}
}
...@@ -38,7 +38,7 @@ describe API::V3::Github do ...@@ -38,7 +38,7 @@ describe API::V3::Github do
end end
end end
describe 'GET /users/:id/repos' do describe 'GET /users/:namespace/repos' do
context 'authenticated' do context 'authenticated' do
it 'returns an array of projects with github format' do it 'returns an array of projects with github format' do
stub_licensed_features(jira_dev_panel_integration: true) stub_licensed_features(jira_dev_panel_integration: true)
...@@ -54,10 +54,7 @@ describe API::V3::Github do ...@@ -54,10 +54,7 @@ describe API::V3::Github do
expect(json_response).to be_an(Array) expect(json_response).to be_an(Array)
expect(json_response.size).to eq(2) expect(json_response.size).to eq(2)
expect(json_response.first.keys).to contain_exactly('id', 'owner', 'name') expect(response).to match_response_schema('entities/github/repositories')
expect(json_response.first['owner'].keys).to contain_exactly('login')
expect(json_response.second.keys).to contain_exactly('id', 'owner', 'name')
expect(json_response.second['owner'].keys).to contain_exactly('login')
end end
end end
...@@ -98,8 +95,8 @@ describe API::V3::Github do ...@@ -98,8 +95,8 @@ describe API::V3::Github do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an(Array) expect(json_response).to be_an(Array)
expect(json_response.first.keys).to contain_exactly('name', 'commit')
expect(json_response.first['commit'].keys).to contain_exactly('sha', 'type') expect(response).to match_response_schema('entities/github/branches')
end end
end end
...@@ -136,28 +133,8 @@ describe API::V3::Github do ...@@ -136,28 +133,8 @@ describe API::V3::Github do
get v3_api("/repos/#{project.namespace.path}/#{project.path}/commits/#{commit_id}", user) get v3_api("/repos/#{project.namespace.path}/#{project.path}/commits/#{commit_id}", user)
commit_author = {
'name' => commit.author_name,
'email' => commit.author_email,
'date' => commit.authored_date.iso8601,
'type' => 'User'
}
commit_committer = {
'name' => commit.committer_name,
'email' => commit.committer_email,
'date' => commit.committed_date.iso8601,
'type' => 'User'
}
parent_commits = commit.parent_ids.map { |id| { 'sha' => id } }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['sha']).to eq(commit.id) expect(response).to match_response_schema('entities/github/commit')
expect(json_response['parents']).to eq(parent_commits)
expect(json_response.dig('commit', 'author')).to eq(commit_author)
expect(json_response.dig('commit', 'committer')).to eq(commit_committer)
expect(json_response.dig('commit', 'message')).to eq(commit.safe_message)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment