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
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
describe('Notifications API', function () {
|
2020-11-30 17:25:22 +03:00
|
|
|
let request;
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
await testUtils.startGhost();
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
await localUtils.doAuth(request);
|
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,
|
|
|
|
id: 'customId'
|
|
|
|
};
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
const res = await 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)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(201);
|
|
|
|
|
|
|
|
const jsonResponse = res.body;
|
2019-02-04 17:16:24 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
should.exist(jsonResponse.notifications);
|
2019-02-04 17:16:24 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
localUtils.API.checkResponse(jsonResponse.notifications[0], 'notification');
|
2019-02-04 17:16:24 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
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
|
|
|
|
2020-11-30 17:25:22 +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}/`);
|
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
|
|
|
|
};
|
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
// create the notification that is to be deleted
|
2020-11-30 17:25:22 +03:00
|
|
|
const res = await 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)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(201);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
const notification = jsonResponse.notifications[0];
|
|
|
|
|
|
|
|
const res2 = await request.del(localUtils.API.getApiQuery(`notifications/${notification.id}/`))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect(204);
|
|
|
|
res2.body.should.be.empty();
|
|
|
|
|
|
|
|
const res3 = await request.get(localUtils.API.getApiQuery(`notifications/`))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect(200);
|
|
|
|
const deleted = res3.body.notifications.filter(n => n.id === notification.id);
|
|
|
|
deleted.should.be.empty();
|
2018-10-12 20:44:03 +03:00
|
|
|
});
|
|
|
|
});
|