From c2a79e1d7c6905c0ea33225ef92a31b88f7dc3be Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Sun, 1 Mar 2020 22:37:29 +0100 Subject: [PATCH] fix tests --- test/api/unit/middlewares/response.js | 41 +++------------------------ 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/test/api/unit/middlewares/response.js b/test/api/unit/middlewares/response.js index b8157287be..dbc689276a 100644 --- a/test/api/unit/middlewares/response.js +++ b/test/api/unit/middlewares/response.js @@ -34,7 +34,7 @@ describe('response middleware', () => { expect(res.json).to.be.calledWith({ success: true, data: { field: 1 }, - notifications: [], + notifications: res.locals.user.notifications, userV: res.locals.user._v, appVersion: packageInfo.version, }); @@ -52,7 +52,7 @@ describe('response middleware', () => { success: true, data: { field: 1 }, message: 'hello', - notifications: [], + notifications: res.locals.user.notifications, userV: res.locals.user._v, appVersion: packageInfo.version, }); @@ -69,7 +69,7 @@ describe('response middleware', () => { expect(res.json).to.be.calledWith({ success: false, data: { field: 1 }, - notifications: [], + notifications: res.locals.user.notifications, userV: res.locals.user._v, appVersion: packageInfo.version, }); @@ -84,42 +84,9 @@ describe('response middleware', () => { expect(res.json).to.be.calledWith({ success: true, data: { field: 1 }, - notifications: [], + notifications: res.locals.user.notifications, userV: 0, appVersion: packageInfo.version, }); }); - - it('returns notifications if a user is authenticated', () => { - const { user } = res.locals; - - user.notifications = [ - null, // invalid, not an object - { seen: true }, // invalid, no type or id - { id: 123 }, // invalid, no type - // invalid, no id, not included here because the id would be added automatically - // {type: 'ABC'}, - { type: 'ABC', id: '123' }, // valid - ]; - - responseMiddleware(req, res, next); - res.respond(200, { field: 1 }); - - expect(res.json).to.be.calledOnce; - - expect(res.json).to.be.calledWith({ - success: true, - data: { field: 1 }, - notifications: [ - { - type: 'ABC', - id: '123', - data: {}, - seen: false, - }, - ], - userV: res.locals.user._v, - appVersion: packageInfo.version, - }); - }); });