From 77bfad0307f4e5daea0584a30b0dcf24ccc9ec42 Mon Sep 17 00:00:00 2001 From: jw255 Date: Thu, 22 Feb 2018 16:57:45 +0000 Subject: restructuring of tests --- src/app.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/app.ts') diff --git a/src/app.ts b/src/app.ts index 4f0e0d7..ef4485e 100644 --- a/src/app.ts +++ b/src/app.ts @@ -5,17 +5,19 @@ import * as logger from 'morgan'; class App { public express: ex.Express; - public logEnabled: boolean = true; + private logEnabled: boolean; - public constructor() { + public constructor(enableLog: boolean) { this.express = ex(); this.middleware(); this.mountRoutes(); + this.logEnabled = enableLog; } // Configure Express middleware. private middleware(): void { if (this.logEnabled) { + console.log("log enabled") this.express.use(logger('combined')); } this.express.use(bodyParser.json()); @@ -36,4 +38,7 @@ class App { } } -export default new App().express; +export default new App(true).express; +export function TestApp(){ + return new App(false).express; +} -- cgit v1.2.1 From 80f5aeb37b3d997015238173499f4a067ec0c266 Mon Sep 17 00:00:00 2001 From: jw255 Date: Sat, 24 Feb 2018 19:34:20 +0000 Subject: tests now actually test what they are supposed to and catch errors if needed --- src/app.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/app.ts') diff --git a/src/app.ts b/src/app.ts index ef4485e..612ba49 100644 --- a/src/app.ts +++ b/src/app.ts @@ -33,8 +33,18 @@ class App { important : 'Endpoints start from /cs3099group-be-4/' }); }); - this.express.use('/', defRouter); + defRouter.get('/*', (req: ex.Request, res: ex.Response): void => { + res.status(404) + .json({ + status: 'error', + error : 'invalid_route', + error_description: 'Endpoints start from /cs3099group-be-4/\n' + +' Please refer to \'https://github.com/CS3099JH2017/cs3099jh/blob/master/protocols/BE01.md\'' + + ' for further details.' + }); + }) this.express.use('/cs3099group-be-4', FileRouter); + this.express.use('/', defRouter); } } -- cgit v1.2.1