2
0

♻️ (viewer) Change to features-centric folder structure

This commit is contained in:
Baptiste Arnaud
2022-11-15 10:28:03 +01:00
committed by Baptiste Arnaud
parent 643571fe7d
commit a9d04798bc
80 changed files with 523 additions and 491 deletions

View File

@ -0,0 +1 @@
export { createResultQuery, updateResultQuery } from './queries'

View File

@ -0,0 +1,9 @@
import { Result } from 'models'
import { sendRequest } from 'utils'
export const createResultQuery = async (typebotId: string) => {
return sendRequest<{ result: Result; hasReachedLimit: boolean }>({
url: `/api/typebots/${typebotId}/results`,
method: 'POST',
})
}

View File

@ -0,0 +1,2 @@
export * from './createResultQuery'
export * from './updateResultQuery'

View File

@ -0,0 +1,12 @@
import { Result } from 'models'
import { sendRequest } from 'utils'
export const updateResultQuery = async (
resultId: string,
result: Partial<Result>
) =>
sendRequest<Result>({
url: `/api/typebots/t/results/${resultId}`,
method: 'PATCH',
body: result,
})

View File

@ -0,0 +1,51 @@
import { getTestAsset } from '@/test/utils/playwright'
import test, { expect } from '@playwright/test'
import cuid from 'cuid'
import {
importTypebotInDatabase,
injectFakeResults,
} from 'utils/playwright/databaseActions'
import { apiToken } from 'utils/playwright/databaseSetup'
import { typebotViewer } from 'utils/playwright/testHelpers'
test('Big groups should work as expected', async ({ page }) => {
const typebotId = cuid()
await importTypebotInDatabase(getTestAsset('typebots/hugeGroup.json'), {
id: typebotId,
publicId: `${typebotId}-public`,
})
await page.goto(`/${typebotId}-public`)
await typebotViewer(page).locator('input').fill('Baptiste')
await typebotViewer(page).locator('input').press('Enter')
await typebotViewer(page).locator('input').fill('26')
await typebotViewer(page).locator('input').press('Enter')
await typebotViewer(page).locator('button >> text=Yes').click()
await page.goto(`${process.env.NEXTAUTH_URL}/typebots/${typebotId}/results`)
await expect(page.locator('text="Baptiste"')).toBeVisible()
await expect(page.locator('text="26"')).toBeVisible()
await expect(page.locator('text="Yes"')).toBeVisible()
await page.hover('tbody > tr')
await page.click('button >> text="Open"')
await expect(page.locator('text="Baptiste" >> nth=1')).toBeVisible()
await expect(page.locator('text="26" >> nth=1')).toBeVisible()
await expect(page.locator('text="Yes" >> nth=1')).toBeVisible()
})
test('can list results with API', async ({ request }) => {
const typebotId = cuid()
await importTypebotInDatabase(getTestAsset('typebots/api.json'), {
id: typebotId,
})
await injectFakeResults({ typebotId, count: 20 })
expect(
(await request.get(`/api/typebots/${typebotId}/results`)).status()
).toBe(401)
const response = await request.get(
`/api/typebots/${typebotId}/results?limit=10`,
{
headers: { Authorization: `Bearer ${apiToken}` },
}
)
const { results } = await response.json()
expect(results).toHaveLength(10)
})