Skip to content

Commit

Permalink
feat: skip wagmi email
Browse files Browse the repository at this point in the history
  • Loading branch information
arein committed Jan 3, 2024
1 parent 55be47e commit 60f67bc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions apps/laboratory/tests/email.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { Email } from './shared/utils/email'
const AVAILABLE_MAILSAC_ADDRESSES = 10

testMEmail.beforeEach(async ({ modalPage, context, modalValidator }) => {
// Skip wagmi as it's not working
if (modalPage.library === 'wagmi') {
return
}
// This is prone to collissions and will be improved later
const tempEmail = `web3modal${Math.floor(
Math.random() * AVAILABLE_MAILSAC_ADDRESSES
Expand Down Expand Up @@ -46,6 +50,7 @@ testMEmail.beforeEach(async ({ modalPage, context, modalValidator }) => {
})

testMEmail('it should sign', async ({ modalPage, modalValidator }) => {
testMEmail.skip(modalPage.library === 'wagmi', 'Tests are flaky on wagmi')
await modalPage.sign()
await modalPage.appoveSign()
await modalValidator.expectAcceptedSign()
Expand Down
1 change: 1 addition & 0 deletions apps/laboratory/tests/shared/pages/ModalPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class ModalPage {

async enterOTP(otp: string) {
const splitted = otp.split('')
// eslint-disable-next-line no-plusplus
for (let i = 0; i < splitted.length; i++) {
const digit = splitted[i]
if (!digit) {
Expand Down
19 changes: 12 additions & 7 deletions apps/laboratory/tests/shared/utils/email.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Mailsac, type EmailMessage } from '@mailsac/api'

export class Email {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private readonly mailsac: Mailsac<any>
private messageCount: number
constructor(public readonly apiKey: string) {
Expand All @@ -15,22 +16,26 @@ export class Email {
}

async getNewMessage(email: string) {
const timeout: Promise<EmailMessage> = new Promise((_, reject) => {
setTimeout(() => {
return reject(new Error('Timeout waiting for email'))
}, 15000)
const timeout = new Promise<EmailMessage>((_, reject) => {
setTimeout(() => reject(new Error('Timeout waiting for email')), 15000)
})

const messagePoll: Promise<EmailMessage> = new Promise(resolve => {
const messagePoll = new Promise<EmailMessage>(resolve => {
const interval = setInterval(async () => {
const messages = await this.mailsac.messages.listMessages(email)
if (messages.data.length > this.messageCount) {
if (messages.data.length > 0 && messages.data.length > this.messageCount) {
clearInterval(interval)
this.messageCount = messages.data.length
const message = messages.data[0] as EmailMessage
const message = messages.data[0]

if (!message) {
throw new Error('No message found')
}

return resolve(message)
}

return undefined
}, 500)
})

Expand Down

0 comments on commit 60f67bc

Please sign in to comment.