2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe NoteEntity do
|
2018-03-17 18:26:18 +05:30
|
|
|
include Gitlab::Routing
|
|
|
|
|
|
|
|
let(:request) { double('request', current_user: user, noteable: note.noteable) }
|
|
|
|
|
|
|
|
let(:entity) { described_class.new(note, request: request) }
|
|
|
|
let(:note) { create(:note) }
|
|
|
|
let(:user) { create(:user) }
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
subject { entity.as_json }
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
it_behaves_like 'note entity'
|
2023-07-09 08:55:56 +05:30
|
|
|
|
|
|
|
shared_examples 'external author' do
|
|
|
|
context 'when anonymous' do
|
|
|
|
let(:user) { nil }
|
|
|
|
|
|
|
|
it { is_expected.to eq(obfuscated_email) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with signed in user' do
|
|
|
|
before do
|
|
|
|
stub_member_access_level(note.project, access_level => user) if access_level
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has no role in project' do
|
|
|
|
let(:access_level) { nil }
|
|
|
|
|
|
|
|
it { is_expected.to eq(obfuscated_email) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has guest role in project' do
|
|
|
|
let(:access_level) { :guest }
|
|
|
|
|
|
|
|
it { is_expected.to eq(obfuscated_email) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has reporter role in project' do
|
|
|
|
let(:access_level) { :reporter }
|
|
|
|
|
|
|
|
it { is_expected.to eq(email) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has developer role in project' do
|
|
|
|
let(:access_level) { :developer }
|
|
|
|
|
|
|
|
it { is_expected.to eq(email) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with email participant' do
|
|
|
|
let_it_be(:note) { create(:note) }
|
|
|
|
let_it_be(:note_metadata) { create(:note_metadata, note: note) }
|
|
|
|
|
|
|
|
subject { entity.as_json[:external_author] }
|
|
|
|
|
|
|
|
context 'when external_note_author_service_desk feature flag is enabled' do
|
|
|
|
let(:obfuscated_email) { 'em*****@e*****.c**' }
|
|
|
|
let(:email) { 'email@example.com' }
|
|
|
|
|
|
|
|
it_behaves_like 'external author'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when external_note_author_service_desk feature flag is disabled' do
|
|
|
|
let(:email) { nil }
|
|
|
|
let(:obfuscated_email) { nil }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_feature_flags(external_note_author_service_desk: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'external author'
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|