feat: Customisable Email Templates (#1095)

This commit is contained in:
Sojan Jose
2020-08-06 15:21:06 +05:30
committed by GitHub
parent db877453a4
commit a04ca24def
27 changed files with 409 additions and 44 deletions

View File

@@ -0,0 +1,5 @@
FactoryBot.define do
factory :email_template do
name { 'MyString' }
end
end

View File

@@ -0,0 +1,80 @@
require 'rails_helper'
describe ::EmailTemplates::DbResolverService do
subject(:resolver) { described_class.using(EmailTemplate, {}) }
describe '#find_templates' do
context 'when template does not exist in db' do
it 'return empty array' do
expect(resolver.find_templates('test', '', false, [])).to eq([])
end
end
context 'when installation template exist in db' do
it 'return installation template' do
email_template = create(:email_template, name: 'test', body: 'test')
handler = ActionView::Template.registered_template_handler(:liquid)
template_details = {
format: Mime['html'].to_sym,
updated_at: email_template.updated_at,
virtual_path: 'test'
}
expect(
resolver.find_templates('test', '', false, []).first.to_json
).to eq(
ActionView::Template.new(
email_template.body,
"DB Template - #{email_template.id}", handler, template_details
).to_json
)
end
end
context 'when account template exists in db' do
let(:account) { create(:account) }
let(:installation_template) { create(:email_template, name: 'test', body: 'test') }
let(:account_template) { create(:email_template, name: 'test', body: 'test2', account: account) }
it 'return account template for current account' do
Current.account = account
handler = ActionView::Template.registered_template_handler(:liquid)
template_details = {
format: Mime['html'].to_sym,
updated_at: account_template.updated_at,
virtual_path: 'test'
}
expect(
resolver.find_templates('test', '', false, []).first.to_json
).to eq(
ActionView::Template.new(
account_template.body,
"DB Template - #{account_template.id}", handler, template_details
).to_json
)
Current.account = nil
end
it 'return installation template when current account dont have template' do
Current.account = create(:account)
handler = ActionView::Template.registered_template_handler(:liquid)
template_details = {
format: Mime['html'].to_sym,
updated_at: installation_template.updated_at,
virtual_path: 'test'
}
expect(
resolver.find_templates('test', '', false, []).first.to_json
).to eq(
ActionView::Template.new(
installation_template.body,
"DB Template - #{installation_template.id}", handler, template_details
).to_json
)
Current.account = nil
end
end
end
end

View File

@@ -31,6 +31,7 @@ RSpec.describe 'Confirmation Instructions', type: :mailer do
expect(mail.body).to match(
"#{CGI.escapeHTML(inviter_val.name)}, with #{CGI.escapeHTML(inviter_val.account.name)}, has invited you to try out Chatwoot!"
)
Current.account = nil
end
end
end