2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2019-08-06 15:26:29 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
require 'ostruct'
|
|
|
|
|
|
|
|
RSpec.describe NotificationFactory::Mailer do
|
|
|
|
describe '#template' do
|
|
|
|
context 'for postmaster oversized mail' do
|
2020-02-18 19:51:31 +00:00
|
|
|
let(:raw_incoming_mail) { File.read(Rails.root.join('test/data/mail/mail010.box')) }
|
2019-08-06 15:26:29 +00:00
|
|
|
|
2020-06-22 09:57:45 +00:00
|
|
|
let(:parsed_incoming_mail) { Channel::EmailParser.new.parse raw_incoming_mail }
|
2019-08-06 15:26:29 +00:00
|
|
|
|
|
|
|
let(:incoming_mail) do
|
2021-11-18 07:50:18 +00:00
|
|
|
mail = Channel::EmailParser::MESSAGE_STRUCT.new
|
2019-08-06 15:26:29 +00:00
|
|
|
mail.from_display_name = parsed_incoming_mail[:from_display_name]
|
|
|
|
mail.subject = parsed_incoming_mail[:subject]
|
2020-02-18 19:51:31 +00:00
|
|
|
mail.msg_size = format('%<MB>.2f', MB: raw_incoming_mail.size.to_f / 1024 / 1024)
|
2019-08-06 15:26:29 +00:00
|
|
|
mail
|
|
|
|
end
|
|
|
|
|
2019-08-09 10:47:21 +00:00
|
|
|
let(:en_expected_subject) { '[undeliverable] Message too large' }
|
2019-08-06 15:26:29 +00:00
|
|
|
|
|
|
|
let(:en_expected_body) do
|
|
|
|
<<~BODY
|
|
|
|
Dear Smith Sepp,
|
|
|
|
|
|
|
|
Unfortunately your email titled \"Gruß aus Oberalteich\" could not be delivered to one or more recipients.
|
|
|
|
|
|
|
|
Your message was 0.01 MB but we only accept messages up to 10 MB.
|
|
|
|
|
|
|
|
Please reduce the message size and try again. Thank you for your understanding.
|
|
|
|
|
|
|
|
Regretfully,
|
|
|
|
|
|
|
|
Postmaster of zammad.example.com
|
|
|
|
BODY
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'plaintext mail templating' do
|
|
|
|
it 'templates correctly' do
|
|
|
|
result = described_class.template(
|
|
|
|
template: 'email_oversized',
|
|
|
|
locale: locale,
|
|
|
|
format: 'txt',
|
|
|
|
objects: {
|
|
|
|
mail: incoming_mail,
|
|
|
|
},
|
|
|
|
raw: true, # will not add application template
|
|
|
|
standalone: true, # default: false - will send header & footer
|
|
|
|
)
|
|
|
|
expect(result[:subject]).to eq(expected_subject)
|
|
|
|
expect(result[:body]).to eq(expected_body)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'English locale (en)' do
|
|
|
|
include_examples 'plaintext mail templating' do
|
|
|
|
let(:locale) { 'en' }
|
|
|
|
let(:expected_subject) { en_expected_subject }
|
|
|
|
let(:expected_body) { en_expected_body }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'German locale (de)' do
|
|
|
|
include_examples 'plaintext mail templating' do
|
|
|
|
let(:locale) { 'de' }
|
|
|
|
let(:expected_subject) { '[Unzustellbar] Nachricht zu groß' }
|
|
|
|
let(:expected_body) do
|
|
|
|
<<~BODY
|
|
|
|
Hallo Smith Sepp,
|
|
|
|
|
|
|
|
Ihre E-Mail mit dem Betreff \"Gruß aus Oberalteich\" konnte nicht an einen oder mehrere Empfänger zugestellt werden.
|
|
|
|
|
|
|
|
Die Nachricht hatte eine Größe von 0.01 MB, wir akzeptieren jedoch nur E-Mails mit einer Größe von bis zu 10 MB.
|
|
|
|
|
|
|
|
Bitte reduzieren Sie die Größe Ihrer Nachricht und versuchen Sie es erneut. Vielen Dank für Ihr Verständnis.
|
|
|
|
|
|
|
|
Mit freundlichen Grüßen
|
|
|
|
|
|
|
|
Postmaster von zammad.example.com
|
|
|
|
BODY
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unsupported locale, which defaults back to English locale (en)' do
|
|
|
|
include_examples 'plaintext mail templating' do
|
|
|
|
let(:locale) { 'UNSUPPORTED_LOCALE' }
|
|
|
|
let(:expected_subject) { en_expected_subject }
|
|
|
|
let(:expected_body) { en_expected_body }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-02-19 14:57:32 +00:00
|
|
|
|
|
|
|
describe '#send' do
|
|
|
|
subject(:result) do
|
|
|
|
described_class.send(
|
|
|
|
recipient: user,
|
|
|
|
subject: 'some subject',
|
|
|
|
body: 'some body',
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'recipient with email address' do
|
2020-06-19 09:17:18 +00:00
|
|
|
let(:user) { create(:agent, email: 'somebody@example.com') }
|
2020-02-19 14:57:32 +00:00
|
|
|
|
|
|
|
it 'returns a Mail::Message' do
|
2021-07-16 13:38:01 +00:00
|
|
|
expect(result).to be_kind_of(Mail::Message)
|
2020-02-19 14:57:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'recipient without email address' do
|
2020-06-19 09:17:18 +00:00
|
|
|
let(:user) { create(:agent, email: '') }
|
2020-02-19 14:57:32 +00:00
|
|
|
|
|
|
|
it 'raises Exceptions::UnprocessableEntity' do
|
|
|
|
expect { result }.to raise_error(Exceptions::UnprocessableEntity)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-06 15:26:29 +00:00
|
|
|
end
|