2019-07-09 04:44:19 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe API::UserCounts do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
|
|
|
|
let!(:merge_request) { create(:merge_request, :simple, author: user, assignees: [user], source_project: project, title: "Test") }
|
|
|
|
|
|
|
|
describe 'GET /user_counts' do
|
|
|
|
context 'when unauthenticated' do
|
|
|
|
it 'returns authentication error' do
|
|
|
|
get api('/user_counts')
|
|
|
|
|
2020-03-31 17:08:05 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2019-07-09 04:44:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authenticated' do
|
|
|
|
it 'returns open counts for current user' do
|
|
|
|
get api('/user_counts', user)
|
|
|
|
|
2020-03-31 17:08:05 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-07-09 04:44:19 -04:00
|
|
|
expect(json_response).to be_a Hash
|
|
|
|
expect(json_response['merge_requests']).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates the mr count when a new mr is assigned' do
|
|
|
|
create(:merge_request, source_project: project, author: user, assignees: [user])
|
|
|
|
|
|
|
|
get api('/user_counts', user)
|
|
|
|
|
2020-03-31 17:08:05 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-07-09 04:44:19 -04:00
|
|
|
expect(json_response).to be_a Hash
|
|
|
|
expect(json_response['merge_requests']).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|