Skip to content

Commit 1a2f3a9

Browse files
committed
chore: add better typing in backend-helpers
1 parent 7207f2e commit 1a2f3a9

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

apps/e2e/tests/backend/backend-helpers.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,25 +186,37 @@ export async function bumpEmailAddress(options: { unindexed?: boolean } = {}) {
186186
return mailbox;
187187
}
188188

189+
// Type for outbox email items (simplified - full type is EmailOutboxCrud["Server"]["Read"])
190+
type OutboxEmail = {
191+
id: string,
192+
subject?: string,
193+
status: string,
194+
simple_status: string,
195+
[key: string]: unknown,
196+
};
197+
189198
// Helper to get emails from the outbox, filtered by subject if provided
190-
export async function getOutboxEmails(options?: { subject?: string }) {
199+
export async function getOutboxEmails(options?: { subject?: string }): Promise<OutboxEmail[]> {
191200
const listResponse = await niceBackendFetch("/api/v1/emails/outbox", {
192201
method: "GET",
193202
accessType: "server",
194203
});
204+
const items = listResponse.body.items as OutboxEmail[];
195205
if (options?.subject) {
196-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
197-
return listResponse.body.items.filter((e: any) => e.subject === options.subject);
206+
return items.filter((e) => e.subject === options.subject);
198207
}
199-
return listResponse.body.items;
208+
return items;
200209
}
201210

202-
// Helper to poll the outbox until an email with the expected subject and status appears
203-
export async function waitForOutboxEmailWithStatus(subject: string, status: string) {
211+
// Helper to poll the outbox until the most recent email with the expected subject has the expected status.
212+
// Note: emails are returned ordered by createdAt desc (newest first), so we check emails[0] specifically
213+
// to ensure we're waiting for the MOST RECENT email, not an older one with the same subject.
214+
export async function waitForOutboxEmailWithStatus(subject: string, status: string): Promise<OutboxEmail[]> {
204215
const maxRetries = 24;
205-
let emails: any[] = [];
216+
let emails: OutboxEmail[] = [];
206217
for (let i = 0; i < maxRetries; i++) {
207218
emails = await getOutboxEmails({ subject });
219+
// Check the most recent email (first in the list due to createdAt desc ordering)
208220
if (emails.length > 0 && emails[0].status === status) {
209221
return emails;
210222
}

0 commit comments

Comments
 (0)