Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 }}
5 changes: 3 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
57 changes: 48 additions & 9 deletions test/email.ts
Original file line number Diff line number Diff line change
@@ -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<EmailMessage> {

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) => {
Expand All @@ -26,9 +54,20 @@ export async function getEmail(email: string): Promise<EmailMessage> {
})
}
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,
}
}
Loading