1 | var Notify = require('../notifiers/notifysend')
|
2 | , should = require('should')
|
3 | , utils = require('../lib/utils')
|
4 | , os = require('os')
|
5 | , assert = require('assert');
|
6 |
|
7 | describe('notify-send', function(){
|
8 |
|
9 | before(function () {
|
10 | this.original = utils.command;
|
11 | this.originalType = os.type;
|
12 | os.type = function () {
|
13 | return "Linux";
|
14 | };
|
15 | });
|
16 |
|
17 | after(function () {
|
18 | utils.command = this.original;
|
19 | os.type = this.originalType;
|
20 | });
|
21 |
|
22 | it('should pass on title and body', function (done) {
|
23 | var expected = [ '"title"', '"body"' ];
|
24 |
|
25 | utils.command = function (notifier, argsList, callback) {
|
26 | argsList.should.eql(expected);
|
27 | done();
|
28 | };
|
29 |
|
30 | var notifier = new Notify({ suppressOsdCheck: true });
|
31 |
|
32 | notifier.notify({
|
33 | title: "title",
|
34 | message: "body"
|
35 | }, function (err) {
|
36 | should.not.exist(err);
|
37 | done();
|
38 | })
|
39 | });
|
40 |
|
41 | it('should pass have default title', function (done) {
|
42 | var expected = [ '"Node Notification:"', '"body"' ];
|
43 |
|
44 | utils.command = function (notifier, argsList, callback) {
|
45 | argsList.should.eql(expected);
|
46 | done();
|
47 | };
|
48 |
|
49 | var notifier = new Notify({ suppressOsdCheck: true });
|
50 |
|
51 | notifier.notify({
|
52 | message: "body"
|
53 | }, function (err) {
|
54 | should.not.exist(err);
|
55 | done();
|
56 | })
|
57 | });
|
58 |
|
59 |
|
60 | it('should throw error if no message is passed', function (done) {
|
61 |
|
62 | utils.command = function (notifier, argsList, callback) {
|
63 | should.not.exist(argsList);
|
64 | done();
|
65 | };
|
66 |
|
67 | var notifier = new Notify({ suppressOsdCheck: true });
|
68 |
|
69 | notifier.notify({
|
70 | }, function (err) {
|
71 | err.message.should.equal("Message is required.");
|
72 | done();
|
73 | })
|
74 | });
|
75 |
|
76 |
|
77 | it('should escape message input', function (done) {
|
78 | var expected = [ '"Node Notification:"', '"some \\"me\'ss\\`age\\`\\""' ];
|
79 |
|
80 | utils.command = function (notifier, argsList, callback) {
|
81 | argsList.should.eql(expected);
|
82 | done();
|
83 | };
|
84 |
|
85 | var notifier = new Notify({ suppressOsdCheck: true });
|
86 |
|
87 | notifier.notify({
|
88 | message: 'some "me\'ss`age`"'
|
89 | }, function (err) {
|
90 | should.not.exist(err);
|
91 | done();
|
92 | })
|
93 | });
|
94 |
|
95 | it('should send additional parameters as --"keyname"', function (done) {
|
96 | var expected = [ '"title"', '"body"', '--icon', '"icon-string"' ]
|
97 |
|
98 | utils.command = function (notifier, argsList, callback) {
|
99 | argsList.should.eql(expected);
|
100 | done();
|
101 | };
|
102 |
|
103 | var notifier = new Notify({ suppressOsdCheck: true });
|
104 |
|
105 | notifier.notify({
|
106 | title: "title",
|
107 | message: "body",
|
108 | icon: "icon-string"
|
109 | }, function (err) {
|
110 | should.not.exist(err);
|
111 | done();
|
112 | })
|
113 | });
|
114 |
|
115 | it('should remove extra options that are not supported by notify-send', function (done) {
|
116 | var expected = [ '"title"', '"body"', '--icon', '"icon-string"' ]
|
117 |
|
118 | utils.command = function (notifier, argsList, callback) {
|
119 | argsList.should.eql(expected);
|
120 | done();
|
121 | };
|
122 |
|
123 | var notifier = new Notify({ suppressOsdCheck: true });
|
124 |
|
125 | notifier.notify({
|
126 | title: "title",
|
127 | message: "body",
|
128 | icon: "icon-string",
|
129 | tullball: "notValid"
|
130 | }, function (err) {
|
131 | should.not.exist(err);
|
132 | done();
|
133 | })
|
134 | });
|
135 |
|
136 | });
|