apsProperties.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  1. const Notification = require('../../lib/notification');
  2. describe('Notification', function () {
  3. let note;
  4. beforeEach(function () {
  5. note = new Notification();
  6. });
  7. describe('aps convenience properties', function () {
  8. describe('alert', function () {
  9. it('defaults to undefined', function () {
  10. expect(compiledOutput()).to.not.have.nested.deep.property('aps.alert');
  11. });
  12. it('can be set to a string', function () {
  13. note.alert = 'hello';
  14. expect(compiledOutput()).to.have.nested.deep.property('aps.alert', 'hello');
  15. });
  16. it('can be set to an object', function () {
  17. note.alert = { body: 'hello' };
  18. expect(compiledOutput())
  19. .to.have.nested.deep.property('aps.alert')
  20. .that.deep.equals({ body: 'hello' });
  21. });
  22. it('can be set to undefined', function () {
  23. note.alert = { body: 'hello' };
  24. note.alert = undefined;
  25. expect(compiledOutput()).to.not.have.nested.deep.property('aps.alert');
  26. });
  27. describe('setAlert', function () {
  28. it('is chainable', function () {
  29. expect(note.setAlert('hello')).to.equal(note);
  30. expect(compiledOutput()).to.have.nested.deep.property('aps.alert', 'hello');
  31. });
  32. });
  33. });
  34. describe('body', function () {
  35. it('defaults to undefined', function () {
  36. expect(note.body).to.be.undefined;
  37. });
  38. it('can be set to a string', function () {
  39. note.body = 'Hello, world';
  40. expect(typeof compiledOutput().aps.alert).to.equal('string');
  41. });
  42. it('sets alert as a string by default', function () {
  43. note.body = 'Hello, world';
  44. expect(compiledOutput()).to.have.nested.deep.property('aps.alert', 'Hello, world');
  45. });
  46. context('alert is already an Object', function () {
  47. beforeEach(function () {
  48. note.alert = { body: 'Existing Body' };
  49. });
  50. it('reads the value from alert body', function () {
  51. expect(note.body).to.equal('Existing Body');
  52. });
  53. it('sets the value correctly', function () {
  54. note.body = 'Hello, world';
  55. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.body', 'Hello, world');
  56. });
  57. });
  58. describe('setBody', function () {
  59. it('is chainable', function () {
  60. expect(note.setBody('hello')).to.equal(note);
  61. expect(compiledOutput()).to.have.nested.deep.property('aps.alert', 'hello');
  62. });
  63. });
  64. });
  65. describe('locKey', function () {
  66. it('sets the aps.alert.loc-key property', function () {
  67. note.locKey = 'hello_world';
  68. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.loc-key', 'hello_world');
  69. });
  70. context('alert is already an object', function () {
  71. beforeEach(function () {
  72. note.alert = { body: 'Test', 'launch-image': 'test.png' };
  73. note.locKey = 'hello_world';
  74. });
  75. it('contains all expected properties', function () {
  76. expect(compiledOutput()).to.have.nested.deep.property('aps.alert').that.deep.equals({
  77. body: 'Test',
  78. 'launch-image': 'test.png',
  79. 'loc-key': 'hello_world',
  80. });
  81. });
  82. });
  83. context('alert is already a string', function () {
  84. beforeEach(function () {
  85. note.alert = 'Good Morning';
  86. note.locKey = 'good_morning';
  87. });
  88. it('retains the alert body correctly', function () {
  89. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.body', 'Good Morning');
  90. });
  91. it('sets the aps.alert.loc-key property', function () {
  92. expect(compiledOutput()).to.have.nested.deep.property(
  93. 'aps.alert.loc-key',
  94. 'good_morning'
  95. );
  96. });
  97. });
  98. describe('setLocKey', function () {
  99. it('is chainable', function () {
  100. expect(note.setLocKey('good_morning')).to.equal(note);
  101. expect(compiledOutput()).to.have.nested.deep.property(
  102. 'aps.alert.loc-key',
  103. 'good_morning'
  104. );
  105. });
  106. });
  107. });
  108. describe('locArgs', function () {
  109. it('sets the aps.alert.loc-args property', function () {
  110. note.locArgs = ['arg1', 'arg2'];
  111. expect(compiledOutput())
  112. .to.have.nested.deep.property('aps.alert.loc-args')
  113. .that.deep.equals(['arg1', 'arg2']);
  114. });
  115. context('alert is already an object', function () {
  116. beforeEach(function () {
  117. note.alert = { body: 'Test', 'launch-image': 'test.png' };
  118. note.locArgs = ['Hi there'];
  119. });
  120. it('contains all expected properties', function () {
  121. expect(compiledOutput())
  122. .to.have.nested.deep.property('aps.alert')
  123. .that.deep.equals({
  124. body: 'Test',
  125. 'launch-image': 'test.png',
  126. 'loc-args': ['Hi there'],
  127. });
  128. });
  129. });
  130. context('alert is already a string', function () {
  131. beforeEach(function () {
  132. note.alert = 'Hello, world';
  133. note.locArgs = ['Hi there'];
  134. });
  135. it('retains the alert body', function () {
  136. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.body', 'Hello, world');
  137. });
  138. it('sets the aps.alert.loc-args property', function () {
  139. expect(compiledOutput())
  140. .to.have.nested.deep.property('aps.alert.loc-args')
  141. .that.deep.equals(['Hi there']);
  142. });
  143. });
  144. describe('setLocArgs', function () {
  145. it('is chainable', function () {
  146. expect(note.setLocArgs(['Robert'])).to.equal(note);
  147. expect(compiledOutput())
  148. .to.have.nested.deep.property('aps.alert.loc-args')
  149. .that.deep.equals(['Robert']);
  150. });
  151. });
  152. });
  153. describe('title', function () {
  154. it('sets the aps.alert.title property', function () {
  155. note.title = 'node-apn';
  156. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.title', 'node-apn');
  157. });
  158. context('alert is already an object', function () {
  159. beforeEach(function () {
  160. note.alert = { body: 'Test', 'launch-image': 'test.png' };
  161. note.title = 'node-apn';
  162. });
  163. it('contains all expected properties', function () {
  164. expect(compiledOutput())
  165. .to.have.nested.deep.property('aps.alert')
  166. .that.deep.equals({ body: 'Test', 'launch-image': 'test.png', title: 'node-apn' });
  167. });
  168. });
  169. context('alert is already a string', function () {
  170. beforeEach(function () {
  171. note.alert = 'Hello, world';
  172. note.title = 'Welcome';
  173. });
  174. it('retains the alert body', function () {
  175. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.body', 'Hello, world');
  176. });
  177. it('sets the aps.alert.title property', function () {
  178. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.title', 'Welcome');
  179. });
  180. });
  181. describe('setTitle', function () {
  182. it('is chainable', function () {
  183. expect(note.setTitle('Bienvenue')).to.equal(note);
  184. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.title', 'Bienvenue');
  185. });
  186. });
  187. });
  188. describe('subtitle', function () {
  189. it('sets the aps.alert.subtitle property', function () {
  190. note.subtitle = 'node-apn';
  191. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.subtitle', 'node-apn');
  192. });
  193. context('alert is already an object', function () {
  194. beforeEach(function () {
  195. note.alert = { body: 'Test', 'launch-image': 'test.png' };
  196. note.subtitle = 'node-apn';
  197. });
  198. it('contains all expected properties', function () {
  199. expect(compiledOutput())
  200. .to.have.nested.deep.property('aps.alert')
  201. .that.deep.equals({ body: 'Test', 'launch-image': 'test.png', subtitle: 'node-apn' });
  202. });
  203. });
  204. context('alert is already a string', function () {
  205. beforeEach(function () {
  206. note.alert = 'Hello, world';
  207. note.subtitle = 'Welcome';
  208. });
  209. it('retains the alert body', function () {
  210. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.body', 'Hello, world');
  211. });
  212. it('sets the aps.alert.subtitle property', function () {
  213. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.subtitle', 'Welcome');
  214. });
  215. });
  216. describe('setSubtitle', function () {
  217. it('is chainable', function () {
  218. expect(note.setSubtitle('Bienvenue')).to.equal(note);
  219. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.subtitle', 'Bienvenue');
  220. });
  221. });
  222. });
  223. describe('titleLocKey', function () {
  224. it('sets the aps.alert.title-loc-key property', function () {
  225. note.titleLocKey = 'Warning';
  226. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.title-loc-key', 'Warning');
  227. });
  228. context('alert is already an object', function () {
  229. beforeEach(function () {
  230. note.alert = { body: 'Test', 'launch-image': 'test.png' };
  231. note.titleLocKey = 'Warning';
  232. });
  233. it('contains all expected properties', function () {
  234. expect(compiledOutput()).to.have.nested.deep.property('aps.alert').that.deep.equals({
  235. body: 'Test',
  236. 'launch-image': 'test.png',
  237. 'title-loc-key': 'Warning',
  238. });
  239. });
  240. });
  241. context('alert is already a string', function () {
  242. beforeEach(function () {
  243. note.alert = 'Hello, world';
  244. note.titleLocKey = 'Warning';
  245. });
  246. it('retains the alert body correctly', function () {
  247. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.body', 'Hello, world');
  248. });
  249. it('sets the aps.alert.title-loc-key property', function () {
  250. expect(compiledOutput()).to.have.nested.deep.property(
  251. 'aps.alert.title-loc-key',
  252. 'Warning'
  253. );
  254. });
  255. });
  256. describe('setAlert', function () {
  257. it('is chainable', function () {
  258. expect(note.setTitleLocKey('greeting')).to.equal(note);
  259. expect(compiledOutput()).to.have.nested.deep.property(
  260. 'aps.alert.title-loc-key',
  261. 'greeting'
  262. );
  263. });
  264. });
  265. });
  266. describe('titleLocArgs', function () {
  267. it('sets the aps.alert.title-loc-args property', function () {
  268. note.titleLocArgs = ['arg1', 'arg2'];
  269. expect(compiledOutput())
  270. .to.have.nested.deep.property('aps.alert.title-loc-args')
  271. .that.deep.equals(['arg1', 'arg2']);
  272. });
  273. context('alert is already an object', function () {
  274. beforeEach(function () {
  275. note.alert = { body: 'Test', 'launch-image': 'test.png' };
  276. note.titleLocArgs = ['Hi there'];
  277. });
  278. it('contains all expected properties', function () {
  279. expect(compiledOutput())
  280. .to.have.nested.deep.property('aps.alert')
  281. .that.deep.equals({
  282. body: 'Test',
  283. 'launch-image': 'test.png',
  284. 'title-loc-args': ['Hi there'],
  285. });
  286. });
  287. });
  288. context('alert is already a string', function () {
  289. beforeEach(function () {
  290. note.alert = 'Hello, world';
  291. note.titleLocArgs = ['Hi there'];
  292. });
  293. it('retains the alert body', function () {
  294. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.body', 'Hello, world');
  295. });
  296. it('sets the aps.alert.title-loc-args property', function () {
  297. expect(compiledOutput())
  298. .to.have.nested.deep.property('aps.alert.title-loc-args')
  299. .that.deep.equals(['Hi there']);
  300. });
  301. });
  302. describe('setTitleLocArgs', function () {
  303. it('is chainable', function () {
  304. expect(note.setTitleLocArgs(['iPhone 6s'])).to.equal(note);
  305. expect(compiledOutput())
  306. .to.have.nested.deep.property('aps.alert.title-loc-args')
  307. .that.deep.equals(['iPhone 6s']);
  308. });
  309. });
  310. });
  311. describe('action', function () {
  312. it('sets the aps.alert.action property', function () {
  313. note.action = 'View';
  314. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.action', 'View');
  315. });
  316. context('alert is already an object', function () {
  317. beforeEach(function () {
  318. note.alert = { body: 'Test', 'launch-image': 'test.png' };
  319. note.action = 'View';
  320. });
  321. it('contains all expected properties', function () {
  322. expect(compiledOutput())
  323. .to.have.nested.deep.property('aps.alert')
  324. .that.deep.equals({ body: 'Test', 'launch-image': 'test.png', action: 'View' });
  325. });
  326. });
  327. context('alert is already a string', function () {
  328. beforeEach(function () {
  329. note.alert = 'Alert';
  330. note.action = 'Investigate';
  331. });
  332. it('retains the alert body', function () {
  333. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.body', 'Alert');
  334. });
  335. it('sets the aps.alert.action property', function () {
  336. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.action', 'Investigate');
  337. });
  338. });
  339. describe('setAction', function () {
  340. it('is chainable', function () {
  341. expect(note.setAction('Reply')).to.equal(note);
  342. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.action', 'Reply');
  343. });
  344. });
  345. });
  346. describe('actionLocKey', function () {
  347. it('sets the aps.alert.action-loc-key property', function () {
  348. note.actionLocKey = 'reply_title';
  349. expect(compiledOutput()).to.have.nested.deep.property(
  350. 'aps.alert.action-loc-key',
  351. 'reply_title'
  352. );
  353. });
  354. context('alert is already an object', function () {
  355. beforeEach(function () {
  356. note.alert = { body: 'Test', 'launch-image': 'test.png' };
  357. note.actionLocKey = 'reply_title';
  358. });
  359. it('contains all expected properties', function () {
  360. expect(compiledOutput()).to.have.nested.deep.property('aps.alert').that.deep.equals({
  361. body: 'Test',
  362. 'launch-image': 'test.png',
  363. 'action-loc-key': 'reply_title',
  364. });
  365. });
  366. });
  367. context('alert is already a string', function () {
  368. beforeEach(function () {
  369. note.alert = 'Hello, world';
  370. note.actionLocKey = 'ignore_title';
  371. });
  372. it('retains the alert body correctly', function () {
  373. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.body', 'Hello, world');
  374. });
  375. it('sets the aps.alert.action-loc-key property', function () {
  376. expect(compiledOutput()).to.have.nested.deep.property(
  377. 'aps.alert.action-loc-key',
  378. 'ignore_title'
  379. );
  380. });
  381. });
  382. describe('setActionLocKey', function () {
  383. it('is chainable', function () {
  384. expect(note.setActionLocKey('ignore_title')).to.equal(note);
  385. expect(compiledOutput()).to.have.nested.deep.property(
  386. 'aps.alert.action-loc-key',
  387. 'ignore_title'
  388. );
  389. });
  390. });
  391. });
  392. describe('launchImage', function () {
  393. it('sets the aps.alert.launch-image property', function () {
  394. note.launchImage = 'testLaunch.png';
  395. expect(compiledOutput())
  396. .to.have.nested.deep.property('aps.alert.launch-image')
  397. .that.deep.equals('testLaunch.png');
  398. });
  399. context('alert is already an object', function () {
  400. beforeEach(function () {
  401. note.alert = { body: 'Test', 'title-loc-key': 'node-apn' };
  402. note.launchImage = 'apnLaunch.png';
  403. });
  404. it('contains all expected properties', function () {
  405. expect(compiledOutput()).to.have.nested.deep.property('aps.alert').that.deep.equals({
  406. body: 'Test',
  407. 'title-loc-key': 'node-apn',
  408. 'launch-image': 'apnLaunch.png',
  409. });
  410. });
  411. });
  412. context('alert is already a string', function () {
  413. beforeEach(function () {
  414. note.alert = 'Hello, world';
  415. note.launchImage = 'apnLaunch.png';
  416. });
  417. it('retains the alert body', function () {
  418. expect(compiledOutput()).to.have.nested.deep.property('aps.alert.body', 'Hello, world');
  419. });
  420. it('sets the aps.alert.launch-image property', function () {
  421. expect(compiledOutput())
  422. .to.have.nested.deep.property('aps.alert.launch-image')
  423. .that.deep.equals('apnLaunch.png');
  424. });
  425. });
  426. describe('setLaunchImage', function () {
  427. it('is chainable', function () {
  428. expect(note.setLaunchImage('remoteLaunch.png')).to.equal(note);
  429. expect(compiledOutput()).to.have.nested.deep.property(
  430. 'aps.alert.launch-image',
  431. 'remoteLaunch.png'
  432. );
  433. });
  434. });
  435. });
  436. describe('badge', function () {
  437. it('defaults to undefined', function () {
  438. expect(compiledOutput()).to.not.have.nested.deep.property('aps.badge');
  439. });
  440. it('can be set to a number', function () {
  441. note.badge = 5;
  442. expect(compiledOutput()).to.have.nested.deep.property('aps.badge', 5);
  443. });
  444. it('can be set to undefined', function () {
  445. note.badge = 5;
  446. note.badge = undefined;
  447. expect(compiledOutput()).to.not.have.nested.deep.property('aps.badge');
  448. });
  449. it('can be set to zero', function () {
  450. note.badge = 0;
  451. expect(compiledOutput()).to.have.nested.deep.property('aps.badge', 0);
  452. });
  453. it('cannot be set to a string', function () {
  454. note.badge = 'hello';
  455. expect(compiledOutput()).to.not.have.nested.deep.property('aps.badge');
  456. });
  457. describe('setBadge', function () {
  458. it('is chainable', function () {
  459. expect(note.setBadge(7)).to.equal(note);
  460. expect(compiledOutput()).to.have.nested.deep.property('aps.badge', 7);
  461. });
  462. });
  463. });
  464. describe('sound', function () {
  465. it('defaults to undefined', function () {
  466. expect(compiledOutput()).to.not.have.nested.deep.property('aps.sound');
  467. });
  468. it('can be set to a string', function () {
  469. note.sound = 'sound.caf';
  470. expect(compiledOutput()).to.have.nested.deep.property('aps.sound', 'sound.caf');
  471. });
  472. it('can be set to undefined', function () {
  473. note.sound = 'sound.caf';
  474. note.sound = undefined;
  475. expect(compiledOutput()).to.not.have.nested.deep.property('aps.sound');
  476. });
  477. it('cannot be set to a number', function () {
  478. note.sound = 5;
  479. expect(compiledOutput()).to.not.have.nested.deep.property('aps.sound');
  480. });
  481. it('can be set to object', function () {
  482. note.sound = {
  483. name: 'sound.caf',
  484. critical: 1,
  485. volume: 0.75,
  486. };
  487. expect(compiledOutput()).to.have.nested.deep.property('aps.sound.name', 'sound.caf');
  488. expect(compiledOutput()).to.have.nested.deep.property('aps.sound.critical', 1);
  489. expect(compiledOutput()).to.have.nested.deep.property('aps.sound.volume', 0.75);
  490. });
  491. describe('setSound', function () {
  492. it('is chainable', function () {
  493. expect(note.setSound('bee.caf')).to.equal(note);
  494. expect(compiledOutput()).to.have.nested.deep.property('aps.sound', 'bee.caf');
  495. });
  496. });
  497. });
  498. describe('content-available', function () {
  499. it('defaults to undefined', function () {
  500. expect(compiledOutput()).to.not.have.nested.deep.property('aps.content-available');
  501. });
  502. it('can be set to a boolean value', function () {
  503. note.contentAvailable = true;
  504. expect(compiledOutput()).to.have.nested.deep.property('aps.content-available', 1);
  505. });
  506. it('can be set to `1`', function () {
  507. note.contentAvailable = 1;
  508. expect(compiledOutput()).to.have.nested.deep.property('aps.content-available', 1);
  509. });
  510. it('can be set to undefined', function () {
  511. note.contentAvailable = true;
  512. note.contentAvailable = undefined;
  513. expect(compiledOutput()).to.not.have.nested.deep.property('aps.content-available');
  514. });
  515. describe('setContentAvailable', function () {
  516. it('is chainable', function () {
  517. expect(note.setContentAvailable(true)).to.equal(note);
  518. expect(compiledOutput()).to.have.nested.deep.property('aps.content-available', 1);
  519. });
  520. });
  521. });
  522. describe('mutable-content', function () {
  523. it('defaults to undefined', function () {
  524. expect(compiledOutput()).to.not.have.nested.deep.property('aps.mutable-content');
  525. });
  526. it('can be set to a boolean value', function () {
  527. note.mutableContent = true;
  528. expect(compiledOutput()).to.have.nested.deep.property('aps.mutable-content', 1);
  529. });
  530. it('can be set to `1`', function () {
  531. note.mutableContent = 1;
  532. expect(compiledOutput()).to.have.nested.deep.property('aps.mutable-content', 1);
  533. });
  534. it('can be set to undefined', function () {
  535. note.mutableContent = true;
  536. note.mutableContent = undefined;
  537. expect(compiledOutput()).to.not.have.nested.deep.property('aps.mutable-content');
  538. });
  539. describe('setMutableContent', function () {
  540. it('is chainable', function () {
  541. expect(note.setMutableContent(true)).to.equal(note);
  542. expect(compiledOutput()).to.have.nested.deep.property('aps.mutable-content', 1);
  543. });
  544. });
  545. });
  546. describe('mdm', function () {
  547. it('defaults to undefined', function () {
  548. expect(compiledOutput()).to.not.have.nested.deep.property('mdm');
  549. });
  550. it('can be set to a string', function () {
  551. note.mdm = 'mdm payload';
  552. expect(compiledOutput()).to.deep.equal({ mdm: 'mdm payload' });
  553. });
  554. it('can be set to undefined', function () {
  555. note.mdm = 'mdm payload';
  556. note.mdm = undefined;
  557. expect(compiledOutput()).to.not.have.nested.deep.property('mdm');
  558. });
  559. it('does not include the aps payload', function () {
  560. note.mdm = 'mdm payload';
  561. note.badge = 5;
  562. expect(compiledOutput()).to.not.have.any.keys('aps');
  563. });
  564. describe('setMdm', function () {
  565. it('is chainable', function () {
  566. expect(note.setMdm('hello')).to.equal(note);
  567. expect(compiledOutput()).to.have.nested.deep.property('mdm', 'hello');
  568. });
  569. });
  570. });
  571. describe('urlArgs', function () {
  572. it('defaults to undefined', function () {
  573. expect(compiledOutput()).to.not.have.nested.deep.property('aps.url-args');
  574. });
  575. it('can be set to an array', function () {
  576. note.urlArgs = ['arg1', 'arg2'];
  577. expect(compiledOutput())
  578. .to.have.nested.deep.property('aps.url-args')
  579. .that.deep.equals(['arg1', 'arg2']);
  580. });
  581. it('can be set to undefined', function () {
  582. note.urlArgs = ['arg1', 'arg2'];
  583. note.urlArgs = undefined;
  584. expect(compiledOutput()).to.not.have.nested.deep.property('aps.url-args');
  585. });
  586. describe('setUrlArgs', function () {
  587. it('is chainable', function () {
  588. expect(note.setUrlArgs(['A318', 'BA001'])).to.equal(note);
  589. expect(compiledOutput())
  590. .to.have.nested.deep.property('aps.url-args')
  591. .that.deep.equals(['A318', 'BA001']);
  592. });
  593. });
  594. });
  595. describe('category', function () {
  596. it('defaults to undefined', function () {
  597. expect(compiledOutput()).to.not.have.nested.deep.property('aps.category');
  598. });
  599. it('can be set to a string', function () {
  600. note.category = 'the-category';
  601. expect(compiledOutput()).to.have.nested.deep.property('aps.category', 'the-category');
  602. });
  603. it('can be set to undefined', function () {
  604. note.category = 'the-category';
  605. note.category = undefined;
  606. expect(compiledOutput()).to.not.have.nested.deep.property('aps.category');
  607. });
  608. describe('setCategory', function () {
  609. it('is chainable', function () {
  610. expect(note.setCategory('reminder')).to.equal(note);
  611. expect(compiledOutput()).to.have.nested.deep.property('aps.category', 'reminder');
  612. });
  613. });
  614. });
  615. describe('target-content-id', function () {
  616. it('defaults to undefined', function () {
  617. expect(compiledOutput()).to.not.have.nested.property('aps.target-content-id');
  618. });
  619. it('can be set to a string', function () {
  620. note.targetContentIdentifier = 'the-target-content-id';
  621. expect(compiledOutput()).to.have.nested.property(
  622. 'aps.target-content-id',
  623. 'the-target-content-id'
  624. );
  625. });
  626. it('can be set to undefined', function () {
  627. note.targetContentIdentifier = 'the-target-content-identifier';
  628. note.targetContentIdentifier = undefined;
  629. expect(compiledOutput()).to.not.have.nested.property('aps.target-content-id');
  630. });
  631. describe('setTargetContentIdentifier', function () {
  632. it('is chainable', function () {
  633. expect(note.setTargetContentIdentifier('the-target-content-id')).to.equal(note);
  634. expect(compiledOutput()).to.have.nested.property(
  635. 'aps.target-content-id',
  636. 'the-target-content-id'
  637. );
  638. });
  639. });
  640. });
  641. describe('thread-id', function () {
  642. it('defaults to undefined', function () {
  643. expect(compiledOutput()).to.not.have.nested.deep.property('aps.thread-id');
  644. });
  645. it('can be set to a string', function () {
  646. note.threadId = 'the-thread-id';
  647. expect(compiledOutput()).to.have.nested.deep.property('aps.thread-id', 'the-thread-id');
  648. });
  649. it('can be set to undefined', function () {
  650. note.threadId = 'the-thread-id';
  651. note.threadId = undefined;
  652. expect(compiledOutput()).to.not.have.nested.deep.property('aps.thread-id');
  653. });
  654. describe('setThreadId', function () {
  655. it('is chainable', function () {
  656. expect(note.setThreadId('the-thread-id')).to.equal(note);
  657. expect(compiledOutput()).to.have.nested.deep.property('aps.thread-id', 'the-thread-id');
  658. });
  659. });
  660. });
  661. describe('interruption-level', function () {
  662. it('defaults to undefined', function () {
  663. expect(compiledOutput()).to.not.have.nested.property('aps.interruption-level');
  664. });
  665. it('can be set to a string', function () {
  666. note.interruptionLevel = 'the-interruption-level';
  667. expect(compiledOutput()).to.have.nested.property(
  668. 'aps.interruption-level',
  669. 'the-interruption-level'
  670. );
  671. });
  672. it('can be set to undefined', function () {
  673. note.interruptionLevel = 'the-interruption-level';
  674. note.interruptionLevel = undefined;
  675. expect(compiledOutput()).to.not.have.nested.property('aps.interruption-level');
  676. });
  677. describe('setInterruptionLevel', function () {
  678. it('is chainable', function () {
  679. expect(note.setInterruptionLevel('the-interruption-level')).to.equal(note);
  680. expect(compiledOutput()).to.have.nested.property(
  681. 'aps.interruption-level',
  682. 'the-interruption-level'
  683. );
  684. });
  685. });
  686. });
  687. describe('events', function () {
  688. it('defaults to undefined', function () {
  689. expect(compiledOutput()).to.not.have.nested.property('aps.events');
  690. });
  691. it('can be set to a string', function () {
  692. note.events = 'the-event';
  693. expect(compiledOutput()).to.have.nested.property('aps.events', 'the-event');
  694. });
  695. it('can be set to undefined', function () {
  696. note.events = 'the-event';
  697. note.events = undefined;
  698. expect(compiledOutput()).to.not.have.nested.property('aps.events');
  699. });
  700. describe('setEvents', function () {
  701. it('is chainable', function () {
  702. expect(note.setEvents('the-event')).to.equal(note);
  703. expect(compiledOutput()).to.have.nested.property('aps.events', 'the-event');
  704. });
  705. });
  706. });
  707. describe('timestamp', function () {
  708. it('defaults to undefined', function () {
  709. expect(compiledOutput()).to.not.have.nested.property('aps.timestamp');
  710. });
  711. it('can be set to a number', function () {
  712. note.timestamp = 1234;
  713. expect(compiledOutput()).to.have.nested.property('aps.timestamp', 1234);
  714. });
  715. it('can be set to undefined', function () {
  716. note.timestamp = 1234;
  717. note.timestamp = undefined;
  718. expect(compiledOutput()).to.not.have.nested.property('aps.timestamp');
  719. });
  720. describe('setTimestamp', function () {
  721. it('is chainable', function () {
  722. expect(note.setTimestamp(1234)).to.equal(note);
  723. expect(compiledOutput()).to.have.nested.property('aps.timestamp', 1234);
  724. });
  725. });
  726. });
  727. describe('relevance-score', function () {
  728. it('defaults to undefined', function () {
  729. expect(compiledOutput()).to.not.have.nested.property('aps.relevance-score');
  730. });
  731. it('can be set to a number', function () {
  732. note.relevanceScore = 1234;
  733. expect(compiledOutput()).to.have.nested.property('aps.relevance-score', 1234);
  734. });
  735. it('can be set to undefined', function () {
  736. note.relevanceScore = 1234;
  737. note.relevanceScore = undefined;
  738. expect(compiledOutput()).to.not.have.nested.property('aps.relevance-score');
  739. });
  740. describe('setRelevanceScore', function () {
  741. it('is chainable', function () {
  742. expect(note.setRelevanceScore(1234)).to.equal(note);
  743. expect(compiledOutput()).to.have.nested.property('aps.relevance-score', 1234);
  744. });
  745. });
  746. });
  747. describe('stale-date', function () {
  748. it('defaults to undefined', function () {
  749. expect(compiledOutput()).to.not.have.nested.property('aps.stale-date');
  750. });
  751. it('can be set to a number', function () {
  752. note.staleDate = 1234;
  753. expect(compiledOutput()).to.have.nested.property('aps.stale-date', 1234);
  754. });
  755. it('can be set to undefined', function () {
  756. note.staleDate = 1234;
  757. note.staleDate = undefined;
  758. expect(compiledOutput()).to.not.have.nested.property('aps.stale-date');
  759. });
  760. describe('setStaleDate', function () {
  761. it('is chainable', function () {
  762. expect(note.setStaleDate(1234)).to.equal(note);
  763. expect(compiledOutput()).to.have.nested.property('aps.stale-date', 1234);
  764. });
  765. });
  766. });
  767. describe('content-state', function () {
  768. const payload = { foo: 'bar' };
  769. it('defaults to undefined', function () {
  770. expect(compiledOutput()).to.not.have.nested.property('aps.content-state');
  771. });
  772. it('can be set to a object', function () {
  773. note.contentState = payload;
  774. expect(compiledOutput())
  775. .to.have.nested.property('aps.content-state')
  776. .that.deep.equals(payload);
  777. });
  778. it('can be set to undefined', function () {
  779. note.contentState = payload;
  780. note.contentState = undefined;
  781. expect(compiledOutput()).to.not.have.nested.property('aps.content-state');
  782. });
  783. describe('setContentState', function () {
  784. it('is chainable', function () {
  785. expect(note.setContentState(payload)).to.equal(note);
  786. expect(compiledOutput())
  787. .to.have.nested.property('aps.content-state')
  788. .that.deep.equals(payload);
  789. });
  790. });
  791. });
  792. context('when no aps properties are set', function () {
  793. it('is not present', function () {
  794. expect(compiledOutput().aps).to.be.undefined;
  795. });
  796. });
  797. });
  798. function compiledOutput() {
  799. return JSON.parse(note.compile());
  800. }
  801. });