34 lines
1.3 KiB
Ruby
34 lines
1.3 KiB
Ruby
|
require 'rails_helper'
|
||
|
RSpec.describe MailPresenter do
|
||
|
include ActionMailbox::TestHelper
|
||
|
|
||
|
describe 'parsed mail decorator' do
|
||
|
let(:mail) { create_inbound_email_from_fixture('welcome.eml').mail }
|
||
|
let(:decorated_mail) { described_class.new(mail) }
|
||
|
|
||
|
it 'give utf8 encoded content' do
|
||
|
expect(decorated_mail.subject).to eq("Discussion: Let's debate these attachments")
|
||
|
expect(decorated_mail.content).to eq("Let's talk about these images:\r\n\r\n")
|
||
|
end
|
||
|
|
||
|
it 'give decoded blob attachments' do
|
||
|
decorated_mail.attachments.each do |attachment|
|
||
|
expect(attachment.keys).to eq([:original, :blob])
|
||
|
expect(attachment[:blob].class.name).to eq('ActiveStorage::Blob')
|
||
|
end
|
||
|
end
|
||
|
|
||
|
it 'give number of attachments of the mail' do
|
||
|
expect(decorated_mail.number_of_attachments).to eq(2)
|
||
|
end
|
||
|
|
||
|
it 'give the serialized data of the email to be stored in the message' do
|
||
|
data = decorated_mail.serialized_data
|
||
|
expect(data.keys).to eq([:content, :number_of_attachments, :subject, :date, :to, :from, :in_reply_to, :cc, :bcc, :message_id])
|
||
|
expect(data[:subject]).to eq(decorated_mail.subject)
|
||
|
expect(data[:date].to_s).to eq('2020-04-20T04:20:20-04:00')
|
||
|
expect(data[:message_id]).to eq(mail.message_id)
|
||
|
end
|
||
|
end
|
||
|
end
|