feat: Customisable Email Templates (#1095)
This commit is contained in:
5
spec/factories/email_template.rb
Normal file
5
spec/factories/email_template.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
FactoryBot.define do
|
||||
factory :email_template do
|
||||
name { 'MyString' }
|
||||
end
|
||||
end
|
||||
80
spec/lib/email_templates/db_resolver_service_spec.rb
Normal file
80
spec/lib/email_templates/db_resolver_service_spec.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user