1 | var Notify = require('../').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();
|
31 | notifier.isNotifyChecked = true;
|
32 | notifier.hasNotifier = true;
|
33 |
|
34 | notifier.notify({
|
35 | title: "title",
|
36 | message: "body"
|
37 | }, function (err) {
|
38 | should.not.exist(err);
|
39 | done();
|
40 | })
|
41 | });
|
42 |
|
43 | it('should pass have default title', function (done) {
|
44 | var expected = [ '"Node Notification:"', '"body"' ];
|
45 |
|
46 | utils.command = function (notifier, argsList, callback) {
|
47 | argsList.should.eql(expected);
|
48 | done();
|
49 | };
|
50 |
|
51 | var notifier = new Notify();
|
52 | notifier.isNotifyChecked = true;
|
53 | notifier.hasNotifier = true;
|
54 |
|
55 | notifier.notify({
|
56 | message: "body"
|
57 | }, function (err) {
|
58 | should.not.exist(err);
|
59 | done();
|
60 | })
|
61 | });
|
62 |
|
63 |
|
64 | it('should throw error if no message is passed', function (done) {
|
65 |
|
66 | utils.command = function (notifier, argsList, callback) {
|
67 | should.not.exist(argsList);
|
68 | done();
|
69 | };
|
70 |
|
71 | var notifier = new Notify();
|
72 | notifier.isNotifyChecked = true;
|
73 | notifier.hasNotifier = true;
|
74 |
|
75 | notifier.notify({
|
76 | }, function (err) {
|
77 | err.message.should.equal("Message is required.");
|
78 | done();
|
79 | })
|
80 | });
|
81 |
|
82 |
|
83 | it('should escape message input', function (done) {
|
84 | var expected = [ '"Node Notification:"', '"some \\"me\'ss\\`age\\`\\""' ];
|
85 |
|
86 | utils.command = function (notifier, argsList, callback) {
|
87 | argsList.should.eql(expected);
|
88 | done();
|
89 | };
|
90 |
|
91 | var notifier = new Notify();
|
92 | notifier.isNotifyChecked = true;
|
93 | notifier.hasNotifier = true;
|
94 |
|
95 | notifier.notify({
|
96 | message: 'some "me\'ss`age`"'
|
97 | }, function (err) {
|
98 | should.not.exist(err);
|
99 | done();
|
100 | })
|
101 | });
|
102 |
|
103 | it('should send additional parameters as --"keyname"', function (done) {
|
104 | var expected = [ '"title"', '"body"', '--icon', '"icon-string"' ]
|
105 |
|
106 | utils.command = function (notifier, argsList, callback) {
|
107 | argsList.should.eql(expected);
|
108 | done();
|
109 | };
|
110 |
|
111 | var notifier = new Notify();
|
112 | notifier.isNotifyChecked = true;
|
113 | notifier.hasNotifier = true;
|
114 |
|
115 | notifier.notify({
|
116 | title: "title",
|
117 | message: "body",
|
118 | icon: "icon-string"
|
119 | }, function (err) {
|
120 | should.not.exist(err);
|
121 | done();
|
122 | })
|
123 | });
|
124 |
|
125 | it('should remove extra options that are not supported by notify-send', function (done) {
|
126 | var expected = [ '"title"', '"body"', '--icon', '"icon-string"' ]
|
127 |
|
128 | utils.command = function (notifier, argsList, callback) {
|
129 | argsList.should.eql(expected);
|
130 | done();
|
131 | };
|
132 |
|
133 | var notifier = new Notify();
|
134 | notifier.isNotifyChecked = true;
|
135 | notifier.hasNotifier = true;
|
136 |
|
137 | notifier.notify({
|
138 | title: "title",
|
139 | message: "body",
|
140 | icon: "icon-string",
|
141 | tullball: "notValid"
|
142 | }, function (err) {
|
143 | should.not.exist(err);
|
144 | done();
|
145 | })
|
146 | });
|
147 |
|
148 | });
|