debian-mirror-gitlab/spec/serializers/member_entity_spec.rb

107 lines
3.1 KiB
Ruby
Raw Normal View History

2021-03-08 18:12:59 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe MemberEntity do
let_it_be(:current_user) { create(:user) }
2021-04-29 21:17:54 +05:30
2021-03-11 19:13:27 +05:30
let(:entity) { described_class.new(member, { current_user: current_user, group: group, source: source }) }
2021-03-08 18:12:59 +05:30
let(:entity_hash) { entity.as_json }
shared_examples 'member.json' do
it 'matches json schema' do
expect(entity.to_json).to match_schema('entities/member')
end
it 'correctly exposes `can_update`' do
allow(member).to receive(:can_update?).and_return(true)
expect(entity_hash[:can_update]).to be(true)
end
it 'correctly exposes `can_remove`' do
allow(member).to receive(:can_remove?).and_return(true)
expect(entity_hash[:can_remove]).to be(true)
end
end
shared_examples 'invite' do
it 'correctly exposes `invite.avatar_url`' do
avatar_url = 'https://www.gravatar.com/avatar/c4637cb869d5f94c3193bde4f23d4cdc?s=80&d=identicon'
allow(entity).to receive(:avatar_icon_for_email).with(member.invite_email, Member::AVATAR_SIZE).and_return(avatar_url)
expect(entity_hash[:invite][:avatar_url]).to match(avatar_url)
end
it 'correctly exposes `invite.can_resend`' do
allow(member).to receive(:can_resend_invite?).and_return(true)
expect(entity_hash[:invite][:can_resend]).to be(true)
end
end
2021-03-11 19:13:27 +05:30
shared_examples 'is_direct_member' do
context 'when `source` is the same as `member.source`' do
let(:source) { direct_member_source }
it 'exposes `is_direct_member` as `true`' do
expect(entity_hash[:is_direct_member]).to be(true)
end
end
context 'when `source` is not the same as `member.source`' do
let(:source) { inherited_member_source }
it 'exposes `is_direct_member` as `false`' do
expect(entity_hash[:is_direct_member]).to be(false)
end
end
end
2021-03-08 18:12:59 +05:30
context 'group member' do
let(:group) { create(:group) }
2021-03-11 19:13:27 +05:30
let(:source) { group }
2021-03-08 18:12:59 +05:30
let(:member) { GroupMemberPresenter.new(create(:group_member, group: group), current_user: current_user) }
it_behaves_like 'member.json'
context 'invite' do
let(:member) { GroupMemberPresenter.new(create(:group_member, :invited, group: group), current_user: current_user) }
it_behaves_like 'member.json'
it_behaves_like 'invite'
end
2021-03-11 19:13:27 +05:30
context 'is_direct_member' do
let(:direct_member_source) { group }
let(:inherited_member_source) { create(:group) }
it_behaves_like 'is_direct_member'
end
2021-03-08 18:12:59 +05:30
end
context 'project member' do
let(:project) { create(:project) }
let(:group) { project.group }
2021-03-11 19:13:27 +05:30
let(:source) { project }
2021-03-08 18:12:59 +05:30
let(:member) { ProjectMemberPresenter.new(create(:project_member, project: project), current_user: current_user) }
it_behaves_like 'member.json'
context 'invite' do
let(:member) { ProjectMemberPresenter.new(create(:project_member, :invited, project: project), current_user: current_user) }
it_behaves_like 'member.json'
it_behaves_like 'invite'
end
2021-03-11 19:13:27 +05:30
context 'is_direct_member' do
let(:direct_member_source) { project }
let(:inherited_member_source) { group }
it_behaves_like 'is_direct_member'
end
2021-03-08 18:12:59 +05:30
end
end