2018-10-12 20:44:03 +03:00
|
|
|
const should = require('should');
|
|
|
|
const supertest = require('supertest');
|
2019-09-20 18:02:45 +03:00
|
|
|
const testUtils = require('../../utils');
|
2020-05-27 20:47:53 +03:00
|
|
|
const config = require('../../../core/shared/config');
|
2018-10-12 20:44:03 +03:00
|
|
|
const localUtils = require('./utils');
|
2019-09-20 18:02:45 +03:00
|
|
|
|
2018-10-12 20:44:03 +03:00
|
|
|
const ghost = testUtils.startGhost;
|
|
|
|
let request;
|
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
describe('Notifications API', function () {
|
2018-10-12 20:44:03 +03:00
|
|
|
let ghostServer;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
return ghost()
|
|
|
|
.then(function (_ghostServer) {
|
|
|
|
ghostServer = _ghostServer;
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
})
|
|
|
|
.then(function () {
|
|
|
|
return localUtils.doAuth(request);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-18 12:25:17 +03:00
|
|
|
it('Can add notification', function () {
|
2019-02-04 17:16:24 +03:00
|
|
|
const newNotification = {
|
|
|
|
type: 'info',
|
|
|
|
message: 'test notification',
|
|
|
|
custom: true,
|
|
|
|
id: 'customId'
|
|
|
|
};
|
|
|
|
|
2019-04-18 12:25:17 +03:00
|
|
|
return request.post(localUtils.API.getApiQuery('notifications/'))
|
2019-02-04 17:16:24 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.send({notifications: [newNotification]})
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(201)
|
2019-04-18 12:25:17 +03:00
|
|
|
.then(function (res) {
|
2020-04-29 18:44:27 +03:00
|
|
|
const jsonResponse = res.body;
|
2019-02-04 17:16:24 +03:00
|
|
|
|
|
|
|
should.exist(jsonResponse.notifications);
|
|
|
|
|
|
|
|
localUtils.API.checkResponse(jsonResponse.notifications[0], 'notification');
|
|
|
|
|
|
|
|
jsonResponse.notifications[0].type.should.equal(newNotification.type);
|
|
|
|
jsonResponse.notifications[0].message.should.equal(newNotification.message);
|
|
|
|
jsonResponse.notifications[0].status.should.equal('alert');
|
|
|
|
jsonResponse.notifications[0].dismissible.should.be.true();
|
|
|
|
should.exist(jsonResponse.notifications[0].location);
|
|
|
|
jsonResponse.notifications[0].location.should.equal('bottom');
|
|
|
|
jsonResponse.notifications[0].id.should.be.a.String();
|
2020-09-14 13:33:37 +03:00
|
|
|
|
|
|
|
should.exist(res.headers.location);
|
|
|
|
res.headers.location.should.equal(`http://127.0.0.1:2369${localUtils.API.getApiQuery('notifications/')}${res.body.notifications[0].id}/`);
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|
2018-10-12 20:44:03 +03:00
|
|
|
});
|
|
|
|
|
2019-04-18 12:25:17 +03:00
|
|
|
it('Can delete notification', function () {
|
|
|
|
const newNotification = {
|
2018-10-12 20:44:03 +03:00
|
|
|
type: 'info',
|
|
|
|
message: 'test notification',
|
|
|
|
status: 'alert',
|
|
|
|
custom: true
|
|
|
|
};
|
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
// create the notification that is to be deleted
|
2019-04-18 12:25:17 +03:00
|
|
|
return request.post(localUtils.API.getApiQuery('notifications/'))
|
2019-02-04 17:16:24 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.send({notifications: [newNotification]})
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(201)
|
2019-04-18 12:25:17 +03:00
|
|
|
.then(function (res) {
|
2019-02-04 17:16:24 +03:00
|
|
|
const jsonResponse = res.body;
|
|
|
|
|
|
|
|
should.exist(jsonResponse.notifications);
|
|
|
|
localUtils.API.checkResponse(jsonResponse.notifications[0], 'notification');
|
|
|
|
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);
|
|
|
|
|
2019-04-18 12:25:17 +03:00
|
|
|
return jsonResponse.notifications[0];
|
|
|
|
})
|
|
|
|
.then((notification) => {
|
|
|
|
return request.del(localUtils.API.getApiQuery(`notifications/${notification.id}/`))
|
2019-02-04 17:16:24 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect(204)
|
2019-04-18 12:25:17 +03:00
|
|
|
.then(function (res) {
|
2019-02-04 17:16:24 +03:00
|
|
|
res.body.should.be.empty();
|
|
|
|
|
2019-04-18 12:25:17 +03:00
|
|
|
return notification;
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then((notification) => {
|
|
|
|
return request.get(localUtils.API.getApiQuery(`notifications/`))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect(200)
|
|
|
|
.then(function (res) {
|
|
|
|
const deleted = res.body.notifications.filter(n => n.id === notification.id);
|
|
|
|
deleted.should.be.empty();
|
2018-10-12 20:44:03 +03:00
|
|
|
});
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|
2018-10-12 20:44:03 +03:00
|
|
|
});
|
|
|
|
});
|