♻️ (viewer) Change to features-centric folder structure
This commit is contained in:
committed by
Baptiste Arnaud
parent
643571fe7d
commit
a9d04798bc
1
apps/viewer/src/features/results/index.ts
Normal file
1
apps/viewer/src/features/results/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export { createResultQuery, updateResultQuery } from './queries'
|
@ -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',
|
||||
})
|
||||
}
|
2
apps/viewer/src/features/results/queries/index.ts
Normal file
2
apps/viewer/src/features/results/queries/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './createResultQuery'
|
||||
export * from './updateResultQuery'
|
@ -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,
|
||||
})
|
51
apps/viewer/src/features/results/results.spec.ts
Normal file
51
apps/viewer/src/features/results/results.spec.ts
Normal 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)
|
||||
})
|
Reference in New Issue
Block a user