debian-mirror-gitlab/spec/requests/api/user_counts_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
2.2 KiB
Ruby
Raw Normal View History

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
2021-10-27 15:23:28 +05:30
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-09-30 21:07:59 +05:30
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
2021-10-27 15:23:28 +05:30
it 'returns assigned issue counts for current_user' do
2019-09-30 21:07:59 +05:30
get api('/user_counts', user)
2021-10-27 15:23:28 +05:30
expect(json_response['assigned_issues']).to eq(1)
2019-09-30 21:07:59 +05:30
end
2021-10-27 15:23:28 +05:30
context 'merge requests' do
it 'returns assigned MR counts for current user' do
get api('/user_counts', user)
2019-09-30 21:07:59 +05:30
2021-10-27 15:23:28 +05:30
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-07-16 23:28:13 +05:30
expect(json_response['attention_requests']).to eq(0)
2022-05-07 20:08:51 +05:30
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-10-27 15:23:28 +05:30
end
end
it 'returns pending todo counts for current_user' do
2019-09-30 21:07:59 +05:30
get api('/user_counts', user)
2021-10-27 15:23:28 +05:30
expect(json_response['todos']).to eq(1)
2019-09-30 21:07:59 +05:30
end
end
end
end