-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(email-plugin): Added
from
field to the email config (#168)
* feat(email-plugin): Added `from` field to the email config * test(email-plugin): Fix tests and raise error for missing field
- Loading branch information
1 parent
7568e20
commit 09eb34e
Showing
8 changed files
with
79 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ describe('EmailPlugin', () => { | |
.on(MockEvent) | ||
.filter(event => event.shouldSend === true) | ||
.setRecipient(() => '[email protected]') | ||
.setFrom('"test from" <[email protected]>') | ||
.setSubject('test subject'); | ||
|
||
const module = await initPluginWithHandlers([handler]); | ||
|
@@ -74,6 +75,7 @@ describe('EmailPlugin', () => { | |
.on(MockEvent) | ||
.filter(event => event.shouldSend === true) | ||
.filter(event => !!event.ctx.user) | ||
.setFrom('"test from" <[email protected]>') | ||
.setRecipient(() => '[email protected]') | ||
.setSubject('test subject'); | ||
|
||
|
@@ -99,6 +101,7 @@ describe('EmailPlugin', () => { | |
it('interpolates subject', async () => { | ||
const handler = new EmailEventListener('test') | ||
.on(MockEvent) | ||
.setFrom('"test from" <[email protected]>') | ||
.setRecipient(() => '[email protected]') | ||
.setSubject('Hello {{ subjectVar }}') | ||
.setTemplateVars(event => ({ subjectVar: 'foo' })); | ||
|
@@ -114,6 +117,7 @@ describe('EmailPlugin', () => { | |
it('interpolates body', async () => { | ||
const handler = new EmailEventListener('test') | ||
.on(MockEvent) | ||
.setFrom('"test from" <[email protected]>') | ||
.setRecipient(() => '[email protected]') | ||
.setSubject('Hello') | ||
.setTemplateVars(event => ({ testVar: 'this is the test var' })); | ||
|
@@ -129,6 +133,7 @@ describe('EmailPlugin', () => { | |
it('interpolates globalTemplateVars', async () => { | ||
const handler = new EmailEventListener('test') | ||
.on(MockEvent) | ||
.setFrom('"test from" <[email protected]>') | ||
.setRecipient(() => '[email protected]') | ||
.setSubject('Hello {{ globalVar }}'); | ||
|
||
|
@@ -142,9 +147,27 @@ describe('EmailPlugin', () => { | |
await module.close(); | ||
}); | ||
|
||
it('interpolates from', async () => { | ||
const handler = new EmailEventListener('test') | ||
.on(MockEvent) | ||
.setFrom('"test from {{ globalVar }}" <[email protected]>') | ||
.setRecipient(() => '[email protected]') | ||
.setSubject('Hello'); | ||
|
||
const module = await initPluginWithHandlers([handler], { | ||
globalTemplateVars: { globalVar: 'baz' }, | ||
}); | ||
|
||
eventBus.publish(new MockEvent(ctx, true)); | ||
await pause(); | ||
expect(onSend.mock.calls[0][0].from).toBe('"test from baz" <[email protected]>'); | ||
await module.close(); | ||
}); | ||
|
||
it('globalTemplateVars available in setTemplateVars method', async () => { | ||
const handler = new EmailEventListener('test') | ||
.on(MockEvent) | ||
.setFrom('"test from" <[email protected]>') | ||
.setRecipient(() => '[email protected]') | ||
.setSubject('Hello {{ testVar }}') | ||
.setTemplateVars((event, globals) => ({ testVar: globals.globalVar + ' quux' })); | ||
|
@@ -162,6 +185,7 @@ describe('EmailPlugin', () => { | |
it('setTemplateVars overrides globals', async () => { | ||
const handler = new EmailEventListener('test') | ||
.on(MockEvent) | ||
.setFrom('"test from" <[email protected]>') | ||
.setRecipient(() => '[email protected]') | ||
.setSubject('Hello {{ name }}') | ||
.setTemplateVars((event, globals) => ({ name: 'quux' })); | ||
|
@@ -184,6 +208,7 @@ describe('EmailPlugin', () => { | |
it('additional LanguageCode', async () => { | ||
const handler = new EmailEventListener('test') | ||
.on(MockEvent) | ||
.setFrom('"test from" <[email protected]>') | ||
.setSubject('Hello, {{ name }}!') | ||
.setRecipient(() => '[email protected]') | ||
.setTemplateVars(() => ({ name: 'Test' })) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters