2019-09-03 10:03:31 +03:00
|
|
|
const should = require('should');
|
|
|
|
const supertest = require('supertest');
|
2022-02-06 19:18:41 +03:00
|
|
|
const testUtils = require('../../../utils');
|
|
|
|
const config = require('../../../../core/shared/config');
|
2019-09-03 10:03:31 +03:00
|
|
|
const localUtils = require('./utils');
|
|
|
|
|
|
|
|
describe('Notifications API', function () {
|
|
|
|
describe('As Editor', function () {
|
|
|
|
let request;
|
|
|
|
|
2021-11-24 12:42:57 +03:00
|
|
|
before(async function () {
|
2021-11-24 16:29:45 +03:00
|
|
|
await localUtils.startGhost();
|
2021-11-24 12:42:57 +03:00
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
const user = await testUtils.createUser({
|
|
|
|
user: testUtils.DataGenerator.forKnex.createUser({
|
|
|
|
email: 'test+editor@ghost.org'
|
|
|
|
}),
|
|
|
|
role: testUtils.DataGenerator.Content.roles[1].name
|
|
|
|
});
|
|
|
|
|
|
|
|
request.user = user;
|
|
|
|
await localUtils.doAuth(request);
|
2019-09-03 10:03:31 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Add notification', function () {
|
|
|
|
const newNotification = {
|
|
|
|
type: 'info',
|
|
|
|
message: 'test notification',
|
|
|
|
custom: true
|
|
|
|
};
|
|
|
|
|
|
|
|
return request.post(localUtils.API.getApiQuery('notifications/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.send({notifications: [newNotification]})
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(201)
|
|
|
|
.then((res) => {
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
|
|
|
|
should.exist(jsonResponse);
|
|
|
|
should.exist(jsonResponse.notifications);
|
|
|
|
should.equal(jsonResponse.notifications.length, 1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Read notifications', function () {
|
|
|
|
return request.get(localUtils.API.getApiQuery('notifications/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.then((res) => {
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
|
|
|
|
should.exist(jsonResponse);
|
|
|
|
should.exist(jsonResponse.notifications);
|
|
|
|
should.equal(jsonResponse.notifications.length, 1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('As Author', function () {
|
|
|
|
let request;
|
|
|
|
|
2021-11-24 12:42:57 +03:00
|
|
|
before(async function () {
|
2021-11-24 16:29:45 +03:00
|
|
|
await localUtils.startGhost();
|
2021-11-24 12:42:57 +03:00
|
|
|
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
const user = await testUtils.createUser({
|
|
|
|
user: testUtils.DataGenerator.forKnex.createUser({
|
|
|
|
email: 'test+author@ghost.org'
|
|
|
|
}),
|
|
|
|
role: testUtils.DataGenerator.Content.roles[2].name
|
|
|
|
});
|
|
|
|
request.user = user;
|
|
|
|
await localUtils.doAuth(request);
|
2019-09-03 10:03:31 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Add notification', function () {
|
|
|
|
const newNotification = {
|
|
|
|
type: 'info',
|
|
|
|
message: 'test notification',
|
|
|
|
custom: true
|
|
|
|
};
|
|
|
|
|
|
|
|
return request.post(localUtils.API.getApiQuery('notifications/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.send({notifications: [newNotification]})
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(403);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Read notifications', function () {
|
|
|
|
return request.get(localUtils.API.getApiQuery('notifications/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(403);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Can view by multiple users', function () {
|
|
|
|
let requestEditor1;
|
|
|
|
let requestEditor2;
|
|
|
|
let notification;
|
|
|
|
|
2021-11-24 12:42:57 +03:00
|
|
|
before(async function () {
|
2021-11-24 16:29:45 +03:00
|
|
|
await localUtils.startGhost();
|
2021-11-24 12:42:57 +03:00
|
|
|
|
|
|
|
requestEditor1 = supertest.agent(config.get('url'));
|
|
|
|
requestEditor2 = supertest.agent(config.get('url'));
|
|
|
|
|
|
|
|
const editor1User = await testUtils.createUser({
|
|
|
|
user: testUtils.DataGenerator.forKnex.createUser({
|
|
|
|
email: 'test+editor1@ghost.org'
|
|
|
|
}),
|
|
|
|
role: testUtils.DataGenerator.Content.roles[1].name
|
|
|
|
});
|
|
|
|
requestEditor1.user = editor1User;
|
|
|
|
await localUtils.doAuth(requestEditor1);
|
|
|
|
|
|
|
|
const editor2User = await testUtils.createUser({
|
|
|
|
user: testUtils.DataGenerator.forKnex.createUser({
|
|
|
|
email: 'test+editor2@ghost.org'
|
|
|
|
}),
|
|
|
|
role: testUtils.DataGenerator.Content.roles[1].name
|
|
|
|
});
|
|
|
|
requestEditor2.user = editor2User;
|
|
|
|
await localUtils.doAuth(requestEditor2);
|
2019-09-03 10:03:31 +03:00
|
|
|
|
2021-11-24 12:42:57 +03:00
|
|
|
const newNotification = {
|
|
|
|
type: 'info',
|
|
|
|
message: 'multiple views',
|
|
|
|
custom: true
|
|
|
|
};
|
|
|
|
|
|
|
|
await requestEditor1.post(localUtils.API.getApiQuery('notifications/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.send({notifications: [newNotification]})
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(201)
|
|
|
|
.then((res) => {
|
|
|
|
notification = res.body.notifications[0];
|
2019-09-03 10:03:31 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('notification is visible and dismissible by other user', function () {
|
|
|
|
return requestEditor1.del(localUtils.API.getApiQuery(`notifications/${notification.id}`))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect(204)
|
|
|
|
.then(() => {
|
|
|
|
return requestEditor2.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.not.be.empty();
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
return requestEditor2.del(localUtils.API.getApiQuery(`notifications/${notification.id}`))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect(204);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
return requestEditor2.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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|