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.

55 lines
1.7 KiB
Ruby
Raw Permalink Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe API::UserCounts, feature_category: :service_ping 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
2023-01-13 00:05:48 +05:30
it 'returns assigned MR counts for current user' do
get api('/user_counts', user)
2019-09-30 21:07:59 +05:30
2023-01-13 00:05:48 +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
2021-10-27 15:23:28 +05:30
2023-01-13 00:05:48 +05:30
it 'updates the mr count when a new mr is assigned' do
create(:merge_request, source_project: project, author: user, assignees: [user])
2021-10-27 15:23:28 +05:30
2023-01-13 00:05:48 +05:30
get api('/user_counts', user)
2021-10-27 15:23:28 +05:30
2023-01-13 00:05:48 +05:30
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_a Hash
expect(json_response['merge_requests']).to eq(2)
2021-10-27 15:23:28 +05:30
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