diff --git a/src/Infrastructures/http/_test/createServer.test.js b/src/Infrastructures/http/_test/createServer.test.js index a51f571..d2cb281 100644 --- a/src/Infrastructures/http/_test/createServer.test.js +++ b/src/Infrastructures/http/_test/createServer.test.js @@ -521,4 +521,34 @@ describe('HTTP server', () => { expect(responseJson.status).toEqual('error'); expect(responseJson.message).toEqual('terjadi kegagalan pada server kami'); }); + + it('should response 404 when request unregistered route', async () => { + // Arrange + const server = await createServer({}); + + // Action + const response = await server.inject({ + method: 'GET', + url: '/unregisteredRoute', + }); + + // Assert + expect(response.statusCode).toEqual(404); + }); + + describe('when GET /', () => { + it('should return 200 and hello world', async () => { + // Arrange + const server = await createServer({}); + // Action + const response = await server.inject({ + method: 'GET', + url: '/', + }); + // Assert + const responseJson = JSON.parse(response.payload); + expect(response.statusCode).toEqual(200); + expect(responseJson.value).toEqual('Hello world!'); + }); + }); }); diff --git a/src/Infrastructures/http/createServer.js b/src/Infrastructures/http/createServer.js index bf62204..9f67749 100644 --- a/src/Infrastructures/http/createServer.js +++ b/src/Infrastructures/http/createServer.js @@ -23,6 +23,14 @@ const createServer = async (container) => { }, ]); + server.route({ + method: 'GET', + path: '/', + handler: () => ({ + value: 'Hello world!', + }), + }); + server.ext('onPreResponse', (request, h) => { // mendapatkan konteks response dari request const { response } = request;