2022-04-19 14:10:22 -07:00
|
|
|
import test, { expect } from '@playwright/test'
|
|
|
|
import { createWebhook, importTypebotInDatabase } from '../services/database'
|
|
|
|
import cuid from 'cuid'
|
|
|
|
import path from 'path'
|
|
|
|
import { typebotViewer } from '../services/selectorUtils'
|
|
|
|
import { HttpMethod } from 'models'
|
|
|
|
|
|
|
|
test('should execute webhooks properly', async ({ page }) => {
|
|
|
|
const typebotId = cuid()
|
|
|
|
await importTypebotInDatabase(
|
|
|
|
path.join(__dirname, '../fixtures/typebots/webhook.json'),
|
|
|
|
{ id: typebotId, publicId: `${typebotId}-public` }
|
|
|
|
)
|
|
|
|
await createWebhook(typebotId, {
|
|
|
|
id: 'success-webhook',
|
2022-05-13 06:47:39 -07:00
|
|
|
url: 'http://localhost:3001/api/mock/success',
|
2022-04-19 14:10:22 -07:00
|
|
|
method: HttpMethod.POST,
|
|
|
|
})
|
|
|
|
await createWebhook(typebotId, {
|
|
|
|
id: 'failed-webhook',
|
2022-05-13 06:47:39 -07:00
|
|
|
url: 'http://localhost:3001/api/mock/fail',
|
2022-04-19 14:10:22 -07:00
|
|
|
method: HttpMethod.POST,
|
|
|
|
})
|
|
|
|
|
|
|
|
await page.goto(`/${typebotId}-public`)
|
2022-10-02 10:34:13 +02:00
|
|
|
await Promise.all([
|
|
|
|
page.waitForResponse(
|
|
|
|
async (resp) =>
|
|
|
|
resp.request().url().includes(`/api/typebots/${typebotId}/blocks`) &&
|
|
|
|
resp.status() === 200 &&
|
|
|
|
(await resp.json()).statusCode === 200
|
|
|
|
),
|
|
|
|
typebotViewer(page).locator('text=Send success webhook').click(),
|
|
|
|
])
|
|
|
|
await Promise.all([
|
|
|
|
page.waitForResponse(
|
|
|
|
async (resp) =>
|
|
|
|
resp.request().url().includes(`/api/typebots/${typebotId}/blocks`) &&
|
|
|
|
resp.status() === 200 &&
|
|
|
|
(await resp.json()).statusCode === 500
|
|
|
|
),
|
|
|
|
typebotViewer(page).locator('text=Send failed webhook').click(),
|
|
|
|
])
|
2022-04-19 14:10:22 -07:00
|
|
|
await page.goto(`http://localhost:3000/typebots/${typebotId}/results`)
|
|
|
|
await page.click('text="See logs"')
|
|
|
|
await expect(
|
|
|
|
page.locator('text="Webhook successfuly executed."')
|
|
|
|
).toBeVisible()
|
|
|
|
await expect(page.locator('text="Webhook returned an error"')).toBeVisible()
|
|
|
|
})
|