Skip to content

Commit

Permalink
🔧 Enable usage limits on viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Dec 5, 2022
1 parent 4b2f42b commit cfcecaa
Show file tree
Hide file tree
Showing 4 changed files with 334 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ import cuid from 'cuid'
import { parse } from 'papaparse'
import { readFileSync } from 'fs'
import { isDefined } from 'utils'
import { importTypebotInDatabase } from 'utils/playwright/databaseActions'
import {
createWorkspaces,
importTypebotInDatabase,
injectFakeResults,
} from 'utils/playwright/databaseActions'
import { typebotViewer } from 'utils/playwright/testHelpers'
import { getTestAsset } from '@/test/utils/playwright'
import { Plan } from 'db'

// const THREE_GIGABYTES = 3 * 1024 * 1024 * 1024
const THREE_GIGABYTES = 3 * 1024 * 1024 * 1024

test('should work as expected', async ({ page, browser }) => {
const typebotId = cuid()
Expand Down Expand Up @@ -73,47 +78,45 @@ test('should work as expected', async ({ page, browser }) => {
await expect(page2.locator('pre')).toBeHidden()
})

// TODO: uncomment on 1st of November

// test.describe('Storage limit is reached', () => {
// const typebotId = cuid()
test.describe('Storage limit is reached', () => {
const typebotId = cuid()
const workspaceId = cuid()

// test.beforeAll(async () => {
// await importTypebotInDatabase(
// path.join(__dirname, '../fixtures/typebots/fileUpload.json'),
// {
// id: typebotId,
// publicId: `${typebotId}-public`,
// }
// )
// await createResults({
// typebotId,
// count: 20,
// fakeStorage: THREE_GIGABYTES,
// })
// })
test.beforeAll(async () => {
await createWorkspaces([{ id: workspaceId, plan: Plan.STARTER }])
await importTypebotInDatabase(getTestAsset('typebots/fileUpload.json'), {
id: typebotId,
publicId: `${typebotId}-public`,
workspaceId,
})
await injectFakeResults({
typebotId,
count: 20,
fakeStorage: THREE_GIGABYTES,
})
})

// test("shouldn't upload anything if limit has been reached", async ({
// page,
// }) => {
// await page.goto(`/${typebotId}-public`)
// await typebotViewer(page)
// .locator(`input[type="file"]`)
// .setInputFiles([
// path.join(__dirname, '../fixtures/typebots/api.json'),
// path.join(__dirname, '../fixtures/typebots/fileUpload.json'),
// path.join(__dirname, '../fixtures/typebots/hugeGroup.json'),
// ])
// await expect(typebotViewer(page).locator(`text="3"`)).toBeVisible()
// await typebotViewer(page).locator('text="Upload 3 files"').click()
// await expect(
// typebotViewer(page).locator(`text="3 files uploaded"`)
// ).toBeVisible()
// await page.evaluate(() =>
// window.localStorage.setItem('workspaceId', 'starterWorkspace')
// )
// await page.goto(`${process.env.NEXTAUTH_URL}/typebots/${typebotId}/results`)
// await expect(page.locator('text="150%"')).toBeVisible()
// await expect(page.locator('text="api.json"')).toBeHidden()
// })
// })
test("shouldn't upload anything if limit has been reached", async ({
page,
}) => {
await page.goto(`/${typebotId}-public`)
await typebotViewer(page)
.locator(`input[type="file"]`)
.setInputFiles([
getTestAsset('typebots/api.json'),
getTestAsset('typebots/fileUpload.json'),
getTestAsset('typebots/hugeGroup.json'),
])
await expect(typebotViewer(page).locator(`text="3"`)).toBeVisible()
await typebotViewer(page).locator('text="Upload 3 files"').click()
await expect(
typebotViewer(page).locator(`text="3 files uploaded"`)
).toBeVisible()
await page.evaluate(() =>
window.localStorage.setItem('workspaceId', 'starterWorkspace')
)
await page.goto(`${process.env.NEXTAUTH_URL}/typebots/${typebotId}/results`)
await expect(page.locator('text="150%"')).toBeVisible()
await expect(page.locator('text="api.json"')).toBeHidden()
})
})
86 changes: 71 additions & 15 deletions apps/viewer/src/features/usage/usage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,75 @@
import { getTestAsset } from '@/test/utils/playwright'
import test, { expect } from '@playwright/test'
import cuid from 'cuid'
import { Plan } from 'db'
import { defaultSettings } from 'models'
import {
createWorkspaces,
importTypebotInDatabase,
injectFakeResults,
} from 'utils/playwright/databaseActions'
import { typebotViewer } from 'utils/playwright/testHelpers'

// TODO: uncomment on 1st of November
test('should not start if chat limit is reached', async ({ page, context }) => {
await test.step('Free plan', async () => {
const workspaceId = cuid()
const typebotId = cuid()
await createWorkspaces([{ id: workspaceId, plan: Plan.FREE }])
await importTypebotInDatabase(getTestAsset('typebots/fileUpload.json'), {
id: typebotId,
publicId: `${typebotId}-public`,
workspaceId,
})
await injectFakeResults({ typebotId, count: 400 })
await page.goto(`/${typebotId}-public`)
await expect(page.locator('text="This bot is now closed."')).toBeVisible()
await page.goto(`${process.env.NEXTAUTH_URL}/typebots/${typebotId}/results`)
await expect(page.locator('text="133%"')).toBeVisible()
})

// test('should not start if chat limit is reached', async ({ page }) => {
// const typebotId = cuid()
// await importTypebotInDatabase(
// path.join(__dirname, '../fixtures/typebots/fileUpload.json'),
// {
// id: typebotId,
// publicId: `${typebotId}-public`,
// workspaceId: limitTestWorkspaceId,
// }
// )
// await createResults({ typebotId, count: 320 })
// await page.goto(`/${typebotId}-public`)
// await expect(page.locator('text="This bot is now closed."')).toBeVisible()
// })
await test.step('Lifetime plan', async () => {
const workspaceId = cuid()
const typebotId = cuid()
await createWorkspaces([{ id: workspaceId, plan: Plan.LIFETIME }])
await importTypebotInDatabase(getTestAsset('typebots/fileUpload.json'), {
id: typebotId,
publicId: `${typebotId}-public`,
workspaceId,
})
await injectFakeResults({ typebotId, count: 3000 })
await page.goto(`/${typebotId}-public`)
await expect(
typebotViewer(page).locator('text="Hey there, upload please"')
).toBeVisible()
})

await test.step('Custom plan', async () => {
const workspaceId = cuid()
const typebotId = cuid()
await createWorkspaces([
{ id: workspaceId, plan: Plan.CUSTOM, customChatsLimit: 1000 },
])
await importTypebotInDatabase(getTestAsset('typebots/fileUpload.json'), {
id: typebotId,
publicId: `${typebotId}-public`,
workspaceId,
settings: {
...defaultSettings,
general: {
...defaultSettings.general,
isNewResultOnRefreshEnabled: true,
},
},
})
const page = await context.newPage()
await page.goto(`/${typebotId}-public`)
await expect(
typebotViewer(page).locator('text="Hey there, upload please"')
).toBeVisible()
await injectFakeResults({ typebotId, count: 2000 })
await page.goto(`/${typebotId}-public`)
await expect(page.locator('text="This bot is now closed."')).toBeVisible()
await page.goto(`${process.env.NEXTAUTH_URL}/typebots/${typebotId}/results`)
await expect(page.locator('text="200%"')).toBeVisible()
})
})
Loading

5 comments on commit cfcecaa

@vercel
Copy link

@vercel vercel bot commented on cfcecaa Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on cfcecaa Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on cfcecaa Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./apps/docs

docs-typebot-io.vercel.app
docs.typebot.io
docs-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on cfcecaa Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on cfcecaa Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2-alpha – ./apps/viewer

ns8.vn
yobot.me
247987.com
8jours.top
bot.aws.bj
bot.bbc.bj
finplex.be
sat.cr8.ai
bot.aipr.kr
minipost.uk
bt.id8rs.com
bot.krdfy.com
goldorayo.com
signup.cr8.ai
vhpage.cr8.ai
am.nigerias.io
an.nigerias.io
ar.nigerias.io
bot.enreso.org
bot.lalmon.com
ticketfute.com
apo.nigerias.io
apr.nigerias.io
aso.nigerias.io
bot.ageenda.com
bot.artiweb.app
bot.devitus.com
bot.tc-mail.com
chat.sureb4.com
eventhub.com.au
games.klujo.com
sakuranembro.it
typebot.aloe.do
bot.piccinato.co
botc.ceox.com.br
clo.closeer.work
faqs.nigerias.io
feedback.ofx.one
form.syncwin.com
kw.wpwakanda.com
myrentalhost.com
stan.vselise.com
start.taxtree.io
typebot.aloe.bot
voicehelp.cr8.ai
app.chatforms.net
bot.agfunnel.tech
bot.hostnation.de
bot.maitempah.com
bot.phuonghub.com
bot.reviewzer.com
cares.urlabout.me
fmm.wpwakanda.com
gentleman-shop.fr
k1.kandabrand.com
lb.ticketfute.com
ov1.wpwakanda.com
ov2.wpwakanda.com
ov3.wpwakanda.com
1988.bouclidom.com
andreimayer.com.br
bot.megafox.com.br
bot.neferlopez.com
bots.robomotion.io
cadu.uninta.edu.br
dicanatural.online
goalsettingbot.com
positivobra.com.br
survey.digienge.io
this-is-a-test.com
zap.techadviser.in
bot.digitalbled.com
bot.eventhub.com.au
bot.jepierre.com.br
bot.winglabs.com.br
carsalesenquiry.com
demo.botscientis.us
forms.webisharp.com
kbsub.wpwakanda.com
live.botscientis.us
mentoria.omelhor.vc
nutrisamirbayde.com
order.maitempah.com
quest.wpwakanda.com
survey1.digienge.io
test.botscientis.us
typebot.stillio.com
wordsandimagery.com
bium.gratirabbit.com
bot.ansuraniphone.my
bot.cotemeuplano.com
chat.hayurihijab.com
chatbee.agfunnel.com
click.sevenoways.com
connect.growthguy.in
kuiz.sistemniaga.com
onboarding.growthside.io
type.opaulovieira.com.br
aibot.angrybranding.co.uk
bot.aidigitalmarketing.kr

Please sign in to comment.