Skip to content

Commit

Permalink
updated package.json with jest:test.
Browse files Browse the repository at this point in the history
created defaultRoute testing.
updated error-handler.js with custom msg.
  • Loading branch information
IrinaGM committed Nov 30, 2019
1 parent 5ac035c commit b908668
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"scripts": {
"start": "node src/index.js",
"test": "jest",
"test:local": "NODE_ENV=development jest",
"start:local": "NODE_ENV=development nodemon src/index.js",
"start:production": "NODE_ENV=production nodemon src/index.js",
"test:watch": "jest --watch"
Expand Down
9 changes: 7 additions & 2 deletions src/middleware/error-handler.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
const { logger } = require("../utils/logger");
const { logger } = require('../utils/logger');

const errorHandler = (err, req, res, next) => {
logger.error(err.message);
if (!err.statusCode) err.statusCode = 500;
res.status(err.statusCode).send(err.message);
res
.status(err.statusCode)
.send(
'There was a problem retrieving the data. The following error has accured:' +
err.message
);
};

module.exports = {
Expand Down
12 changes: 7 additions & 5 deletions src/routes/defaultRoute/defaultRoute.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const request = require('supertest');
const { app } = require('../../index');

const { defaultRouter } = require('./defaultRoute.router');
//const { defaultRouter } = require('./defaultRoute.router');

describe('tests for default route endpoint', () => {
it('returns correct response to non existing route', () => {
const response = {
it('responds with json containing error when route does not exist', async () => {
const response = await request(app).get('/default');
expect(response.statusCode).toEqual(404);
expect(response.body).toEqual({
error: 'Incorrect Route'
};
expect(defaultRouter).toContain(response);
});
});
});

0 comments on commit b908668

Please sign in to comment.