feat: publish CodexPi contest snapshot
Some checks are pending
Qualité / tests (push) Waiting to run
Some checks are pending
Qualité / tests (push) Waiting to run
This commit is contained in:
22
frontend/tests/apiPayload.test.ts
Normal file
22
frontend/tests/apiPayload.test.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import {expectArrayPayload, readJsonPayload} from '../src/apiPayload.ts'
|
||||
|
||||
test('a truncated successful JSON response is rejected instead of becoming an object', async () => {
|
||||
const response = new Response('{"messages":[', {
|
||||
status: 200,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
})
|
||||
await assert.rejects(() => readJsonPayload(response), /incomplète/i)
|
||||
})
|
||||
|
||||
test('a valid JSON response is decoded', async () => {
|
||||
const response = new Response('[{"id":"message-1"}]', {status: 200})
|
||||
assert.deepEqual(await readJsonPayload(response), [{id: 'message-1'}])
|
||||
})
|
||||
|
||||
test('array endpoints reject a valid but malformed payload', () => {
|
||||
assert.throws(() => expectArrayPayload({}, 'messages'), /messages.*invalide/i)
|
||||
assert.deepEqual(expectArrayPayload([{id: 'message-1'}], 'messages'), [{id: 'message-1'}])
|
||||
})
|
||||
Reference in New Issue
Block a user