2018-10-12 20:44:03 +03:00
|
|
|
const should = require('should');
|
2022-09-09 14:51:12 +03:00
|
|
|
const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework');
|
|
|
|
const {anyObjectId, anyEtag, anyLocationFor} = matchers;
|
|
|
|
|
|
|
|
const matchNotification = {
|
|
|
|
id: anyObjectId
|
|
|
|
};
|
2019-09-20 18:02:45 +03:00
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
describe('Notifications API', function () {
|
2022-09-09 14:51:12 +03:00
|
|
|
let agent;
|
2020-11-30 17:25:22 +03:00
|
|
|
|
|
|
|
before(async function () {
|
2022-09-09 14:51:12 +03:00
|
|
|
agent = await agentProvider.getAdminAPIAgent();
|
|
|
|
await fixtureManager.init();
|
|
|
|
await agent.loginAsOwner();
|
2018-10-12 20:44:03 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can add notification', async function () {
|
2019-02-04 17:16:24 +03:00
|
|
|
const newNotification = {
|
|
|
|
type: 'info',
|
|
|
|
message: 'test notification',
|
|
|
|
custom: true,
|
2022-09-09 14:51:12 +03:00
|
|
|
id: '59a952be7d79ed06b0d21133'
|
2019-02-04 17:16:24 +03:00
|
|
|
};
|
|
|
|
|
2022-09-09 14:51:12 +03:00
|
|
|
await agent
|
|
|
|
.post('notifications')
|
|
|
|
.body({
|
|
|
|
notifications: [newNotification]
|
|
|
|
})
|
|
|
|
.expectStatus(201)
|
|
|
|
.matchBodySnapshot()
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
});
|
2018-10-12 20:44:03 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can delete notification', async function () {
|
2019-04-18 12:25:17 +03:00
|
|
|
const newNotification = {
|
2018-10-12 20:44:03 +03:00
|
|
|
type: 'info',
|
|
|
|
message: 'test notification',
|
|
|
|
status: 'alert',
|
|
|
|
custom: true
|
|
|
|
};
|
|
|
|
|
2022-09-09 14:51:12 +03:00
|
|
|
// create the notification to deleted
|
|
|
|
const res = await agent
|
|
|
|
.post('notifications')
|
|
|
|
.body({
|
|
|
|
notifications: [newNotification]
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
notifications: [matchNotification]
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag,
|
|
|
|
location: anyLocationFor('notifications')
|
|
|
|
});
|
2020-11-30 17:25:22 +03:00
|
|
|
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
|
|
|
|
should.exist(jsonResponse.notifications);
|
|
|
|
jsonResponse.notifications.length.should.eql(1);
|
|
|
|
|
|
|
|
jsonResponse.notifications[0].type.should.equal(newNotification.type);
|
|
|
|
jsonResponse.notifications[0].message.should.equal(newNotification.message);
|
|
|
|
jsonResponse.notifications[0].status.should.equal(newNotification.status);
|
|
|
|
|
|
|
|
const notification = jsonResponse.notifications[0];
|
|
|
|
|
2022-09-09 14:51:12 +03:00
|
|
|
const res2 = await agent
|
|
|
|
.delete(`notifications/${notification.id}/`)
|
|
|
|
.matchBodySnapshot()
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.expectStatus(204);
|
|
|
|
|
|
|
|
const res3 = await agent
|
|
|
|
.get('notifications')
|
|
|
|
.matchBodySnapshot({
|
|
|
|
notifications: [matchNotification]
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.expectStatus(200);
|
2020-11-30 17:25:22 +03:00
|
|
|
|
|
|
|
const deleted = res3.body.notifications.filter(n => n.id === notification.id);
|
|
|
|
deleted.should.be.empty();
|
2018-10-12 20:44:03 +03:00
|
|
|
});
|
|
|
|
});
|