2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Email::Handler::CreateNoteHandler do
|
2016-09-13 17:45:13 +05:30
|
|
|
include_context :email_shared_context
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, :public, :repository) }
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
let(:noteable) { note.noteable }
|
|
|
|
let(:note) { create(:diff_note_on_merge_request, project: project) }
|
|
|
|
let(:email_raw) { fixture_file('emails/valid_reply.eml') }
|
2021-03-08 18:12:59 +05:30
|
|
|
let!(:sent_notification) do
|
|
|
|
SentNotification.record_note(note, user.id, mail_key)
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it_behaves_like :reply_processing_shared_examples
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it_behaves_like :note_handler_shared_examples do
|
|
|
|
let(:recipient) { sent_notification.recipient }
|
|
|
|
|
|
|
|
let(:update_commands_only) { fixture_file('emails/update_commands_only_reply.eml')}
|
|
|
|
let(:no_content) { fixture_file('emails/no_content_reply.eml') }
|
|
|
|
let(:commands_in_reply) { fixture_file('emails/commands_in_reply.eml') }
|
|
|
|
let(:with_quick_actions) { fixture_file('emails/valid_reply_with_quick_actions.eml') }
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
before do
|
|
|
|
stub_incoming_email_setting(enabled: true, address: "reply+%{key}@appmail.adventuretime.ooo")
|
|
|
|
stub_config_setting(host: 'localhost')
|
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'when the recipient address does not include a mail key' do
|
|
|
|
let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(mail_key, '') }
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it 'raises a UnknownIncomingEmail' do
|
2016-09-13 17:45:13 +05:30
|
|
|
expect { receiver.execute }.to raise_error(Gitlab::Email::UnknownIncomingEmail)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'when no sent notification for the mail key could be found' do
|
2016-09-13 17:45:13 +05:30
|
|
|
let(:email_raw) { fixture_file('emails/wrong_mail_key.eml') }
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it 'raises a SentNotificationNotFoundError' do
|
2016-09-13 17:45:13 +05:30
|
|
|
expect { receiver.execute }.to raise_error(Gitlab::Email::SentNotificationNotFoundError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'when issue is confidential' do
|
2019-02-02 18:00:53 +05:30
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:note) { create(:note, noteable: issue, project: project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
issue.update_attribute(:confidential, true)
|
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it_behaves_like :checks_permissions_on_noteable_examples
|
2019-02-02 18:00:53 +05:30
|
|
|
end
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
shared_examples 'a reply to existing comment' do
|
2021-03-08 18:12:59 +05:30
|
|
|
it 'creates a comment' do
|
2016-09-13 17:45:13 +05:30
|
|
|
expect { receiver.execute }.to change { noteable.notes.count }.by(1)
|
2016-11-03 12:29:30 +05:30
|
|
|
new_note = noteable.notes.last
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
expect(new_note.author).to eq(sent_notification.recipient)
|
|
|
|
expect(new_note.position).to eq(note.position)
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(new_note.note).to include('I could not disagree more.')
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(new_note.in_reply_to?(note)).to be_truthy
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
if note.part_of_discussion?
|
|
|
|
expect(new_note.discussion_id).to eq(note.discussion_id)
|
|
|
|
else
|
|
|
|
expect(new_note.discussion_id).not_to eq(note.discussion_id)
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2019-03-02 22:35:43 +05:30
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
# additional shared tests in :reply_processing_shared_examples
|
|
|
|
context 'when everything is fine' do
|
2019-03-02 22:35:43 +05:30
|
|
|
before do
|
|
|
|
setup_attachment
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a reply to existing comment'
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
context 'when sub-addressing is not supported' do
|
|
|
|
before do
|
|
|
|
stub_incoming_email_setting(enabled: true, address: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'an email that contains a mail key' do |header|
|
|
|
|
it "fetches the mail key from the #{header} header and creates a comment" do
|
|
|
|
expect { receiver.execute }.to change { noteable.notes.count }.by(1)
|
2016-11-03 12:29:30 +05:30
|
|
|
new_note = noteable.notes.last
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
expect(new_note.author).to eq(sent_notification.recipient)
|
|
|
|
expect(new_note.position).to eq(note.position)
|
|
|
|
expect(new_note.note).to include('I could not disagree more.')
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'mail key is in the References header' do
|
|
|
|
let(:email_raw) { fixture_file('emails/reply_without_subaddressing_and_key_inside_references.eml') }
|
|
|
|
|
|
|
|
it_behaves_like 'an email that contains a mail key', 'References'
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
context 'mail key is in the References header with a comma' do
|
|
|
|
let(:email_raw) { fixture_file('emails/reply_without_subaddressing_and_key_inside_references_with_a_comma.eml') }
|
|
|
|
|
|
|
|
it_behaves_like 'an email that contains a mail key', 'References'
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'when note is not a discussion' do
|
2019-03-02 22:35:43 +05:30
|
|
|
let(:note) { create(:note_on_merge_request, project: project) }
|
|
|
|
|
|
|
|
it_behaves_like 'a reply to existing comment'
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|