diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 5db44de5c..43beb22fa 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -2,7 +2,7 @@ name: CD Azure (preview) on: # Uncomment for testing: - # pull_request: + pull_request: pull_request_target: types: [opened, synchronize, reopened, labeled] workflow_dispatch: @@ -168,5 +168,6 @@ jobs: TEST_URL: ${{ steps.deploy_web.outputs.url }} # The tests need these tokens to run, but their actual value should not matter NUXT_GITHUB_REPO_TOKEN: 'SIGNAL_TO_RUN_TEST' - # Re-enable when email sending in the test environment is fixed - #NUXT_EMAIL_CLIENT: 'SIGNAL_TO_RUN_TEST' + # enable to run email tests + NUXT_EMAIL_CLIENT: 'SIGNAL_TO_RUN_TEST' + NUXT_MAILSAC_KEY: ${{ secrets.MAILSAC_API_KEY }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4f3558c94..aa7b96af5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -144,5 +144,6 @@ jobs: TEST_URL: ${{ matrix.url }} # The tests need these tokens to run, but their actual value should not matter NUXT_GITHUB_REPO_TOKEN: 'SIGNAL_TO_RUN_TEST' - # Re-enable when email sending in the test environment is fixed - # NUXT_EMAIL_CLIENT: 'SIGNAL_TO_RUN_TEST' + # enable to run email tests + NUXT_EMAIL_CLIENT: 'SIGNAL_TO_RUN_TEST' + NUXT_MAILSAC_KEY: ${{ secrets.MAILSAC_API_KEY }} \ No newline at end of file diff --git a/test/email.ts b/test/email.ts index f9503ba92..909541da4 100644 --- a/test/email.ts +++ b/test/email.ts @@ -1,22 +1,50 @@ interface EmailMessage { from: string subject: string - date: string - body: string + received: string //Date in ISO 8601 textBody: string - htmlBody: string + // body: string + // htmlBody: string +} + +interface MailAddress { + address: string + name: string +} + +interface MailsacResponse { + _id: string + from: MailAddress[] + to: MailAddress[] + subject: string + received: string //Date in ISO 8601 } export function getTemporaryEmail(): string { const randomId = Math.floor(Math.random() * 10000) - return `jabref-test${randomId}@1secmail.com` + return `jabref-test${randomId}@mailsac.com` } export async function getEmail(email: string): Promise { + + if(!process.env.NUXT_MAILSAC_KEY || process.env.NUXT_MAILSAC_KEY === 'none') { + throw new Error('No Mailsac API key configured') + } + + const headers = { + 'mailsac-key': process.env.NUXT_MAILSAC_KEY, + } + + const [login, domain] = email.split('@') const response = await fetch( - `https://www.1secmail.com/api/v1/?action=getMessages&login=${login}&domain=${domain}`, + `https://mailsac.com/api/addresses/${login}@${domain}/messages`, + { + headers + }, ) - const messages = (await response.json()) as { id: string }[] + + const messages = (await response.json()) as MailsacResponse[] + if (messages.length === 0) { // Try again in 1 second if there are no messages return new Promise((resolve) => { @@ -26,9 +54,20 @@ export async function getEmail(email: string): Promise { }) } const message = messages[0]! + const messageResponse = await fetch( - `https://www.1secmail.com/api/v1/?action=readMessage&login=${login}&domain=${domain}&id=${message.id}`, + `https://mailsac.com/api/text/${login}@${domain}/${message._id}`, + { + headers, + }, ) - const messageJson = await messageResponse.json() - return messageJson + + const messageData = (await messageResponse.text()) as string + + return { + from: message.from[0]!.address, + subject: message.subject, + received: message.received, + textBody: messageData, + } }