chore(e2e): 👷 Fix e2e pipeline
This commit is contained in:
5
apps/builder/playwright/.env.example
Normal file
5
apps/builder/playwright/.env.example
Normal file
@ -0,0 +1,5 @@
|
||||
PLAYWRIGHT_BUILDER_TEST_BASE_URL=http://localhost:3000
|
||||
|
||||
# For auth
|
||||
GITHUB_EMAIL=
|
||||
GITHUB_PASSWORD=
|
@ -1,31 +1,43 @@
|
||||
import { chromium, FullConfig, Page } from '@playwright/test'
|
||||
import { setupDatabase, teardownDatabase, user } from './services/database'
|
||||
import { setupDatabase, teardownDatabase } from './services/database'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
require('dotenv').config({ path: '.env' })
|
||||
|
||||
async function globalSetup(config: FullConfig) {
|
||||
const { baseURL } = config.projects[0].use
|
||||
if (!baseURL) throw new Error('baseURL is missing')
|
||||
|
||||
await teardownDatabase()
|
||||
await setupDatabase()
|
||||
|
||||
// Skip auth if debugging
|
||||
if (process.env.PWDEBUG === '1') return
|
||||
|
||||
const browser = await chromium.launch()
|
||||
const page = await browser.newPage()
|
||||
await signIn(page, user.email)
|
||||
await signIn(page)
|
||||
await page.context().storageState({
|
||||
path: './playwright/authenticatedState.json',
|
||||
})
|
||||
|
||||
await setupDatabase(process.env.GITHUB_EMAIL as string)
|
||||
}
|
||||
|
||||
const signIn = async (page: Page, email: string) => {
|
||||
await page.goto('http://localhost:3000/api/auth/signin')
|
||||
await page.fill('[placeholder="credentials\\@email\\.com"]', email)
|
||||
await Promise.all([
|
||||
page.waitForNavigation({ url: 'http://localhost:3000/typebots' }),
|
||||
page.press('[placeholder="credentials\\@email\\.com"]', 'Enter'),
|
||||
])
|
||||
const signIn = async (page: Page) => {
|
||||
if (!process.env.GITHUB_EMAIL || !process.env.GITHUB_PASSWORD)
|
||||
throw new Error(
|
||||
'GITHUB_USERNAME or GITHUB_PASSWORD are missing in the environment. They are required to log in.'
|
||||
)
|
||||
await page.goto(`${process.env.PLAYWRIGHT_BUILDER_TEST_BASE_URL}/signin`)
|
||||
await page.click('text=Continue with GitHub')
|
||||
await page.fill('input[name="login"]', process.env.GITHUB_EMAIL)
|
||||
await page.fill('input[name="password"]', process.env.GITHUB_PASSWORD)
|
||||
await page.press('input[name="password"]', 'Enter')
|
||||
try {
|
||||
await page.locator('text=Authorize baptisteArno').click({ timeout: 3000 })
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
await page.waitForNavigation({
|
||||
url: `${process.env.PLAYWRIGHT_BUILDER_TEST_BASE_URL}/typebots`,
|
||||
})
|
||||
}
|
||||
|
||||
export default globalSetup
|
||||
|
@ -5,20 +5,23 @@ import {
|
||||
Step,
|
||||
Typebot,
|
||||
} from 'models'
|
||||
import { CredentialsType, DashboardFolder, Plan, PrismaClient, User } from 'db'
|
||||
import { CredentialsType, DashboardFolder, PrismaClient, User } from 'db'
|
||||
import { readFileSync } from 'fs'
|
||||
|
||||
export const user = { id: 'user1', email: 'test1@gmail.com' }
|
||||
|
||||
const prisma = new PrismaClient()
|
||||
|
||||
export const teardownDatabase = async () => prisma.user.deleteMany()
|
||||
|
||||
export const setupDatabase = async () => {
|
||||
await createUsers()
|
||||
export const setupDatabase = async (userEmail: string) => {
|
||||
const createdUser = await getSignedInUser(userEmail)
|
||||
if (!createdUser) throw new Error("Couldn't find user")
|
||||
process.env.PLAYWRIGHT_USER_ID = createdUser.id
|
||||
return createCredentials()
|
||||
}
|
||||
|
||||
const getSignedInUser = (email: string) =>
|
||||
prisma.user.findFirst({ where: { email } })
|
||||
|
||||
export const createTypebots = async (partialTypebots: Partial<Typebot>[]) => {
|
||||
await prisma.typebot.createMany({
|
||||
data: partialTypebots.map(parseTestTypebot) as any[],
|
||||
@ -33,47 +36,37 @@ export const createTypebots = async (partialTypebots: Partial<Typebot>[]) => {
|
||||
export const createFolders = (partialFolders: Partial<DashboardFolder>[]) =>
|
||||
prisma.dashboardFolder.createMany({
|
||||
data: partialFolders.map((folder) => ({
|
||||
ownerId: user.id,
|
||||
ownerId: process.env.PLAYWRIGHT_USER_ID as string,
|
||||
name: 'Folder #1',
|
||||
id: 'folder',
|
||||
...folder,
|
||||
})),
|
||||
})
|
||||
|
||||
const createUsers = () =>
|
||||
prisma.user.create({
|
||||
data: {
|
||||
...user,
|
||||
emailVerified: new Date(),
|
||||
plan: Plan.FREE,
|
||||
stripeId: 'stripe-test2',
|
||||
},
|
||||
})
|
||||
|
||||
const createCredentials = () => {
|
||||
if (!process.env.GOOGLE_REFRESH_TOKEN_TEST)
|
||||
console.warn(
|
||||
'GOOGLE_REFRESH_TOKEN_TEST env var is missing. It is required to run Google Sheets tests'
|
||||
)
|
||||
return prisma.credentials.createMany({
|
||||
const createCredentials = () =>
|
||||
prisma.credentials.createMany({
|
||||
data: [
|
||||
{
|
||||
name: 'test2@gmail.com',
|
||||
ownerId: user.id,
|
||||
ownerId: process.env.PLAYWRIGHT_USER_ID as string,
|
||||
type: CredentialsType.GOOGLE_SHEETS,
|
||||
data: {
|
||||
expiry_date: 1642441058842,
|
||||
access_token:
|
||||
'ya29.A0ARrdaM--PV_87ebjywDJpXKb77NBFJl16meVUapYdfNv6W6ZzqqC47fNaPaRjbDbOIIcp6f49cMaX5ndK9TAFnKwlVqz3nrK9nLKqgyDIhYsIq47smcAIZkK56SWPx3X3DwAFqRu2UPojpd2upWwo-3uJrod',
|
||||
refresh_token: process.env.GOOGLE_REFRESH_TOKEN_TEST,
|
||||
// This token is linked to a mock Google account (typebot.test.user@gmail.com)
|
||||
refresh_token:
|
||||
'1//03W5-TyIxXd7nCgYIARAAGAMSNwF-L9IrAGAmp5MG8RqVyk6YYmqDDn9x-4nHTkSUj4xZWuMs6mNeyjdS_bgO0CWuZEfJoAd_zIw',
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
export const updateUser = (data: Partial<User>) =>
|
||||
prisma.user.update({ data, where: { id: user.id } })
|
||||
prisma.user.update({
|
||||
data,
|
||||
where: { id: process.env.PLAYWRIGHT_USER_ID as string },
|
||||
})
|
||||
|
||||
export const createResults = async ({ typebotId }: { typebotId: string }) => {
|
||||
await prisma.result.createMany({
|
||||
@ -129,7 +122,7 @@ export const loadRawTypebotInDatabase = (typebot: Typebot) =>
|
||||
data: {
|
||||
...typebot,
|
||||
id: 'typebot4',
|
||||
ownerId: user.id,
|
||||
ownerId: process.env.PLAYWRIGHT_USER_ID,
|
||||
} as any,
|
||||
})
|
||||
|
||||
@ -137,7 +130,7 @@ const parseTestTypebot = (partialTypebot: Partial<Typebot>): Typebot => ({
|
||||
id: partialTypebot.id ?? 'typebot',
|
||||
folderId: null,
|
||||
name: 'My typebot',
|
||||
ownerId: user.id,
|
||||
ownerId: process.env.PLAYWRIGHT_USER_ID as string,
|
||||
theme: defaultTheme,
|
||||
settings: defaultSettings,
|
||||
createdAt: new Date(),
|
||||
@ -224,7 +217,13 @@ export const importTypebotInDatabase = (
|
||||
updates?: Partial<Typebot>
|
||||
) => {
|
||||
const typebot: Typebot = JSON.parse(readFileSync(path).toString())
|
||||
return prisma.typebot.create({
|
||||
data: { ...typebot, ...updates, ownerId: user.id } as any,
|
||||
})
|
||||
try {
|
||||
return prisma.typebot.create({
|
||||
data: {
|
||||
...typebot,
|
||||
...updates,
|
||||
ownerId: process.env.PLAYWRIGHT_USER_ID,
|
||||
} as any,
|
||||
})
|
||||
} catch {}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import test, { expect } from '@playwright/test'
|
||||
import { refreshUser } from '../services/browser'
|
||||
import { Plan } from 'db'
|
||||
import path from 'path'
|
||||
import { updateUser, user } from '../services/database'
|
||||
import { updateUser } from '../services/database'
|
||||
|
||||
test.describe('Account page', () => {
|
||||
test('should edit user info properly', async ({ page }) => {
|
||||
@ -14,17 +14,14 @@ test.describe('Account page', () => {
|
||||
).toBeDefined()
|
||||
await page.fill('#name', 'John Doe')
|
||||
expect(saveButton).toBeVisible()
|
||||
const avatarImg = page.locator('img')
|
||||
await expect(page.locator('text=JD')).toBeVisible()
|
||||
await expect(avatarImg).toBeHidden()
|
||||
await page.setInputFiles(
|
||||
'input[type="file"]',
|
||||
path.join(__dirname, '../fixtures/avatar.jpg')
|
||||
)
|
||||
await expect(avatarImg).toHaveAttribute(
|
||||
await expect(page.locator('img')).toHaveAttribute(
|
||||
'src',
|
||||
new RegExp(
|
||||
`https://s3.eu-west-3.amazonaws.com/typebot/users/${user.id}/avatar`,
|
||||
`https://s3.eu-west-3.amazonaws.com/typebot/users/${process.env.PLAYWRIGHT_USER_ID}/avatar`,
|
||||
'gm'
|
||||
)
|
||||
)
|
||||
@ -43,7 +40,6 @@ test.describe('Account page', () => {
|
||||
)
|
||||
await expect(manageSubscriptionButton).toBeHidden()
|
||||
await updateUser({ plan: Plan.PRO, stripeId: 'stripeId' })
|
||||
await page.evaluate(refreshUser)
|
||||
await page.reload()
|
||||
await expect(page.locator('text=Pro plan')).toBeVisible()
|
||||
await expect(manageSubscriptionButton).toBeVisible()
|
||||
|
@ -16,7 +16,10 @@ test.describe('Condition step', () => {
|
||||
|
||||
await page.goto(`/typebots/${typebotId}/edit`)
|
||||
await page.click('text=Configure...')
|
||||
await page.fill('input[placeholder="Search for a variable"]', 'Age')
|
||||
await page.fill(
|
||||
'input[placeholder="Search for a variable"] >> nth=-1',
|
||||
'Age'
|
||||
)
|
||||
await page.click('button:has-text("Age")')
|
||||
await page.click('button:has-text("Select an operator")')
|
||||
await page.click('button:has-text("Greater than")', { force: true })
|
||||
@ -37,7 +40,10 @@ test.describe('Condition step', () => {
|
||||
)
|
||||
|
||||
await page.click('text=Configure...')
|
||||
await page.fill('input[placeholder="Search for a variable"]', 'Age')
|
||||
await page.fill(
|
||||
'input[placeholder="Search for a variable"] >> nth=-1',
|
||||
'Age'
|
||||
)
|
||||
await page.click('button:has-text("Age")')
|
||||
await page.click('button:has-text("Select an operator")')
|
||||
await page.click('button:has-text("Greater than")', { force: true })
|
||||
|
@ -6,7 +6,7 @@ import { importTypebotInDatabase } from '../../services/database'
|
||||
const typebotId = 'set-variable-step'
|
||||
|
||||
test.describe('Set variable step', () => {
|
||||
test('its configuration should work', async ({ page, context }) => {
|
||||
test('its configuration should work', async ({ page }) => {
|
||||
await importTypebotInDatabase(
|
||||
path.join(__dirname, '../../fixtures/typebots/logic/setVariable.json'),
|
||||
{
|
||||
@ -16,16 +16,19 @@ test.describe('Set variable step', () => {
|
||||
|
||||
await page.goto(`/typebots/${typebotId}/edit`)
|
||||
await page.click('text=Type a number...')
|
||||
await page.fill('input[placeholder="Select a variable"]', 'Num')
|
||||
await page.fill('input[placeholder="Select a variable"] >> nth=-1', 'Num')
|
||||
await page.click('text=Create "Num"')
|
||||
|
||||
await page.click('text=Click to edit... >> nth = 0')
|
||||
await page.fill('input[placeholder="Select a variable"]', 'Total')
|
||||
await page.fill('input[placeholder="Select a variable"] >> nth=-1', 'Total')
|
||||
await page.click('text=Create "Total"')
|
||||
await page.fill('textarea', '1000 * {{Num}}')
|
||||
|
||||
await page.click('text=Click to edit...')
|
||||
await page.fill('input[placeholder="Select a variable"]', 'Custom var')
|
||||
await page.fill(
|
||||
'input[placeholder="Select a variable"] >> nth=-1',
|
||||
'Custom var'
|
||||
)
|
||||
await page.click('text=Create "Custom var"')
|
||||
await page.fill('textarea', 'Custom value')
|
||||
|
||||
|
@ -41,14 +41,18 @@ test.describe.parallel('Theme page', () => {
|
||||
test.describe('Chat', () => {
|
||||
test('should reflect change in real-time', async ({ page }) => {
|
||||
const typebotId = 'chat-theme-typebot'
|
||||
await importTypebotInDatabase(
|
||||
path.join(__dirname, '../fixtures/typebots/theme.json'),
|
||||
{
|
||||
id: typebotId,
|
||||
}
|
||||
)
|
||||
try {
|
||||
await importTypebotInDatabase(
|
||||
path.join(__dirname, '../fixtures/typebots/theme.json'),
|
||||
{
|
||||
id: typebotId,
|
||||
}
|
||||
)
|
||||
} catch {}
|
||||
|
||||
await page.goto(`/typebots/${typebotId}/theme`)
|
||||
await page.click('button:has-text("Chat")')
|
||||
await page.waitForTimeout(300)
|
||||
|
||||
// Host bubbles
|
||||
await page.click(':nth-match([aria-label="Pick a color"], 1)')
|
||||
|
Reference in New Issue
Block a user