2022-04-12 10:00:54 -05:00
|
|
|
import test, { expect } from '@playwright/test'
|
|
|
|
import {
|
|
|
|
createSmtpCredentials,
|
|
|
|
importTypebotInDatabase,
|
|
|
|
} from '../services/database'
|
|
|
|
import cuid from 'cuid'
|
|
|
|
import path from 'path'
|
|
|
|
import { typebotViewer } from '../services/selectorUtils'
|
|
|
|
import { SmtpCredentialsData } from 'models'
|
|
|
|
|
|
|
|
const mockSmtpCredentials: SmtpCredentialsData = {
|
|
|
|
from: {
|
2022-10-02 10:34:13 +02:00
|
|
|
email: 'sedrick.konopelski@ethereal.email',
|
2022-08-21 22:33:09 +02:00
|
|
|
name: 'Kimberly Boyer',
|
2022-04-12 10:00:54 -05:00
|
|
|
},
|
|
|
|
host: 'smtp.ethereal.email',
|
|
|
|
port: 587,
|
2022-10-02 10:34:13 +02:00
|
|
|
username: 'sedrick.konopelski@ethereal.email',
|
|
|
|
password: 'yXZChpPy25Qa5yBbeH',
|
2022-04-12 10:00:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
test('should send an email', async ({ page }) => {
|
|
|
|
const typebotId = cuid()
|
|
|
|
const credentialsId = 'send-email-credentials'
|
|
|
|
await createSmtpCredentials(credentialsId, mockSmtpCredentials)
|
|
|
|
await importTypebotInDatabase(
|
|
|
|
path.join(__dirname, '../fixtures/typebots/sendEmail.json'),
|
|
|
|
{ id: typebotId, publicId: `${typebotId}-public` }
|
|
|
|
)
|
|
|
|
await page.goto(`/${typebotId}-public`)
|
2022-10-02 10:34:13 +02:00
|
|
|
const [response] = await Promise.all([
|
|
|
|
page.waitForResponse((resp) =>
|
|
|
|
resp.request().url().includes(`integrations/email`)
|
|
|
|
),
|
|
|
|
typebotViewer(page).locator('text=Send email').click(),
|
|
|
|
])
|
2022-04-12 10:00:54 -05:00
|
|
|
const { previewUrl } = await response.json()
|
|
|
|
await page.goto(previewUrl)
|
|
|
|
await expect(page.locator('text="Hey!"')).toBeVisible()
|
2022-08-21 22:33:09 +02:00
|
|
|
await expect(page.locator('text="Kimberly Boyer"')).toBeVisible()
|
2022-04-12 10:00:54 -05:00
|
|
|
await expect(page.locator('text="<test1@gmail.com>" >> nth=0')).toBeVisible()
|
|
|
|
await expect(page.locator('text="<test2@gmail.com>" >> nth=0')).toBeVisible()
|
|
|
|
await expect(
|
|
|
|
page.locator('text="<baptiste.arnaud95@gmail.com>" >> nth=0')
|
|
|
|
).toBeVisible()
|
2022-08-21 22:33:09 +02:00
|
|
|
await page.goto(`${process.env.BUILDER_URL}/typebots/${typebotId}/results`)
|
2022-04-19 14:10:22 -07:00
|
|
|
await page.click('text="See logs"')
|
|
|
|
await expect(page.locator('text="Email successfully sent"')).toBeVisible()
|
2022-04-12 10:00:54 -05:00
|
|
|
})
|