fix tests

This commit is contained in:
Matteo Pagliazzi
2020-03-01 22:37:29 +01:00
parent c5208f0ef6
commit c2a79e1d7c

View File

@@ -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,
});
});
});