2
0

(webhook) Improve bot test

This commit is contained in:
Baptiste Arnaud
2022-10-22 07:30:26 +02:00
parent d6dffa924e
commit 264711b029
4 changed files with 233 additions and 98 deletions

View File

@ -14,40 +14,50 @@ test('should execute webhooks properly', async ({ page }) => {
path.join(__dirname, '../fixtures/typebots/webhook.json'),
{ id: typebotId, publicId: `${typebotId}-public` }
)
await createWebhook(typebotId, {
id: 'success-webhook',
url: 'http://localhost:3001/api/mock/success',
method: HttpMethod.POST,
})
await createWebhook(typebotId, {
id: 'failed-webhook',
id: 'failing-webhook',
url: 'http://localhost:3001/api/mock/fail',
method: HttpMethod.POST,
})
await createWebhook(typebotId, {
id: 'partial-body-webhook',
url: 'http://localhost:3000/api/mock/webhook-easy-config',
method: HttpMethod.POST,
body: `{
"name": "{{Name}}",
"age": {{Age}},
"gender": "{{Gender}}"
}`,
})
await createWebhook(typebotId, {
id: 'full-body-webhook',
url: 'http://localhost:3000/api/mock/webhook-easy-config',
method: HttpMethod.POST,
body: `{{Full body}}`,
})
await page.goto(`/${typebotId}-public`)
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(),
])
await typebotViewer(page).locator('text=Send failing webhook').click()
await typebotViewer(page)
.locator('[placeholder="Type a name..."]')
.fill('John')
await typebotViewer(page).locator('text="Send"').click()
await typebotViewer(page).locator('[placeholder="Type an age..."]').fill('30')
await typebotViewer(page).locator('text="Send"').click()
await typebotViewer(page).locator('text="Male"').click()
await expect(
typebotViewer(page).getByText('{"name":"John","age":25,"gender":"male"}')
).toBeVisible()
await expect(
typebotViewer(page).getByText('{"name":"John","age":30,"gender":"Male"}')
).toBeVisible()
await page.goto(`http://localhost:3000/typebots/${typebotId}/results`)
await page.click('text="See logs"')
await expect(
page.locator('text="Webhook successfuly executed."')
page.locator('text="Webhook successfuly executed." >> nth=1')
).toBeVisible()
await expect(page.locator('text="Webhook returned an error"')).toBeVisible()
})