Commit f0f69a97 authored by manojmj's avatar manojmj

Adds API tests

parent a608560a
{
"type": "object",
"required" : [
"forks",
"issues",
"merge_requests",
"notes",
"snippets",
"ssh_keys",
"milestones",
"users",
"projects",
"groups",
"active_users"
],
"properties" : {
"forks": { "type": "string" },
"issues'": { "type": "string" },
"merge_requests'": { "type": "string" },
"notes'": { "type": "string" },
"snippets'": { "type": "string" },
"ssh_keys'": { "type": "string" },
"milestones'": { "type": "string" },
"users'": { "type": "string" },
"projects'": { "type": "string" },
"groups'": { "type": "string" },
"active_users'": { "type": "string" }
}
}
require 'spec_helper'
describe API::Statistics, 'Statistics' do
let(:path) { "/application/statistics" }
describe "GET /application/statistics" do
context 'when no user' do
it "returns authentication error" do
get api(path, nil)
expect(response).to have_gitlab_http_status(401)
end
end
context "when not an admin" do
let(:user) { create(:user) }
it "returns forbidden error" do
get api(path, user)
expect(response).to have_gitlab_http_status(403)
end
end
context 'when authenticated as admin' do
let(:admin) { create(:admin) }
it 'matches the response schema' do
get api(path, admin)
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('statistics')
end
it 'gives the right statistics' do
projects = create_list(:project, 4, namespace: create(:namespace, owner: admin))
issues = create_list(:issue, 2, project: projects.first, updated_by: admin)
create_list(:group, 2)
create_list(:snippet, 2, :public, author: admin)
create_list(:note, 2, author: admin, project: projects.first, noteable: issues.first)
create_list(:milestone, 3, project: projects.first)
create(:key, user: admin)
create(:merge_request, source_project: projects.first)
get api(path, admin)
expect(json_response['issues']).to eq('2')
expect(json_response['merge_requests']).to eq('1')
expect(json_response['notes']).to eq('2')
expect(json_response['snippets']).to eq('2')
expect(json_response['forks']).to eq('0')
expect(json_response['ssh_keys']).to eq('1')
expect(json_response['milestones']).to eq('3')
expect(json_response['users']).to eq('1')
expect(json_response['projects']).to eq('4')
expect(json_response['groups']).to eq('2')
expect(json_response['active_users']).to eq('1')
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