You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { expect, test } from '@playwright/test'
|
|
|
|
import { queryScalar, resetDatabases, seedQuestions } from './helpers/stack'
|
|
|
|
const apiBase = process.env.FULLSTACK_API_BASE_URL ?? 'http://127.0.0.1:18096'
|
|
|
|
test.describe('full-stack question-bank integration', () => {
|
|
test.beforeEach(() => {
|
|
resetDatabases()
|
|
seedQuestions()
|
|
})
|
|
|
|
test('gateway forwards random question and answer validation against DB-backed questions', async ({
|
|
request,
|
|
}) => {
|
|
const randomResp = await request.post(`${apiBase}/api/v1/questions/random`, {
|
|
data: {},
|
|
})
|
|
expect(randomResp.ok()).toBeTruthy()
|
|
const randomBody = await randomResp.json()
|
|
expect(randomBody.success).toBeTruthy()
|
|
expect(randomBody.data.id).toBeTruthy()
|
|
|
|
const questionID = randomBody.data.id as string
|
|
const validateResp = await request.post(
|
|
`${apiBase}/api/v1/questions/${questionID}/validate-answer`,
|
|
{
|
|
data: { answer: '2' },
|
|
}
|
|
)
|
|
expect(validateResp.ok()).toBeTruthy()
|
|
const validateBody = await validateResp.json()
|
|
expect(validateBody.success).toBeTruthy()
|
|
expect(typeof validateBody.data.matched).toBe('boolean')
|
|
|
|
const dbCount = Number.parseInt(
|
|
queryScalar('questions', 'SELECT COUNT(*) FROM questions WHERE is_active = true;'),
|
|
10
|
|
)
|
|
expect(dbCount).toBeGreaterThanOrEqual(2)
|
|
})
|
|
})
|