2
0

(billing) Implement custom plan

This commit is contained in:
Baptiste Arnaud
2022-10-27 11:32:21 +02:00
committed by Baptiste Arnaud
parent 3f7dc79918
commit 385853ca3c
23 changed files with 395 additions and 68 deletions

View File

@@ -10,4 +10,5 @@ SMTP_USERNAME=tobin.tillman65@ethereal.email
SMTP_PASSWORD=Ty9BcwCBrK6w8AG2hx
STRIPE_TEST_PUBLIC_KEY=
STRIPE_TEST_SECRET_KEY=
STRIPE_TEST_SECRET_KEY=
STRIPE_STARTER_PRICE_ID=

View File

@@ -1,4 +1,10 @@
import { CollaborationType, DashboardFolder, PrismaClient, Workspace } from 'db'
import {
CollaborationType,
DashboardFolder,
Prisma,
PrismaClient,
Workspace,
} from 'db'
import Stripe from 'stripe'
import { proWorkspaceId } from 'utils/playwright/databaseSetup'
@@ -74,3 +80,10 @@ export const createFolder = (workspaceId: string, name: string) =>
name,
},
})
export const createClaimableCustomPlan = async (
data: Prisma.ClaimableCustomPlanUncheckedCreateInput
) =>
prisma.claimableCustomPlan.create({
data,
})

View File

@@ -1,7 +1,10 @@
import test, { expect } from '@playwright/test'
import cuid from 'cuid'
import { Plan } from 'db'
import { addSubscriptionToWorkspace } from 'playwright/services/databaseActions'
import {
addSubscriptionToWorkspace,
createClaimableCustomPlan,
} from 'playwright/services/databaseActions'
import {
createTypebots,
createWorkspaces,
@@ -12,6 +15,7 @@ import {
const usageWorkspaceId = cuid()
const usageTypebotId = cuid()
const planChangeWorkspaceId = cuid()
const enterpriseWorkspaceId = cuid()
test.beforeAll(async () => {
await createWorkspaces([
@@ -24,12 +28,20 @@ test.beforeAll(async () => {
id: planChangeWorkspaceId,
name: 'Plan Change Workspace',
},
{
id: enterpriseWorkspaceId,
name: 'Enterprise Workspace',
},
])
await createTypebots([{ id: usageTypebotId, workspaceId: usageWorkspaceId }])
})
test.afterAll(async () => {
await deleteWorkspaces([usageWorkspaceId, planChangeWorkspaceId])
await deleteWorkspaces([
usageWorkspaceId,
planChangeWorkspaceId,
enterpriseWorkspaceId,
])
})
test('should display valid usage', async ({ page }) => {
@@ -38,14 +50,37 @@ test('should display valid usage', async ({ page }) => {
await page.click('text=Billing & Usage')
await expect(page.locator('text="/ 10,000"')).toBeVisible()
await expect(page.locator('text="/ 10 GB"')).toBeVisible()
await page.getByText('Members', { exact: true }).click()
await expect(
page.getByRole('heading', { name: 'Members (1/5)' })
).toBeVisible()
await page.click('text=Pro workspace', { force: true })
await page.click('text=Pro workspace')
await page.click('text="Custom workspace"')
await page.click('text=Settings & Members')
await page.click('text=Billing & Usage')
await expect(page.locator('text="/ 100,000"')).toBeVisible()
await expect(page.locator('text="/ 50 GB"')).toBeVisible()
await expect(page.getByText('Upgrade to Starter')).toBeHidden()
await expect(page.getByText('Upgrade to Pro')).toBeHidden()
await expect(page.getByText('Need custom limits?')).toBeHidden()
await page.getByText('Members', { exact: true }).click()
await expect(
page.getByRole('heading', { name: 'Members (1/20)' })
).toBeVisible()
await page.click('text=Custom workspace', { force: true })
await page.click('text=Custom workspace')
await page.click('text="Free workspace"')
await page.click('text=Settings & Members')
await page.click('text=Billing & Usage')
await expect(page.locator('text="/ 300"')).toBeVisible()
await expect(page.locator('text="Storage"')).toBeHidden()
await page.getByText('Members', { exact: true }).click()
await expect(
page.getByRole('heading', { name: 'Members (1/1)' })
).toBeVisible()
await page.click('text=Free workspace', { force: true })
await injectFakeResults({
@@ -189,3 +224,30 @@ test('should display invoices', async ({ page }) => {
await expect(page.locator('tr')).toHaveCount(2)
await expect(page.locator('text="€39.00"')).toBeVisible()
})
test('custom plans should work', async ({ page }) => {
await page.goto('/typebots')
await page.click('text=Pro workspace')
await page.click('text=Enterprise Workspace')
await page.click('text=Settings & Members')
await page.click('text=Billing & Usage')
await expect(page.getByTestId('current-subscription')).toHaveText(
'Current workspace subscription: Free'
)
await createClaimableCustomPlan({
currency: 'usd',
price: 239,
workspaceId: enterpriseWorkspaceId,
chatsLimit: 100000,
storageLimit: 50,
seatsLimit: 10,
name: 'Acme custom plan',
description: 'Description of the deal',
})
await page.goto('/api/stripe/custom-plan-checkout')
await expect(page.getByRole('list').getByText('$239.00')).toBeVisible()
await expect(page.getByText('Subscribe to Acme custom plan')).toBeVisible()
await expect(page.getByText('Description of the deal')).toBeVisible()
})

View File

@@ -104,6 +104,9 @@ test('can manage members', async ({ page }) => {
).toHaveAttribute('value', '')
await expect(page.locator('text="guest@email.com"')).toBeVisible()
await expect(page.locator('text="Pending"')).toBeVisible()
await expect(
page.getByRole('heading', { name: 'Members (2/5)' })
).toBeVisible()
await page.fill(
'input[placeholder="colleague@company.com"]',
'other-user@email.com'
@@ -116,6 +119,9 @@ test('can manage members', async ({ page }) => {
).toHaveAttribute('value', '')
await expect(page.locator('text="other-user@email.com"')).toBeVisible()
await expect(page.locator('text="James Doe"')).toBeVisible()
await expect(
page.getByRole('heading', { name: 'Members (3/5)' })
).toBeVisible()
await page.click('text="other-user@email.com"')
await page.click('button >> text="Member"')