From 92fe20b3e8c06f1448809a49361d5c34e4583170 Mon Sep 17 00:00:00 2001 From: tryb3l <56679619+tryb3l@users.noreply.github.com> Date: Wed, 18 Sep 2024 23:16:30 +0200 Subject: [PATCH] Add test for non-existent route returning 404 and refactor root route test --- test/routes/root.test.js | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/test/routes/root.test.js b/test/routes/root.test.js index 813eb19..ee40f42 100644 --- a/test/routes/root.test.js +++ b/test/routes/root.test.js @@ -1,13 +1,28 @@ -"use strict"; +'use strict' -const { test } = require("tap"); -const { buildApp } = require("../helper"); +const { test } = require('tap') +const { buildApp } = require('../helper') -test("default root route", async (t) => { - const app = await buildApp(t); +test('default root route', async (t) => { + const app = await buildApp(t) const res = await app.inject({ - url: "/", - }); - t.same(JSON.parse(res.payload), { root: true }); -}); + url: '/', + }) + t.same(JSON.parse(res.payload), { root: true }) +}) + +test('non-existent route returns 404', async (t) => { + const app = await buildApp(t) + + const res = await app.inject({ + url: '/non-existent', + }) + t.equal(res.statusCode, 404) + t.same(JSON.parse(res.payload), { + statusCode: 404, + error: 'Not Found', + message: 'The requested resource could not be found', + requestId: JSON.parse(res.payload).requestId, + }) +})