2020-08-06 09:51:06 +00:00
|
|
|
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 = {
|
2021-06-08 17:15:01 +00:00
|
|
|
locals: [],
|
2020-08-06 09:51:06 +00:00
|
|
|
format: Mime['html'].to_sym,
|
|
|
|
virtual_path: 'test'
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(
|
2021-06-08 17:15:01 +00:00
|
|
|
resolver.find_templates('test', '', false, []).first.inspect
|
2020-08-06 09:51:06 +00:00
|
|
|
).to eq(
|
|
|
|
ActionView::Template.new(
|
|
|
|
email_template.body,
|
2021-06-08 17:15:01 +00:00
|
|
|
"DB Template - #{email_template.id}", handler, **template_details
|
|
|
|
).inspect
|
2020-08-06 09:51:06 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when account template exists in db' do
|
|
|
|
let(:account) { create(:account) }
|
2021-06-08 17:15:01 +00:00
|
|
|
let!(:installation_template) { create(:email_template, name: 'test', body: 'test') }
|
|
|
|
let!(:account_template) { create(:email_template, name: 'test', body: 'test2', account: account) }
|
2020-08-06 09:51:06 +00:00
|
|
|
|
|
|
|
it 'return account template for current account' do
|
|
|
|
Current.account = account
|
|
|
|
handler = ActionView::Template.registered_template_handler(:liquid)
|
|
|
|
template_details = {
|
2021-06-08 17:15:01 +00:00
|
|
|
locals: [],
|
2020-08-06 09:51:06 +00:00
|
|
|
format: Mime['html'].to_sym,
|
|
|
|
virtual_path: 'test'
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(
|
2021-06-08 17:15:01 +00:00
|
|
|
resolver.find_templates('test', '', false, []).first.inspect
|
2020-08-06 09:51:06 +00:00
|
|
|
).to eq(
|
|
|
|
ActionView::Template.new(
|
|
|
|
account_template.body,
|
2021-06-08 17:15:01 +00:00
|
|
|
"DB Template - #{account_template.id}", handler, **template_details
|
|
|
|
).inspect
|
2020-08-06 09:51:06 +00:00
|
|
|
)
|
|
|
|
Current.account = nil
|
|
|
|
end
|
|
|
|
|
2021-10-14 08:27:01 +00:00
|
|
|
it 'return installation template when current account dont have template' do
|
2020-08-06 09:51:06 +00:00
|
|
|
Current.account = create(:account)
|
|
|
|
handler = ActionView::Template.registered_template_handler(:liquid)
|
|
|
|
template_details = {
|
2021-06-08 17:15:01 +00:00
|
|
|
locals: [],
|
2020-08-06 09:51:06 +00:00
|
|
|
format: Mime['html'].to_sym,
|
|
|
|
virtual_path: 'test'
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(
|
2021-06-08 17:15:01 +00:00
|
|
|
resolver.find_templates('test', '', false, []).first.inspect
|
2020-08-06 09:51:06 +00:00
|
|
|
).to eq(
|
|
|
|
ActionView::Template.new(
|
|
|
|
installation_template.body,
|
2021-06-08 17:15:01 +00:00
|
|
|
"DB Template - #{installation_template.id}", handler, **template_details
|
|
|
|
).inspect
|
2020-08-06 09:51:06 +00:00
|
|
|
)
|
|
|
|
Current.account = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|