@adonisjs/mail
Version:
Mail provider for adonis framework and has support for all common mailing services to send emails
162 lines (161 loc) • 5.74 kB
TypeScript
import type { EmitterLike } from '@adonisjs/core/types/events';
import type { SentMessageInfo } from 'nodemailer/lib/json-transport/index.js';
import { Mailer } from './mailer.js';
import type { Message } from './message.js';
import { BaseMail } from './base_mail.js';
import type { MailResponse } from './mail_response.js';
import { JSONTransport } from './transports/json.js';
import type { MailEvents, MailerConfig, MailerContract, MailerMessenger, MessageSearchOptions, NormalizeConstructor, MessageComposeCallback } from './types.js';
/**
* Mails collection to collect mails sent or queued during
* the fake mode
*/
declare class MailsCollection {
#private;
trackSent(mail: BaseMail): void;
trackQueued(mail: BaseMail): void;
clear(): void;
/**
* Returns a list of sent emails captured by the fake mailer
*/
sent(filterFn?: (mail: BaseMail) => boolean): BaseMail[];
/**
* Returns a list of queued emails captured by the fake mailer
*/
queued(filterFn?: (mail: BaseMail) => boolean): BaseMail[];
/**
* Assert the mentioned mail was sent during the fake
* mode
*/
assertSent<T extends NormalizeConstructor<typeof BaseMail>>(mailConstructor: T, findFn?: (mail: InstanceType<T>) => boolean): void;
/**
* Assert the mentioned mail was NOT sent during the fake
* mode
*/
assertNotSent<T extends NormalizeConstructor<typeof BaseMail>>(mailConstructor: T, findFn?: (mail: InstanceType<T>) => boolean): void;
/**
* Assert a total of expected number of mails were sent
*/
assertSentCount(count: number): void;
/**
* Assert the mentioned mail was sent for expected number
* of times
*/
assertSentCount(mailConstructor: NormalizeConstructor<typeof BaseMail>, count: number): void;
/**
* Assert zero emails were sent
*/
assertNoneSent(): void;
/**
* Assert the mentioned mail was queued during the fake
* mode
*/
assertQueued<T extends NormalizeConstructor<typeof BaseMail>>(mailConstructor: T, findFn?: (mail: InstanceType<T>) => boolean): void;
/**
* Assert the mentioned mail was NOT queued during the fake
* mode
*/
assertNotQueued<T extends NormalizeConstructor<typeof BaseMail>>(mailConstructor: T, findFn?: (mail: InstanceType<T>) => boolean): void;
/**
* Assert a total of expected number of mails were queued
*/
assertQueuedCount(count: number): void;
/**
* Assert the mentioned mail was sequeuednt for expected number
* of times
*/
assertQueuedCount(mailConstructor: NormalizeConstructor<typeof BaseMail>, count: number): void;
/**
* Assert zero emails were queued
*/
assertNoneQueued(): void;
}
/**
* Messages collection to collect messages sent or queued during
* the fake mode
*/
declare class MessagesCollection {
#private;
trackSent(message: Message): void;
trackQueued(message: Message): void;
clear(): void;
/**
* Returns a list of sent messages captured by the fake mailer
*/
sent(filterFn?: (message: Message) => boolean): Message[];
/**
* Returns a list of queued messages captured by the fake mailer
*/
queued(filterFn?: (message: Message) => boolean): Message[];
/**
* Assert the mentioned message was sent during the fake
* mode
*/
assertSent(finder: ((message: Message) => boolean) | MessageSearchOptions): void;
/**
* Assert the mentioned message was NOT sent during the fake
* mode
*/
assertNotSent(finder: ((message: Message) => boolean) | MessageSearchOptions): void;
/**
* Assert a total of expected number of messages were sent
*/
assertSentCount(count: number): void;
/**
* Assert the mentioned message was sent for expected number
* of times
*/
assertSentCount(finder: ((message: Message) => boolean) | MessageSearchOptions, count: number): void;
/**
* Assert zero messages were sent
*/
assertNoneSent(): void;
/**
* Assert the mentioned message was queued during the fake
* mode
*/
assertQueued(finder: ((message: Message) => boolean) | MessageSearchOptions): void;
/**
* Assert the mentioned message was NOT queued during the fake
* mode
*/
assertNotQueued(finder: ((message: Message) => boolean) | MessageSearchOptions): void;
/**
* Assert a total of expected number of messages were queued
*/
assertQueuedCount(count: number): void;
/**
* Assert the mentioned message was queued for expected number
* of times
*/
assertQueuedCount(finder: ((message: Message) => boolean) | MessageSearchOptions, count: number): void;
/**
* Assert zero messages were queued
*/
assertNoneQueued(): void;
}
/**
* Fake mailer uses the JSON transport to send emails and
* collects them within memory for a better testing
* experience.
*/
export declare class FakeMailer extends Mailer<JSONTransport> implements MailerContract<JSONTransport> {
mails: MailsCollection;
messages: MessagesCollection;
constructor(name: string, emitter: EmitterLike<MailEvents>, config: MailerConfig);
/**
* Define the messenger to use for queueing emails.
* The fake mailer ignores using a custom messenger
*/
setMessenger(_: MailerMessenger): this;
/**
* @inheritdoc
*/
send(callbackOrMail: MessageComposeCallback | BaseMail, config?: undefined): Promise<MailResponse<SentMessageInfo>>;
/**
* @inheritdoc
*/
sendLater(callbackOrMail: MessageComposeCallback | BaseMail, config?: undefined): Promise<void>;
close(): Promise<void>;
}
export {};