2018-08-23 05:22:23 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-24 02:20:36 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Email::Handler do
|
|
|
|
describe '.for' do
|
|
|
|
it 'picks issue handler if there is not merge request prefix' do
|
|
|
|
expect(described_class.for('email', 'project+key')).to be_an_instance_of(Gitlab::Email::Handler::CreateIssueHandler)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'picks merge request handler if there is merge request key' do
|
|
|
|
expect(described_class.for('email', 'project+merge-request+key')).to be_an_instance_of(Gitlab::Email::Handler::CreateMergeRequestHandler)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil if no handler is found' do
|
|
|
|
expect(described_class.for('email', '')).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2018-04-09 05:39:03 -04:00
|
|
|
|
|
|
|
describe 'regexps are set properly' do
|
|
|
|
let(:addresses) do
|
2018-12-28 13:53:39 -05:00
|
|
|
%W(sent_notification_key#{Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX} sent_notification_key path-to-project-123-user_email_token-merge-request path-to-project-123-user_email_token-issue) +
|
2018-12-14 13:37:03 -05:00
|
|
|
%W(sent_notification_key#{Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX_LEGACY} sent_notification_key path/to/project+merge-request+user_email_token path/to/project+user_email_token)
|
2018-04-09 05:39:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'picks each handler at least once' do
|
|
|
|
matched_handlers = addresses.map do |address|
|
|
|
|
described_class.for('email', address).class
|
|
|
|
end
|
|
|
|
|
2018-04-09 16:30:43 -04:00
|
|
|
expect(matched_handlers.uniq).to match_array(ce_handlers)
|
2018-04-09 05:39:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can pick exactly one handler for each address' do
|
|
|
|
addresses.each do |address|
|
2018-04-09 16:30:43 -04:00
|
|
|
matched_handlers = ce_handlers.select do |handler|
|
2018-04-09 05:39:03 -04:00
|
|
|
handler.new('email', address).can_handle?
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(matched_handlers.count).to eq(1), "#{address} matches #{matched_handlers.count} handlers: #{matched_handlers}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-04-09 16:30:43 -04:00
|
|
|
|
|
|
|
def ce_handlers
|
2018-08-23 05:04:41 -04:00
|
|
|
@ce_handlers ||= Gitlab::Email::Handler.handlers.reject do |handler|
|
2018-04-09 16:30:43 -04:00
|
|
|
handler.name.start_with?('Gitlab::Email::Handler::EE::')
|
|
|
|
end
|
|
|
|
end
|
2017-08-24 02:20:36 -04:00
|
|
|
end
|