-
-
Notifications
You must be signed in to change notification settings - Fork 10k
/
notifications_spec.js
121 lines (101 loc) · 4.56 KB
/
notifications_spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*global describe, it, before, after */
/*jshint expr:true*/
var testUtils = require('../../../utils'),
supertest = require('supertest'),
ghost = require('../../../../../core'),
request;
describe('Notifications API', function () {
var accesstoken = '';
before(function (done) {
// starting ghost automatically populates the db
// TODO: prevent db init, and manage bringing up the DB with fixtures ourselves
ghost().then(function (ghostServer) {
request = supertest.agent(ghostServer.rootApp);
}).then(function () {
return testUtils.doAuth(request);
}).then(function (token) {
accesstoken = token;
done();
}).catch(function (e) {
console.log('Ghost Error: ', e);
console.log(e.stack);
});
});
after(function (done) {
testUtils.clearData().then(function () {
done();
}).catch(done);
});
describe('Add', function () {
var newNotification = {
type: 'info',
message: 'test notification'
};
it('creates a new notification', function (done) {
request.post(testUtils.API.getApiQuery('notifications/'))
.set('Authorization', 'Bearer ' + accesstoken)
.send({notifications: [newNotification]})
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules['private'])
.expect(201)
.end(function (err, res) {
if (err) {
return done(err);
}
var jsonResponse = res.body;
jsonResponse.notifications.should.exist;
testUtils.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('persistent');
done();
});
});
});
describe('Delete', function () {
var newNotification = {
type: 'info',
message: 'test notification',
status: 'persistent'
};
it('deletes a notification', function (done) {
// create the notification that is to be deleted
request.post(testUtils.API.getApiQuery('notifications/'))
.set('Authorization', 'Bearer ' + accesstoken)
.send({notifications: [newNotification]})
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules['private'])
.expect(201)
.end(function (err, res) {
if (err) {
return done(err);
}
var location = res.headers.location,
jsonResponse = res.body;
jsonResponse.notifications.should.exist;
testUtils.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(newNotification.status);
// begin delete test
request.del(location)
.set('Authorization', 'Bearer ' + accesstoken)
.expect('Content-Type', /json/)
.expect(200)
.end(function (err, res) {
if (err) {
return done(err);
}
// a delete returns a JSON object containing the notification
// we just deleted.
var deleteResponse = res.body;
deleteResponse.notifications.should.exist;
deleteResponse.notifications[0].type.should.equal(newNotification.type);
deleteResponse.notifications[0].message.should.equal(newNotification.message);
deleteResponse.notifications[0].status.should.equal(newNotification.status);
done();
});
});
});
});
});