From 6f770af572e1f39c41fcc74fb90c53ebc4af5ce3 Mon Sep 17 00:00:00 2001 From: Nicolas Burtey Date: Fri, 14 Jul 2023 13:59:47 +0100 Subject: [PATCH] chore: exiting if variable env is not set --- e2e/utils/email.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/e2e/utils/email.ts b/e2e/utils/email.ts index 2ad22b5874..f0135b108f 100644 --- a/e2e/utils/email.ts +++ b/e2e/utils/email.ts @@ -1,6 +1,12 @@ import axios from "axios" -export const mailslurpApiKey = process.env.MAILSLURP_API_KEY || "" +export const mailslurpApiKey = process.env.MAILSLURP_API_KEY +if (mailslurpApiKey === undefined) { + console.error("-----------------------------") + console.error("MAILSLURP_API_KEY not set") + console.error("-----------------------------") + process.exit(1) +} const headers = { "Accept": "application/json", @@ -10,8 +16,7 @@ const headers = { export const getInbox = async () => { const optionsCreateInbox = { method: "POST", - url: `https://api.mailslurp.com/inboxes?useShortAddress=true`, - // url: `https://api.mailslurp.com/inboxes?expiresIn=60000&useShortAddress=true`, + url: `https://api.mailslurp.com/inboxes?expiresIn=60000&useShortAddress=true`, headers, } @@ -25,10 +30,10 @@ export const getInbox = async () => { } } -export const getFirstEmail = async (inboxId: string) => { +const getEmail = async (inboxId: string, index: number) => { const optionsGetEmails = { method: "GET", - url: `https://api.mailslurp.com/waitForNthEmail?inboxId=${inboxId}&index=0&unreadOnly=false`, + url: `https://api.mailslurp.com/waitForNthEmail?inboxId=${inboxId}&index=${index}&unreadOnly=false`, headers, } @@ -42,5 +47,12 @@ export const getFirstEmail = async (inboxId: string) => { } } +export const getFirstEmail = async (inboxId: string) => { + return getEmail(inboxId, 0) +} +export const getSecondEmail = async (inboxId: string) => { + return getEmail(inboxId, 1) +} + // getInbox() // getFirstEmail("a96cfd50-4c3e-4a1e-ba48-b7aa7958363f")