2019-09-30 05:06:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe MergeRequestUserEntity do
|
2021-03-01 13:11:21 -05:00
|
|
|
let_it_be(:user) { create(:user) }
|
2021-11-08 01:09:59 -05:00
|
|
|
let_it_be(:merge_request) { create(:merge_request, assignees: [user]) }
|
2021-04-14 11:09:04 -04:00
|
|
|
|
2021-03-01 13:11:21 -05:00
|
|
|
let(:request) { EntityRequest.new(project: merge_request.target_project, current_user: user) }
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
let(:entity) do
|
2021-03-01 13:11:21 -05:00
|
|
|
described_class.new(user, request: request, merge_request: merge_request)
|
2018-06-21 08:22:40 -04:00
|
|
|
end
|
|
|
|
|
2021-03-01 13:11:21 -05:00
|
|
|
describe '#as_json' do
|
2018-06-21 08:22:40 -04:00
|
|
|
subject { entity.as_json }
|
|
|
|
|
|
|
|
it 'exposes needed attributes' do
|
2021-03-01 13:11:21 -05:00
|
|
|
is_expected.to include(
|
|
|
|
:id, :name, :username, :state, :avatar_url, :web_url,
|
2022-08-09 20:09:11 -04:00
|
|
|
:can_merge, :can_update_merge_request, :reviewed, :approved
|
2021-03-01 13:11:21 -05:00
|
|
|
)
|
2018-06-21 08:22:40 -04:00
|
|
|
end
|
2021-01-28 13:09:27 -05:00
|
|
|
|
|
|
|
context 'when `status` is not preloaded' do
|
|
|
|
it 'does not expose the availability attribute' do
|
|
|
|
expect(subject).not_to include(:availability)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-01 13:11:21 -05:00
|
|
|
context 'when the user has not approved the merge-request' do
|
|
|
|
it 'exposes that the user has not approved the MR' do
|
|
|
|
expect(subject).to include(approved: false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user has approved the merge-request' do
|
|
|
|
before do
|
|
|
|
merge_request.approvals.create!(user: user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes that the user has approved the MR' do
|
|
|
|
expect(subject).to include(approved: true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-28 13:09:27 -05:00
|
|
|
context 'when `status` is preloaded' do
|
|
|
|
before do
|
|
|
|
user.create_status!(availability: :busy)
|
|
|
|
|
|
|
|
user.status # make sure `status` is loaded
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes the availibility attribute' do
|
|
|
|
expect(subject[:availability]).to eq('busy')
|
|
|
|
end
|
|
|
|
end
|
2021-03-01 13:11:21 -05:00
|
|
|
|
|
|
|
describe 'performance' do
|
|
|
|
let_it_be(:user_a) { create(:user) }
|
|
|
|
let_it_be(:user_b) { create(:user) }
|
|
|
|
let_it_be(:merge_request_b) { create(:merge_request) }
|
|
|
|
|
|
|
|
it 'is linear in the number of merge requests' do
|
|
|
|
pending "See: https://gitlab.com/gitlab-org/gitlab/-/issues/322549"
|
|
|
|
baseline = ActiveRecord::QueryRecorder.new do
|
|
|
|
ent = described_class.new(user_a, request: request, merge_request: merge_request)
|
|
|
|
ent.as_json
|
|
|
|
end
|
|
|
|
|
|
|
|
expect do
|
|
|
|
a = described_class.new(user_a, request: request, merge_request: merge_request_b)
|
|
|
|
b = described_class.new(user_b, request: request, merge_request: merge_request_b)
|
|
|
|
|
|
|
|
a.as_json
|
|
|
|
b.as_json
|
|
|
|
end.not_to exceed_query_limit(baseline)
|
|
|
|
end
|
|
|
|
end
|
2018-06-21 08:22:40 -04:00
|
|
|
end
|
|
|
|
end
|