2
0
Files
bot/apps/builder/cypress/plugins/database.ts

148 lines
3.1 KiB
TypeScript
Raw Normal View History

2022-01-04 09:15:33 +01:00
import { parseNewTypebot, PublicTypebot, StepType, Typebot } from 'bot-engine'
2021-12-28 11:13:09 +01:00
import { Plan, PrismaClient } from 'db'
2021-12-06 15:48:50 +01:00
const prisma = new PrismaClient()
const teardownTestData = async () => prisma.user.deleteMany()
export const seedDb = async () => {
await teardownTestData()
await createUsers()
await createFolders()
2022-01-04 09:15:33 +01:00
await createTypebots()
await createResults()
return createAnswers()
2021-12-06 15:48:50 +01:00
}
const createUsers = () =>
prisma.user.createMany({
data: [
{ id: 'test1', email: 'test1@gmail.com', emailVerified: new Date() },
2021-12-28 11:13:09 +01:00
{
id: 'test2',
email: 'test2@gmail.com',
emailVerified: new Date(),
plan: Plan.PRO,
stripeId: 'stripe-test2',
},
2021-12-06 15:48:50 +01:00
],
})
const createFolders = () =>
prisma.dashboardFolder.createMany({
data: [{ ownerId: 'test2', name: 'Folder #1', id: 'folder1' }],
})
2022-01-04 09:15:33 +01:00
const createTypebots = async () => {
const typebot2: Typebot = {
...(parseNewTypebot({
name: 'Typebot #2',
ownerId: 'test2',
folderId: null,
}) as Typebot),
id: 'typebot2',
startBlock: {
id: 'start-block',
steps: [
{
id: 'start-step',
blockId: 'start-block',
type: StepType.START,
label: 'Start',
target: { blockId: 'block1' },
},
],
graphCoordinates: { x: 0, y: 0 },
title: 'Start',
},
blocks: [
{
title: 'Block #1',
id: 'block1',
steps: [{ id: 'step1', type: StepType.TEXT_INPUT, blockId: 'block1' }],
graphCoordinates: { x: 200, y: 200 },
},
],
}
await prisma.typebot.createMany({
2021-12-16 10:43:49 +01:00
data: [
2021-12-17 07:54:12 +01:00
{
2021-12-28 11:13:09 +01:00
...parseNewTypebot({
name: 'Typebot #1',
ownerId: 'test2',
folderId: null,
}),
id: 'typebot1',
},
2022-01-04 09:15:33 +01:00
typebot2,
],
})
return prisma.publicTypebot.createMany({
data: [parseTypebotToPublicTypebot('publictypebot2', typebot2)],
})
}
const createResults = () => {
return prisma.result.createMany({
data: [
2021-12-28 11:13:09 +01:00
{
2022-01-04 09:15:33 +01:00
typebotId: 'typebot1',
},
{
typebotId: 'typebot1',
},
{
id: 'result1',
typebotId: 'typebot2',
},
{
id: 'result2',
typebotId: 'typebot2',
},
{
id: 'result3',
typebotId: 'typebot2',
},
],
})
}
const createAnswers = () => {
return prisma.answer.createMany({
data: [
{
resultId: 'result1',
content: 'content 1',
stepId: 'step1',
blockId: 'block1',
},
{
resultId: 'result2',
content: 'content 2',
stepId: 'step1',
blockId: 'block1',
},
{
resultId: 'result3',
content: 'content 3',
stepId: 'step1',
blockId: 'block1',
2021-12-17 07:54:12 +01:00
},
2021-12-16 10:43:49 +01:00
],
2021-12-06 15:48:50 +01:00
})
2021-12-16 10:43:49 +01:00
}
2022-01-04 09:15:33 +01:00
const parseTypebotToPublicTypebot = (
id: string,
typebot: Typebot
): PublicTypebot => ({
id,
blocks: typebot.blocks,
name: typebot.name,
startBlock: typebot.startBlock,
typebotId: typebot.id,
theme: typebot.theme,
settings: typebot.settings,
publicId: typebot.publicId,
})