2019-09-30 21:07:59 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe API::UserCounts do
|
2019-09-30 21:07:59 +05:30
|
|
|
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-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authenticated' do
|
|
|
|
it 'returns open counts for current user' do
|
|
|
|
get api('/user_counts', user)
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-30 21:07:59 +05:30
|
|
|
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-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-30 21:07:59 +05:30
|
|
|
expect(json_response).to be_a Hash
|
|
|
|
expect(json_response['merge_requests']).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|