Skip to content

Commit

Permalink
added custom logs and console logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Schulze committed Nov 5, 2024
1 parent 9e6a773 commit f684813
Show file tree
Hide file tree
Showing 3 changed files with 243 additions and 98 deletions.
70 changes: 44 additions & 26 deletions cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,27 @@ declare global {
* Get all mails from the mailbox.
* @param start
* @param limit
* @param options
*/
mailpitGetAllMails(start?: number, limit?: number): Chainable<MessagesSummary>;
mailpitGetAllMails(start?: number, limit?: number, options?: { log?: boolean }): Chainable<MessagesSummary>;

/**
* Search all mails from the mailbox using query.
* @param query
* @param start
* @param limit
* @param options
*/
mailpitSearchEmails(query: string, start?: number, limit?: number): Chainable<MessagesSummary>;
mailpitSearchEmails(query: string, start?: number, limit?: number, options?: { log?: boolean }): Chainable<MessagesSummary>;

/**
* Get all mails from the mailbox using subject.
* @param subject
* @param start
* @param limit
* @param options
*/
mailpitGetEmailsBySubject(subject: string, start?: number, limit?: number): Chainable<MessagesSummary>;
mailpitGetEmailsBySubject(subject: string, start?: number, limit?: number, options?: { log?: boolean }): Chainable<MessagesSummary>;

/**
* Check if mailpit has any email with the search query
Expand All @@ -39,7 +42,7 @@ declare global {
query: string,
start?: number,
limit?: number,
options?: { timeout?: number; interval?: number },
options?: { timeout?: number; interval?: number, log?: boolean },
): Chainable;

/**
Expand All @@ -54,7 +57,7 @@ declare global {
query: string,
start?: number,
limit?: number,
options?: { timeout?: number; interval?: number },
options?: { timeout?: number; interval?: number, log?: boolean },
): Chainable;

/**
Expand All @@ -69,7 +72,7 @@ declare global {
subject: string,
start?: number,
limit?: number,
options?: { timeout?: number; interval?: number },
options?: { timeout?: number; interval?: number, log?: boolean },
): Chainable;

/**
Expand All @@ -84,16 +87,17 @@ declare global {
subject: string,
start?: number,
limit?: number,
options?: { timeout?: number; interval?: number },
options?: { timeout?: number; interval?: number, log?: boolean },
): Chainable;

/**
* Get all mails from the mailbox using the recipient's email address.
* @param email
* @param start
* @param limit
* @param options
*/
mailpitGetEmailsByTo(email: string, start?: number, limit?: number): Chainable<MessagesSummary>;
mailpitGetEmailsByTo(email: string, start?: number, limit?: number, options?: { log?: boolean }): Chainable<MessagesSummary>;

/**
* Check if mails have emails sent to a specific email address.
Expand All @@ -107,7 +111,7 @@ declare global {
email: string,
start?: number,
limit?: number,
options?: { timeout?: number; interval?: number },
options?: { timeout?: number; interval?: number, log?: boolean },
): Chainable;

/**
Expand All @@ -122,107 +126,121 @@ declare global {
email: string,
start?: number,
limit?: number,
options?: { timeout?: number; interval?: number },
options?: { timeout?: number; interval?: number, log?: boolean },
): Chainable;

/**
* Get the mail text body.
* @param message
* @param options
*/
mailpitGetMailTextBody(message?: Message): Chainable<string>;
mailpitGetMailTextBody(message?: Message, options?: { log?: boolean }): Chainable<string>;

/**
* Get the mail HTML body.
* @param message
* @param options
*/
mailpitGetMailHTMlBody(message?: Message): Chainable<string>;
mailpitGetMailHTMlBody(message?: Message, options?: { log?: boolean }): Chainable<string>;

/**
* Get the mail's "From" address.
* @param message
* @param options
*/
mailpitGetFromAddress(message?: Message): Chainable<string>;
mailpitGetFromAddress(message?: Message, options?: { log?: boolean }): Chainable<string>;

/**
* Get the attachments of the mail.
* @param message
* @param options
*/
mailpitGetAttachments(message?: Message): Chainable<string>;
mailpitGetAttachments(message?: Message, options?: { log?: boolean }): Chainable<string>;

/**
* Get the mail SpamAssassin summary.
* @param message
* @param options
*/
mailpitGetMailSpamAssassinSummary(message?: Message): Chainable<SpamAssassin>;
mailpitGetMailSpamAssassinSummary(message?: Message, options?: { log?: boolean }): Chainable<SpamAssassin>;

/**
* Get the mail SpamAssassin summary.
* This is a deprecated method for backward compatibility.
* @param message
* @param options
* @deprecated Use `mailpitGetMailSpamAssassinSummary` instead.
*/
mailpitGetMailSpamAssainSummary(message?: Message): Chainable<SpamAssassin>;
mailpitGetMailSpamAssainSummary(message?: Message, options?: { log?: boolean }): Chainable<SpamAssassin>;

/**
* Get the recipient addresses of the mail.
* @param message
* @param options
*/
mailpitGetRecipientAddress(message?: Message): Chainable<Array<string>>;
mailpitGetRecipientAddress(message?: Message, options?: { log?: boolean }): Chainable<Array<string>>;

/**
* Get the subject of the mail.
* @param message
* @param options
*/
mailpitGetSubject(message?: Message): Chainable<string>;
mailpitGetSubject(message?: Message, options?: { log?: boolean }): Chainable<string>;

/**
* Get the mail by ID.
* If ID is not provided, it will get the latest email.
* @param id
* @param options
*/
mailpitGetMail(id?: string): Chainable<Message>;
mailpitGetMail(id?: string, options?: { log?: boolean }): Chainable<Message>;

/**
* Send an email.
* If options are not provided, it will send a default email.
* @param options SendEmailOptions
* @param sendOptions SendEmailOptions
* @param options
*/
mailpitSendMail(options?: SendEmailOptions): Chainable<{ ID: string }>;
mailpitSendMail(sendOptions?: SendEmailOptions, options?: { log?: boolean }): Chainable<{ ID: string }>;

/**
* Delete all emails from the mailbox.
*/
mailpitDeleteAllEmails(): Chainable<void>;
mailpitDeleteAllEmails(options?: { log?: boolean }): Chainable<string>;

/**
* Delete emails from the mailbox based on search query.
* @param query Search query to delete emails
* @param options
*/
mailpitDeleteEmailsBySearch(query: string): Chainable<void>;
mailpitDeleteEmailsBySearch(query: string, options?: { log?: boolean }): Chainable<string>;

/**
* Set the read status of one or more emails to read.
* @param messages Array of Message or MessageSummary objects to mark as read
* @param options
*/
mailpitSetStatusAsRead(messages?: Message[] | Message | MessageSummary[] | MessageSummary | null): Chainable<string>;
mailpitSetStatusAsRead(messages?: Message[] | Message | MessageSummary[] | MessageSummary | null, options?: { log?: boolean }): Chainable<string>;

/**
* Set the read status of one or more emails to unread.
* @param messages Array of Message or MessageSummary objects to mark as unread
* @param options
*/
mailpitSetStatusAsUnRead(
messages?: Message[] | Message | MessageSummary[] | MessageSummary | null,
options?: { log?: boolean }
): Chainable<string>;

/**
* Set the read status of all emails to read.
*/
mailpitSetAllEmailStatusAsRead(): Chainable<void>;
mailpitSetAllEmailStatusAsRead(options?: { log?: boolean }): Chainable<string>;

/**
* Set the read status of all emails to unread.
*/
mailpitSetAllEmailStatusAsUnRead(): Chainable<void>;
mailpitSetAllEmailStatusAsUnRead(options?: { log?: boolean }): Chainable<string>;
}
}
}
10 changes: 9 additions & 1 deletion cypress/e2e/mailpit.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ describe("mailpit sending test", () => {
cy.mailpitDeleteAllEmails();
});

Cypress.on('fail', (error) => {
if(error.message.includes('Timed out after 1000ms waiting for condition')) return false;
throw error; // Throw error to have the tests still fail when not the specific error message was found
});

it("can send one email", () => {
cy.mailpitSendMail().then((result) => {
console.log(result)
expect(result).to.have.property("ID");
expect(result.ID).match(/\w+/);
});
Expand Down Expand Up @@ -192,6 +196,10 @@ describe("mailpit query test", () => {
cy.mailpitHasEmailsByTo("to@example.com");
cy.mailpitNotHasEmailsByTo("invalid@example.com");
});

it("can assert timeout", () => {
cy.mailpitHasEmailsByTo("invalid@example.com", undefined, undefined, { timeout: 1000, interval: 100 });
});
});

describe("mailpit read status test", () => {
Expand Down
Loading

0 comments on commit f684813

Please sign in to comment.