2019-07-09 08:44:19 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 06:09:01 +00:00
|
|
|
RSpec.describe API::UserCounts do
|
2021-07-30 21:10:15 +00:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, :public) }
|
|
|
|
let_it_be(:issue) { create(:issue, project: project, author: user, assignees: [user]) }
|
|
|
|
let_it_be(:todo) { create(:todo, :pending, user: user, project: project) }
|
2019-07-09 08:44:19 +00:00
|
|
|
|
|
|
|
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 21:08:05 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2019-07-09 08:44:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authenticated' do
|
2021-07-30 21:10:15 +00:00
|
|
|
it 'returns assigned issue counts for current_user' do
|
2019-07-09 08:44:19 +00:00
|
|
|
get api('/user_counts', user)
|
|
|
|
|
2021-07-30 21:10:15 +00:00
|
|
|
expect(json_response['assigned_issues']).to eq(1)
|
2019-07-09 08:44:19 +00:00
|
|
|
end
|
|
|
|
|
2021-07-30 21:10:15 +00:00
|
|
|
context 'merge requests' do
|
|
|
|
it 'returns assigned MR counts for current user' do
|
|
|
|
get api('/user_counts', user)
|
2019-07-09 08:44:19 +00:00
|
|
|
|
2021-07-30 21:10:15 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
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)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(json_response).to be_a Hash
|
|
|
|
expect(json_response['merge_requests']).to eq(2)
|
2022-03-02 09:13:50 +00:00
|
|
|
expect(json_response['attention_requests']).to eq(2)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'mr_attention_requests is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(mr_attention_requests: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include attention_requests count' do
|
|
|
|
create(:merge_request, source_project: project, author: user, assignees: [user])
|
|
|
|
|
|
|
|
get api('/user_counts', user)
|
|
|
|
|
|
|
|
expect(json_response.key?('attention_requests')).to be(false)
|
|
|
|
end
|
2021-07-30 21:10:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns pending todo counts for current_user' do
|
2019-07-09 08:44:19 +00:00
|
|
|
get api('/user_counts', user)
|
|
|
|
|
2021-07-30 21:10:15 +00:00
|
|
|
expect(json_response['todos']).to eq(1)
|
2019-07-09 08:44:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|