-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow integration with nodemailer-mock
Create a MailerTransportFactory class and inject in MailerService This change allow you to create a custom TransportFactory Class and implement a custom transport link nodemailer-mock that creates a mock to nodemailer SMTP calls. Closes #341
- Loading branch information
1 parent
c416bc2
commit 9a6ecc5
Showing
11 changed files
with
123 additions
and
19 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const MAILER_OPTIONS = 'MAILER_OPTIONS'; | ||
export const MAILER_TRANSPORT_FACTORY = 'MAILER_TRANSPORT_FACTORY'; |
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 |
---|---|---|
@@ -1,11 +1,18 @@ | ||
/** Modules **/ | ||
export { MailerModule } from './mailer.module'; | ||
|
||
/** Constants **/ | ||
export { | ||
MAILER_OPTIONS, | ||
MAILER_TRANSPORT_FACTORY, | ||
} from './constants/mailer.constant'; | ||
|
||
/** Interfaces **/ | ||
export { MailerOptions } from './interfaces/mailer-options.interface'; | ||
export { TemplateAdapter } from './interfaces/template-adapter.interface'; | ||
export { MailerOptionsFactory } from './interfaces/mailer-options-factory.interface'; | ||
export { ISendMailOptions } from './interfaces/send-mail-options.interface'; | ||
export { MailerTransportFactory } from './interfaces/mailer-transport-factory.interface'; | ||
|
||
/** Services **/ | ||
export { MailerService } from './mailer.service'; |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as Mail from 'nodemailer/lib/mailer'; | ||
import { TransportType } from './mailer-options.interface'; | ||
|
||
export interface MailerTransportFactory { | ||
createTransport(opts?: TransportType): Mail; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { createTransport } from 'nodemailer'; | ||
import * as Mail from 'nodemailer/lib/mailer'; | ||
|
||
import { | ||
MailerOptions, | ||
TransportType, | ||
} from './interfaces/mailer-options.interface'; | ||
import { MailerTransportFactory as IMailerTransportFactory } from './interfaces/mailer-transport-factory.interface'; | ||
import { Inject } from '@nestjs/common'; | ||
import { MAILER_OPTIONS } from './constants/mailer.constant'; | ||
|
||
export class MailerTransportFactory implements IMailerTransportFactory { | ||
constructor( | ||
@Inject(MAILER_OPTIONS) | ||
private readonly options: MailerOptions, | ||
) {} | ||
|
||
public createTransport(opts?: TransportType): Mail { | ||
return createTransport( | ||
opts || this.options.transport, | ||
this.options.defaults, | ||
); | ||
} | ||
} |
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