forked from nightscout/cgm-remote-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpushnotify.test.js
114 lines (86 loc) · 2.99 KB
/
pushnotify.test.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
'use strict';
var should = require('should');
var levels = require('../lib/levels');
describe('pushnotify', function ( ) {
it('send a pushover alarm, but only 1 time', function (done) {
var env = require('../lib/server/env')();
var ctx = {};
ctx.levels = levels;
ctx.notifications = require('../lib/notifications')(env, ctx);
var notify = {
title: 'Warning, this is a test!'
, message: 'details details details details'
, level: levels.WARN
, pushoverSound: 'climb'
, plugin: {name: 'test'}
};
ctx.pushover = {
PRIORITY_NORMAL: 0
, PRIORITY_EMERGENCY: 2
, send: function mockedSend (notify2, callback) {
should.deepEqual(notify, notify2);
callback(null, JSON.stringify({receipt: 'abcd12345'}));
done();
}
};
ctx.pushnotify = require('../lib/server/pushnotify')(env, ctx);
ctx.pushnotify.emitNotification(notify);
//call again, but should be deduped, or fail with 'done() called multiple times'
ctx.pushnotify.emitNotification(notify);
});
it('send a pushover notification, but only 1 time', function (done) {
var env = require('../lib/server/env')();
var ctx = {};
ctx.levels = levels;
ctx.notifications = require('../lib/notifications')(env, ctx);
var notify = {
title: 'Sent from a test'
, message: 'details details details details'
, level: levels.INFO
, plugin: {name: 'test'}
};
ctx.pushover = {
PRIORITY_NORMAL: 0
, PRIORITY_EMERGENCY: 2
, send: function mockedSend (notify2, callback) {
should.deepEqual(notify, notify2);
callback(null, JSON.stringify({}));
done();
}
};
ctx.pushnotify = require('../lib/server/pushnotify')(env, ctx);
ctx.pushnotify.emitNotification(notify);
//call again, but should be deduped, or fail with 'done() called multiple times'
ctx.pushnotify.emitNotification(notify);
});
it('send a pushover alarm, and then cancel', function (done) {
var env = require('../lib/server/env')();
var ctx = {};
ctx.levels = levels;
ctx.notifications = require('../lib/notifications')(env, ctx);
var notify = {
title: 'Warning, this is a test!'
, message: 'details details details details'
, level: levels.WARN
, pushoverSound: 'climb'
, plugin: {name: 'test'}
};
ctx.pushover = {
PRIORITY_NORMAL: 0
, PRIORITY_EMERGENCY: 2
, send: function mockedSend (notify2, callback) {
should.deepEqual(notify, notify2);
callback(null, JSON.stringify({receipt: 'abcd12345'}));
}
, cancelWithReceipt: function mockedCancel (receipt) {
receipt.should.equal('abcd12345');
done();
}
};
ctx.pushnotify = require('../lib/server/pushnotify')(env, ctx);
//first send the warning
ctx.pushnotify.emitNotification(notify);
//then pretend is was acked from the web
ctx.pushnotify.emitNotification({clear: true});
});
});