-
Notifications
You must be signed in to change notification settings - Fork 315
/
notify-send.js
105 lines (88 loc) · 2.93 KB
/
notify-send.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
var Notify = require('../notifiers/notifysend');
var utils = require('../lib/utils');
var os = require('os');
describe('notify-send', function() {
var original = utils.command;
var originalType = os.type;
beforeEach(function() {
os.type = function() {
return 'Linux';
};
});
afterEach(function() {
utils.command = original;
os.type = originalType;
});
function expectArgsListToBe(expected, done) {
utils.command = function(notifier, argsList, callback) {
expect(argsList).toEqual(expected);
done();
};
}
it('should pass on title and body', function(done) {
var expected = ['"title"', '"body"'];
expectArgsListToBe(expected, done);
var notifier = new Notify({ suppressOsdCheck: true });
notifier.notify({ title: 'title', message: 'body' });
});
it('should pass have default title', function(done) {
var expected = ['"Node Notification:"', '"body"'];
expectArgsListToBe(expected, done);
var notifier = new Notify({ suppressOsdCheck: true });
notifier.notify({ message: 'body' });
});
it('should throw error if no message is passed', function(done) {
utils.command = function(notifier, argsList, callback) {
expect(argsList).toBeUndefined();
};
var notifier = new Notify({ suppressOsdCheck: true });
notifier.notify({}, function(err) {
expect(err.message).toBe('Message is required.');
done();
});
});
it('should escape message input', function(done) {
var excapedNewline = process.platform === 'win32' ? '\\r\\n' : '\\n';
var expected = [
'"Node Notification:"',
'"some' + excapedNewline + ' \\"me\'ss\\`age\\`\\""'
];
expectArgsListToBe(expected, done);
var notifier = new Notify({ suppressOsdCheck: true });
notifier.notify({ message: 'some\n "me\'ss`age`"' });
});
it('should send additional parameters as --"keyname"', function(done) {
var expected = ['"title"', '"body"', '--icon', '"icon-string"'];
expectArgsListToBe(expected, done);
var notifier = new Notify({ suppressOsdCheck: true });
notifier.notify({ title: 'title', message: 'body', icon: 'icon-string' });
});
it('should only include strings as arguments', function(done) {
var expected = ['"HACKED"'];
expectArgsListToBe(expected, done);
var notifier = new Notify({ suppressOsdCheck: true });
var options = JSON.parse(
'{"title":"HACKED", "message":["`touch HACKED`"]}'
);
notifier.notify(options);
});
it('should remove extra options that are not supported by notify-send', function(done) {
var expected = [
'"title"',
'"body"',
'--icon',
'"icon-string"',
'--expire-time',
'"100"'
];
expectArgsListToBe(expected, done);
var notifier = new Notify({ suppressOsdCheck: true });
notifier.notify({
title: 'title',
message: 'body',
icon: 'icon-string',
time: 100,
tullball: 'notValid'
});
});
});