✨ (editor) Add unpublish and close typebot options
Introducing more menu items on the "Publised" button in the editor. You can now unpublish a typebot and close it to new responses
This commit is contained in:
@ -1,12 +0,0 @@
|
||||
import { Page } from '@playwright/test'
|
||||
|
||||
export const mockSessionResponsesToOtherUser = async (page: Page) =>
|
||||
page.route('/api/auth/session', (route) => {
|
||||
if (route.request().method() === 'GET') {
|
||||
return route.fulfill({
|
||||
status: 200,
|
||||
body: '{"user":{"id":"otherUserId","name":"James Doe","email":"other-user@email.com","emailVerified":null,"image":"https://avatars.githubusercontent.com/u/16015833?v=4","stripeId":null,"graphNavigation": "TRACKPAD"}}',
|
||||
})
|
||||
}
|
||||
return route.continue()
|
||||
})
|
@ -1,239 +0,0 @@
|
||||
import {
|
||||
CredentialsType,
|
||||
defaultSettings,
|
||||
defaultTheme,
|
||||
PublicTypebot,
|
||||
SmtpCredentialsData,
|
||||
Block,
|
||||
Typebot,
|
||||
Webhook,
|
||||
} from 'models'
|
||||
import { GraphNavigation, Plan, PrismaClient, WorkspaceRole } from 'db'
|
||||
import { readFileSync } from 'fs'
|
||||
import { injectFakeResults } from 'utils'
|
||||
import { encrypt } from 'utils/api'
|
||||
|
||||
const prisma = new PrismaClient()
|
||||
|
||||
const userId = 'userId'
|
||||
export const freeWorkspaceId = 'freeWorkspace'
|
||||
export const starterWorkspaceId = 'starterWorkspace'
|
||||
export const limitTestWorkspaceId = 'limitTestWorkspace'
|
||||
export const apiToken = 'jirowjgrwGREHE'
|
||||
|
||||
export const teardownDatabase = async () => {
|
||||
await prisma.workspace.deleteMany({
|
||||
where: {
|
||||
members: {
|
||||
some: { userId },
|
||||
},
|
||||
},
|
||||
})
|
||||
await prisma.user.deleteMany({
|
||||
where: { id: userId },
|
||||
})
|
||||
return prisma.webhook.deleteMany()
|
||||
}
|
||||
|
||||
export const setupDatabase = async () => {
|
||||
await createWorkspaces()
|
||||
await createUser()
|
||||
}
|
||||
|
||||
export const createWorkspaces = async () =>
|
||||
prisma.workspace.createMany({
|
||||
data: [
|
||||
{
|
||||
id: freeWorkspaceId,
|
||||
name: 'Free workspace',
|
||||
plan: Plan.FREE,
|
||||
},
|
||||
{
|
||||
id: starterWorkspaceId,
|
||||
name: 'Starter workspace',
|
||||
plan: Plan.STARTER,
|
||||
},
|
||||
{
|
||||
id: limitTestWorkspaceId,
|
||||
name: 'Limit test workspace',
|
||||
plan: Plan.FREE,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
export const createUser = async () => {
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
id: userId,
|
||||
email: 'user@email.com',
|
||||
name: 'John Doe',
|
||||
graphNavigation: GraphNavigation.TRACKPAD,
|
||||
apiTokens: {
|
||||
createMany: {
|
||||
data: [
|
||||
{
|
||||
name: 'Token',
|
||||
token: apiToken,
|
||||
createdAt: new Date(2022, 1, 1),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
await prisma.memberInWorkspace.createMany({
|
||||
data: [
|
||||
{ role: WorkspaceRole.ADMIN, userId, workspaceId: freeWorkspaceId },
|
||||
{ role: WorkspaceRole.ADMIN, userId, workspaceId: starterWorkspaceId },
|
||||
{ role: WorkspaceRole.ADMIN, userId, workspaceId: limitTestWorkspaceId },
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
export const createWebhook = (typebotId: string, webhook?: Partial<Webhook>) =>
|
||||
prisma.webhook.create({
|
||||
data: {
|
||||
id: 'webhook1',
|
||||
typebotId,
|
||||
method: 'GET',
|
||||
...webhook,
|
||||
},
|
||||
})
|
||||
|
||||
export const createTypebots = async (partialTypebots: Partial<Typebot>[]) => {
|
||||
await prisma.typebot.createMany({
|
||||
data: partialTypebots.map(parseTestTypebot),
|
||||
})
|
||||
return prisma.publicTypebot.createMany({
|
||||
data: partialTypebots.map((t) =>
|
||||
parseTypebotToPublicTypebot(t.id + '-published', parseTestTypebot(t))
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
export const updateTypebot = async (
|
||||
partialTypebot: Partial<Typebot> & { id: string }
|
||||
) => {
|
||||
await prisma.typebot.updateMany({
|
||||
where: { id: partialTypebot.id },
|
||||
data: partialTypebot,
|
||||
})
|
||||
return prisma.publicTypebot.updateMany({
|
||||
where: { typebotId: partialTypebot.id },
|
||||
data: partialTypebot,
|
||||
})
|
||||
}
|
||||
|
||||
const parseTypebotToPublicTypebot = (
|
||||
id: string,
|
||||
typebot: Typebot
|
||||
): PublicTypebot => ({
|
||||
id,
|
||||
groups: typebot.groups,
|
||||
typebotId: typebot.id,
|
||||
theme: typebot.theme,
|
||||
settings: typebot.settings,
|
||||
variables: typebot.variables,
|
||||
edges: typebot.edges,
|
||||
createdAt: typebot.createdAt,
|
||||
updatedAt: typebot.updatedAt,
|
||||
})
|
||||
|
||||
const parseTestTypebot = (partialTypebot: Partial<Typebot>): Typebot => ({
|
||||
id: partialTypebot.id ?? 'typebot',
|
||||
folderId: null,
|
||||
name: 'My typebot',
|
||||
workspaceId: freeWorkspaceId,
|
||||
icon: null,
|
||||
theme: defaultTheme,
|
||||
settings: defaultSettings,
|
||||
publicId: partialTypebot.id + '-public',
|
||||
publishedTypebotId: null,
|
||||
updatedAt: new Date().toISOString(),
|
||||
createdAt: new Date().toISOString(),
|
||||
customDomain: null,
|
||||
variables: [{ id: 'var1', name: 'var1' }],
|
||||
...partialTypebot,
|
||||
edges: [
|
||||
{
|
||||
id: 'edge1',
|
||||
from: { groupId: 'group0', blockId: 'block0' },
|
||||
to: { groupId: 'group1' },
|
||||
},
|
||||
],
|
||||
groups: [
|
||||
{
|
||||
id: 'group0',
|
||||
title: 'Group #0',
|
||||
blocks: [
|
||||
{
|
||||
id: 'block0',
|
||||
type: 'start',
|
||||
groupId: 'group0',
|
||||
label: 'Start',
|
||||
outgoingEdgeId: 'edge1',
|
||||
},
|
||||
],
|
||||
graphCoordinates: { x: 0, y: 0 },
|
||||
},
|
||||
...(partialTypebot.groups ?? []),
|
||||
],
|
||||
})
|
||||
|
||||
export const parseDefaultGroupWithBlock = (
|
||||
block: Partial<Block>
|
||||
): Pick<Typebot, 'groups'> => ({
|
||||
groups: [
|
||||
{
|
||||
graphCoordinates: { x: 200, y: 200 },
|
||||
id: 'group1',
|
||||
blocks: [
|
||||
{
|
||||
id: 'block1',
|
||||
groupId: 'group1',
|
||||
...block,
|
||||
} as Block,
|
||||
],
|
||||
title: 'Group #1',
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
export const importTypebotInDatabase = async (
|
||||
path: string,
|
||||
updates?: Partial<Typebot>
|
||||
) => {
|
||||
const typebot: Typebot = {
|
||||
...JSON.parse(readFileSync(path).toString()),
|
||||
workspaceId: starterWorkspaceId,
|
||||
...updates,
|
||||
}
|
||||
await prisma.typebot.create({
|
||||
data: typebot,
|
||||
})
|
||||
return prisma.publicTypebot.create({
|
||||
data: parseTypebotToPublicTypebot(
|
||||
updates?.id ? `${updates?.id}-public` : 'publicBot',
|
||||
typebot
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
export const createResults = injectFakeResults(prisma)
|
||||
|
||||
export const createSmtpCredentials = (
|
||||
id: string,
|
||||
smtpData: SmtpCredentialsData
|
||||
) => {
|
||||
const { encryptedData, iv } = encrypt(smtpData)
|
||||
return prisma.credentials.create({
|
||||
data: {
|
||||
id,
|
||||
data: encryptedData,
|
||||
iv,
|
||||
name: smtpData.from.email as string,
|
||||
type: CredentialsType.SMTP,
|
||||
workspaceId: freeWorkspaceId,
|
||||
},
|
||||
})
|
||||
}
|
23
apps/viewer/playwright/services/databaseActions.ts
Normal file
23
apps/viewer/playwright/services/databaseActions.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { CredentialsType, SmtpCredentialsData } from 'models'
|
||||
import { PrismaClient } from 'db'
|
||||
import { encrypt } from 'utils/api'
|
||||
import { freeWorkspaceId } from 'utils/playwright/databaseSetup'
|
||||
|
||||
const prisma = new PrismaClient()
|
||||
|
||||
export const createSmtpCredentials = (
|
||||
id: string,
|
||||
smtpData: SmtpCredentialsData
|
||||
) => {
|
||||
const { encryptedData, iv } = encrypt(smtpData)
|
||||
return prisma.credentials.create({
|
||||
data: {
|
||||
id,
|
||||
data: encryptedData,
|
||||
iv,
|
||||
name: smtpData.from.email as string,
|
||||
type: CredentialsType.SMTP,
|
||||
workspaceId: freeWorkspaceId,
|
||||
},
|
||||
})
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
import { Page } from '@playwright/test'
|
||||
|
||||
export const typebotViewer = (page: Page) =>
|
||||
page.frameLocator('#typebot-iframe')
|
Reference in New Issue
Block a user