2
0

feat(editor): Restore published version button

Had to migrate webhooks into a standalone table
This commit is contained in:
Baptiste Arnaud
2022-03-01 07:13:09 +01:00
parent 0df719d531
commit e17a1a0869
46 changed files with 578 additions and 348 deletions

View File

@ -284,12 +284,7 @@
"blockId": "webhookBlock",
"type": "Webhook",
"options": { "responseVariableMapping": [], "variablesForTest": [] },
"webhook": {
"id": "3zZp4961n6CeorWR43jdV9",
"method": "GET",
"headers": [],
"queryParams": []
}
"webhookId": "webhook1"
}
]
}

View File

@ -1,9 +1,6 @@
import { FullConfig } from '@playwright/test'
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')

View File

@ -1,8 +1,6 @@
import {
Block,
defaultSettings,
defaultTheme,
PublicBlock,
PublicTypebot,
Step,
Typebot,
@ -12,12 +10,13 @@ import { readFileSync } from 'fs'
const prisma = new PrismaClient()
export const teardownDatabase = () => {
export const teardownDatabase = async () => {
try {
return prisma.user.delete({
await prisma.user.delete({
where: { id: 'user' },
})
} catch {}
return
}
export const setupDatabase = () => createUser()
@ -32,6 +31,15 @@ export const createUser = () =>
},
})
export const createWebhook = (typebotId: string) =>
prisma.webhook.create({
data: {
id: 'webhook1',
typebotId: typebotId,
method: 'GET',
},
})
export const createTypebots = async (partialTypebots: Partial<Typebot>[]) => {
await prisma.typebot.createMany({
data: partialTypebots.map(parseTestTypebot) as any[],
@ -49,7 +57,7 @@ const parseTypebotToPublicTypebot = (
): PublicTypebot => ({
id,
name: typebot.name,
blocks: parseBlocksToPublicBlocks(typebot.blocks),
blocks: typebot.blocks,
typebotId: typebot.id,
theme: typebot.theme,
settings: typebot.settings,
@ -57,16 +65,10 @@ const parseTypebotToPublicTypebot = (
variables: typebot.variables,
edges: typebot.edges,
customDomain: null,
createdAt: typebot.createdAt,
updatedAt: typebot.updatedAt,
})
const parseBlocksToPublicBlocks = (blocks: Block[]): PublicBlock[] =>
blocks.map((b) => ({
...b,
steps: b.steps.map((s) =>
'webhook' in s ? { ...s, webhook: s.webhook.id } : s
),
}))
const parseTestTypebot = (partialTypebot: Partial<Typebot>): Typebot => ({
id: partialTypebot.id ?? 'typebot',
folderId: null,

View File

@ -1,5 +1,9 @@
import test, { expect } from '@playwright/test'
import { createResults, importTypebotInDatabase } from '../services/database'
import {
createResults,
createWebhook,
importTypebotInDatabase,
} from '../services/database'
import path from 'path'
const typebotId = 'webhook-flow'
@ -9,6 +13,7 @@ test.beforeAll(async () => {
path.join(__dirname, '../fixtures/typebots/api.json'),
{ id: typebotId }
)
await createWebhook(typebotId)
await createResults({ typebotId })
} catch (err) {}
})
@ -49,13 +54,13 @@ test('can get webhook steps', async ({ request }) => {
test('can subscribe webhook', async ({ request }) => {
expect(
(
await request.patch(
await request.post(
`/api/typebots/${typebotId}/blocks/webhookBlock/steps/webhookStep/subscribeWebhook`,
{ data: { url: 'https://test.com' } }
)
).status()
).toBe(401)
const response = await request.patch(
const response = await request.post(
`/api/typebots/${typebotId}/blocks/webhookBlock/steps/webhookStep/subscribeWebhook`,
{
headers: {
@ -73,12 +78,12 @@ test('can subscribe webhook', async ({ request }) => {
test('can unsubscribe webhook', async ({ request }) => {
expect(
(
await request.delete(
await request.post(
`/api/typebots/${typebotId}/blocks/webhookBlock/steps/webhookStep/unsubscribeWebhook`
)
).status()
).toBe(401)
const response = await request.delete(
const response = await request.post(
`/api/typebots/${typebotId}/blocks/webhookBlock/steps/webhookStep/unsubscribeWebhook`,
{
headers: { Authorization: 'Bearer userToken' },