Skip to content

Commit 73e1175

Browse files
committed
test: improve validation
1 parent 609b84d commit 73e1175

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

__tests__/httpServer/apiV1.test.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,12 @@ describe('HTTP Server API V1', () => {
400400
const storedChecks = await getAllChecks()
401401

402402
expect(response.status).toBe(200)
403-
// @TODO: find a more elegant way to solve the issue with the date format
404-
expect(response.body).toStrictEqual(JSON.parse(JSON.stringify(storedChecks)))
403+
const expected = storedChecks.map(c => ({
404+
...c,
405+
created_at: c.created_at.toISOString(),
406+
updated_at: c.updated_at.toISOString()
407+
}))
408+
expect(response.body).toStrictEqual(expected)
405409
})
406410

407411
test.todo('should return 500 for internal server error')
@@ -413,8 +417,12 @@ describe('HTTP Server API V1', () => {
413417
const storedCheck = await getCheckById(1)
414418

415419
expect(response.status).toBe(200)
416-
// @TODO: find a more elegant way to solve the issue with the date format
417-
expect(response.body).toStrictEqual(JSON.parse(JSON.stringify(storedCheck)))
420+
const expected = {
421+
...storedCheck,
422+
created_at: storedCheck.created_at.toISOString(),
423+
updated_at: storedCheck.updated_at.toISOString()
424+
}
425+
expect(response.body).toStrictEqual(expected)
418426
})
419427

420428
test('should return 400 for invalid check ID', async () => {
@@ -442,8 +450,12 @@ describe('HTTP Server API V1', () => {
442450
const storedChecklists = await getAllChecklists()
443451

444452
expect(response.status).toBe(200)
445-
// @TODO: find a more elegant way to solve the issue with the date format
446-
expect(response.body).toStrictEqual(JSON.parse(JSON.stringify(storedChecklists)))
453+
const expected = storedChecklists.map(c => ({
454+
...c,
455+
created_at: c.created_at.toISOString(),
456+
updated_at: c.updated_at.toISOString()
457+
}))
458+
expect(response.body).toStrictEqual(expected)
447459
})
448460

449461
test.todo('should return 500 for internal server error')

0 commit comments

Comments
 (0)