1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Query.note(id)', feature_category: :team_planning do
include GraphqlHelpers
let_it_be(:current_user) { create(:user) }
let_it_be(:reporter_user) { create(:user) }
let_it_be(:project) { create(:project, :private, reporters: reporter_user) }
let_it_be(:issue) { create(:issue, project: project) }
let_it_be(:note) { create(:note, noteable: issue, project: project) }
let_it_be(:system_note) { create(:note, :system, noteable: issue, project: project) }
let(:note_params) { { 'id' => global_id_of(note) } }
let(:note_data) { graphql_data['note'] }
let(:note_fields) { all_graphql_fields_for('Note'.classify) }
let(:query) do
graphql_query_for('note', note_params, note_fields)
end
it_behaves_like 'a working graphql query' do
before do
post_graphql(query, current_user: current_user)
end
end
context 'when the user does not have access to read the note' do
it 'returns nil' do
post_graphql(query, current_user: current_user)
expect(note_data).to be nil
end
context 'when it is a system note' do
let(:note_params) { { 'id' => global_id_of(system_note) } }
it 'returns nil' do
post_graphql(query, current_user: current_user)
expect(note_data).to be nil
end
end
end
context 'when the user has access to read the note' do
before_all do
project.add_guest(current_user)
end
it 'returns note' do
post_graphql(query, current_user: current_user)
expect(note_data['id']).to eq(global_id_of(note).to_s)
end
context 'when it is a system note' do
let(:note_params) { { 'id' => global_id_of(system_note) } }
it 'returns note' do
post_graphql(query, current_user: current_user)
expect(note_data['id']).to eq(global_id_of(system_note).to_s)
end
context 'with issue_email_participants action' do
let_it_be(:email) { 'user@example.com' }
let_it_be(:note_text) { "added #{email}" }
let_it_be(:issue_email_participants_system_note) do
create(:note, :system,
project: project, noteable: issue, author: Users::Internal.support_bot, note: note_text)
end
let_it_be(:system_note_metadata) do
create(:system_note_metadata, note: issue_email_participants_system_note, action: :issue_email_participants)
end
let(:obfuscated_email) { 'us*****@e*****.c**' }
let(:note_params) { { 'id' => global_id_of(issue_email_participants_system_note) } }
it 'returns obfuscated email' do
post_graphql(query, current_user: current_user)
expect(note_data['id']).to eq(global_id_of(issue_email_participants_system_note).to_s)
expect(note_data['body']).to include(obfuscated_email)
expect(note_data['bodyHtml']).to include(obfuscated_email)
end
context 'when user has at least the reporter role in project' do
it 'returns email' do
post_graphql(query, current_user: reporter_user)
expect(note_data['id']).to eq(global_id_of(issue_email_participants_system_note).to_s)
expect(note_data['body']).to include(email)
expect(note_data['bodyHtml']).to include(email)
end
end
end
end
context 'and notes widget is not available' do
before do
WorkItems::Type.default_by_type(:issue).widget_definitions
.find_by_widget_type(:notes).update!(disabled: true)
end
it 'returns nil' do
post_graphql(query, current_user: current_user)
expect(note_data).to be nil
end
end
context 'when note is internal' do
let_it_be(:note) { create(:note, :confidential, noteable: issue, project: project) }
it 'returns nil' do
post_graphql(query, current_user: current_user)
expect(note_data).to be nil
end
context 'and user can read confidential notes' do
let_it_be(:developer) { create(:user) }
before do
project.add_developer(developer)
end
it 'returns note' do
post_graphql(query, current_user: developer)
expect(note_data['id']).to eq(global_id_of(note).to_s)
end
end
end
end
end
|