Skip to content

Commit

Permalink
fix: edge integration (#91)
Browse files Browse the repository at this point in the history
* fix: edge integration

* test: remove outdated test
  • Loading branch information
Julien-R44 authored Dec 10, 2023
1 parent 0cb4f15 commit 362a3ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion providers/mail_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export default class MailProvider {
protected async defineTemplateEngine() {
if (this.app.usingEdgeJS) {
const edge = await import('edge.js')
Message.templateEngine = edge.default
Message.templateEngine = {
render(templatePath, helpers, data) {
return edge.default.share(helpers).render(templatePath, data)
},
}
}
}

Expand Down
13 changes: 11 additions & 2 deletions tests/integration/mail_provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ test.group('Mail Provider', () => {
await app.container.make('mail.manager')
}).throws('Invalid "config/mail.ts" file. Make sure you are using the "defineConfig" method')

test('share edge template engine with Message class', async ({ assert }) => {
test('correctly share helpers and view data with edge', async ({ assert }) => {
const ignitor = new IgnitorFactory()
.merge({
rcFileContents: {
Expand All @@ -106,6 +106,15 @@ test.group('Mail Provider', () => {
await app.init()
await app.boot()

assert.strictEqual(Message.templateEngine, edge)
const message = new Message()
edge.registerTemplate('foo/bar', {
template: `Hello {{ username }} <img src="{{ embedImage('./foo.jpg') }}" />`,
})

message.htmlView('foo/bar', { username: 'jul' })
await message.computeContents()

assert.isDefined(message.nodeMailerMessage.attachments![0])
assert.include(message.nodeMailerMessage.html, 'Hello jul')
})
})

0 comments on commit 362a3ca

Please sign in to comment.