-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
registrationSerializer.spec.ts
834 lines (730 loc) · 38 KB
/
registrationSerializer.spec.ts
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
AdmRegistrationDescription,
AdmTemplateRegistrationDescription,
AppleRegistrationDescription,
AppleTemplateRegistrationDescription,
BaiduRegistrationDescription,
BaiduTemplateRegistrationDescription,
BrowserRegistrationDescription,
BrowserTemplateRegistrationDescription,
FcmRegistrationDescription,
FcmTemplateRegistrationDescription,
GcmRegistrationDescription,
GcmTemplateRegistrationDescription,
MpnsRegistrationDescription,
MpnsTemplateRegistrationDescription,
WindowsRegistrationDescription,
WindowsTemplateRegistrationDescription,
createAdmRegistrationDescription,
createAdmTemplateRegistrationDescription,
createAppleRegistrationDescription,
createAppleTemplateRegistrationDescription,
createBaiduRegistrationDescription,
createBaiduTemplateRegistrationDescription,
createBrowserRegistrationDescription,
createBrowserTemplateRegistrationDescription,
createFcmRegistrationDescription,
createFcmTemplateRegistrationDescription,
createGcmRegistrationDescription,
createGcmTemplateRegistrationDescription,
createMpnsRegistrationDescription,
createMpnsTemplateRegistrationDescription,
createWindowsRegistrationDescription,
createWindowsTemplateRegistrationDescription,
} from "../../../src/models/registration.js";
import {
registrationDescriptionParser,
registrationDescriptionSerializer,
} from "../../../src/serializers/registrationSerializer.js";
import { assert } from "@azure/test-utils";
const ADM_REGISTEATION = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<AdmRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag,myOtherTag</Tags>
<RegistrationId>{Registration Id}</RegistrationId>
<AdmRegistrationId>{ADM Registration Id}</AdmRegistrationId>
</AdmRegistrationDescription>
</content>
</entry>`;
const ADM_TEMPLATE_REGISTRATION = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<AdmTemplateRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag,myOtherTag</Tags>
<AdmRegistrationId>{ADM Registration Id}</AdmRegistrationId>
<RegistrationId>{Registration Id}</RegistrationId>
<BodyTemplate><![CDATA[{Template for the body}]]></BodyTemplate>
</AdmTemplateRegistrationDescription>
</content>
</entry>`;
const APPLE_REGISTRATION = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<AppleRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag,myOtherTag</Tags>
<RegistrationId>{Registration Id}</RegistrationId>
<DeviceToken>{DeviceToken}</DeviceToken>
</AppleRegistrationDescription>
</content>
</entry>`;
const APPLE_TEMPLATE_REGISTRATION = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<AppleTemplateRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag,myOtherTag</Tags>
<RegistrationId>{Registration Id}</RegistrationId>
<DeviceToken>{DeviceToken}</DeviceToken>
<BodyTemplate><![CDATA[{Template for the body}]]></BodyTemplate>
<ApnsHeaders>
<ApnsHeader>
<Header>apns-priority</Header>
<Value>10</Value>
</ApnsHeader>
<ApnsHeader>
<Header>apns-expiration</Header>
<Value>0</Value>
</ApnsHeader>
</ApnsHeaders>
</AppleTemplateRegistrationDescription>
</content>
</entry>`;
const BAIDU_REGISTRATION = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<BaiduRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag,myOtherTag</Tags>
<RegistrationId>{Registration Id}</RegistrationId>
<BaiduChannelId>{Baidu Channel Id}</BaiduChannelId>
<BaiduUserId>{Baidu User Id}</BaiduUserId>
</BaiduRegistrationDescription>
</content>
</entry>`;
const BAIDU_TEMPLATE_REGISTRATION = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<BaiduTemplateRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag,myOtherTag</Tags>
<RegistrationId>{Registration Id}</RegistrationId>
<BaiduChannelId>{Baidu Channel Id}</BaiduChannelId>
<BaiduUserId>{Baidu User Id}</BaiduUserId>
<BodyTemplate><![CDATA[{Template for the body}]]></BodyTemplate>
</BaiduTemplateRegistrationDescription>
</content>
</entry>`;
const BROWSER_REGISTRATION = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<BrowserRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag,myOtherTag</Tags>
<RegistrationId>{Registration Id}</RegistrationId>
<Endpoint>{Endpoint}</Endpoint>
<P256DH>{P256DH}</P256DH>
<Auth>{Auth Secret}</Auth>
</BrowserRegistrationDescription>
</content>
</entry>`;
const BROWSER_TEMPLATE_REGISTRATION = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<BrowserTemplateRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag,myOtherTag</Tags>
<RegistrationId>{Registration Id}</RegistrationId>
<Endpoint>{Endpoint}</Endpoint>
<P256DH>{P256DH}</P256DH>
<Auth>{Auth Secret}</Auth>
<BodyTemplate><![CDATA[{Template for the body}]]></BodyTemplate>
</BrowserTemplateRegistrationDescription>
</content>
</entry>`;
const GCM_REGISTRATION = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<GcmRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag,myOtherTag</Tags>
<RegistrationId>{Registration Id}</RegistrationId>
<GcmRegistrationId>{GCM Registration Id}</GcmRegistrationId>
</GcmRegistrationDescription>
</content>
</entry>`;
const GCM_TEMPLATE_REGISTRATION = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<GcmTemplateRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag,myOtherTag</Tags>
<RegistrationId>{Registration Id}</RegistrationId>
<GcmRegistrationId>{GCM Registration Id}</GcmRegistrationId>
<BodyTemplate><![CDATA[{Template for the body}]]></BodyTemplate>
</GcmTemplateRegistrationDescription>
</content>
</entry>`;
const FCM_REGISTRATION = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<FcmRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag,myOtherTag</Tags>
<RegistrationId>{Registration Id}</RegistrationId>
<FcmRegistrationId>{FCM Registration Id}</FcmRegistrationId>
</FcmRegistrationDescription>
</content>
</entry>`;
const FCM_TEMPLATE_REGISTRATION = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<FcmTemplateRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag,myOtherTag</Tags>
<RegistrationId>{Registration Id}</RegistrationId>
<FcmRegistrationId>{FCM Registration Id}</FcmRegistrationId>
<BodyTemplate><![CDATA[{Template for the body}]]></BodyTemplate>
</FcmTemplateRegistrationDescription>
</content>
</entry>`;
const MPNS_REGISTRATION = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<MpnsRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag,myOtherTag</Tags>
<RegistrationId>{Registration Id}</RegistrationId>
<ChannelUri>https://www.microsoft.com/</ChannelUri>
</MpnsRegistrationDescription>
</content>
</entry>`;
const MPNS_TEMPLATE_REGISTRATION = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<MpnsTemplateRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag,myOtherTag</Tags>
<RegistrationId>{Registration Id}</RegistrationId>
<ChannelUri>https://www.microsoft.com/</ChannelUri>
<BodyTemplate><![CDATA[{Template for the body}]]></BodyTemplate>
<MpnsHeaders>
<MpnsHeader>
<Header>X-WindowsPhone-Target</Header>
<Value>toast</Value>
</MpnsHeader>
<MpnsHeader>
<Header>X-NotificationClass</Header>
<Value>[batching interval]</Value>
</MpnsHeader>
</MpnsHeaders>
</MpnsTemplateRegistrationDescription>
</content>
</entry>`;
const WNS_REGISTRATION = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<WindowsRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag,myOtherTag</Tags>
<RegistrationId>{Registration Id}</RegistrationId>
<ChannelUri>https://www.microsoft.com/</ChannelUri>
</WindowsRegistrationDescription>
</content>
</entry>`;
const WINDOWS_TEMPLATE_REGISTRATION = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<WindowsTemplateRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag,myOtherTag</Tags>
<RegistrationId>{Registration Id}</RegistrationId>
<ChannelUri>https://www.microsoft.com/</ChannelUri>
<BodyTemplate><![CDATA[{Template for the body}]]></BodyTemplate>
<WnsHeaders>
<WnsHeader>
<Header>X-WNS-Type</Header>
<Value>toast</Value>
</WnsHeader>
<WnsHeader>
<Header>X-NotificationClass</Header>
<Value>[batching interval]</Value>
</WnsHeader>
</WnsHeaders>
</WindowsTemplateRegistrationDescription>
</content>
</entry>`;
describe("parseRegistrationEntry", () => {
it("should parse an Amazon Device Messaging registration description", async () => {
const registration = (await registrationDescriptionParser.parseRegistrationEntry(
ADM_REGISTEATION
)) as AdmRegistrationDescription;
assert.equal(registration.type, "Adm");
assert.equal(registration.registrationId, "{Registration Id}");
assert.equal(registration.admRegistrationId, "{ADM Registration Id}");
assert.deepEqual(registration.tags, ["myTag", "myOtherTag"]);
});
it("should parse an Amazon Device Messaging template registration description", async () => {
const registration = (await registrationDescriptionParser.parseRegistrationEntry(
ADM_TEMPLATE_REGISTRATION
)) as AdmTemplateRegistrationDescription;
assert.equal(registration.type, "AdmTemplate");
assert.equal(registration.registrationId, "{Registration Id}");
assert.equal(registration.admRegistrationId, "{ADM Registration Id}");
assert.deepEqual(registration.tags, ["myTag", "myOtherTag"]);
assert.equal(registration.bodyTemplate, "{Template for the body}");
});
it("should parse an apple registration description", async () => {
const registration = (await registrationDescriptionParser.parseRegistrationEntry(
APPLE_REGISTRATION
)) as AppleRegistrationDescription;
assert.equal(registration.type, "Apple");
assert.equal(registration.registrationId, "{Registration Id}");
assert.equal(registration.deviceToken, "{DeviceToken}");
assert.deepEqual(registration.tags, ["myTag", "myOtherTag"]);
});
it("should parse an apple template registration description", async () => {
const registration = (await registrationDescriptionParser.parseRegistrationEntry(
APPLE_TEMPLATE_REGISTRATION
)) as AppleTemplateRegistrationDescription;
assert.equal(registration.type, "AppleTemplate");
assert.equal(registration.registrationId, "{Registration Id}");
assert.equal(registration.deviceToken, "{DeviceToken}");
assert.deepEqual(registration.tags, ["myTag", "myOtherTag"]);
assert.equal(registration.bodyTemplate, "{Template for the body}");
assert.equal(registration.apnsHeaders!["apns-priority"], "10");
assert.equal(registration.apnsHeaders!["apns-expiration"], "0");
});
it("should parse an Baidu registration description", async () => {
const registration = (await registrationDescriptionParser.parseRegistrationEntry(
BAIDU_REGISTRATION
)) as BaiduRegistrationDescription;
assert.equal(registration.type, "Baidu");
assert.equal(registration.registrationId, "{Registration Id}");
assert.equal(registration.baiduChannelId, "{Baidu Channel Id}");
assert.equal(registration.baiduUserId, "{Baidu User Id}");
assert.deepEqual(registration.tags, ["myTag", "myOtherTag"]);
});
it("should parse an Baidu template registration description", async () => {
const registration = (await registrationDescriptionParser.parseRegistrationEntry(
BAIDU_TEMPLATE_REGISTRATION
)) as BaiduTemplateRegistrationDescription;
assert.equal(registration.type, "BaiduTemplate");
assert.equal(registration.registrationId, "{Registration Id}");
assert.equal(registration.baiduChannelId, "{Baidu Channel Id}");
assert.equal(registration.baiduUserId, "{Baidu User Id}");
assert.deepEqual(registration.tags, ["myTag", "myOtherTag"]);
assert.equal(registration.bodyTemplate, "{Template for the body}");
});
it("should parse an Browser registration description", async () => {
const registration = (await registrationDescriptionParser.parseRegistrationEntry(
BROWSER_REGISTRATION
)) as BrowserRegistrationDescription;
assert.equal(registration.type, "Browser");
assert.equal(registration.registrationId, "{Registration Id}");
assert.equal(registration.endpoint, "{Endpoint}");
assert.equal(registration.p256dh, "{P256DH}");
assert.equal(registration.auth, "{Auth Secret}");
assert.deepEqual(registration.tags, ["myTag", "myOtherTag"]);
});
it("should parse an Browser template registration description", async () => {
const registration = (await registrationDescriptionParser.parseRegistrationEntry(
BROWSER_TEMPLATE_REGISTRATION
)) as BrowserTemplateRegistrationDescription;
assert.equal(registration.type, "BrowserTemplate");
assert.equal(registration.registrationId, "{Registration Id}");
assert.equal(registration.endpoint, "{Endpoint}");
assert.equal(registration.p256dh, "{P256DH}");
assert.equal(registration.auth, "{Auth Secret}");
assert.deepEqual(registration.tags, ["myTag", "myOtherTag"]);
assert.equal(registration.bodyTemplate, "{Template for the body}");
});
it("should parse a GCM registration description", async () => {
const registration = (await registrationDescriptionParser.parseRegistrationEntry(
GCM_REGISTRATION
)) as GcmRegistrationDescription;
assert.equal(registration.type, "Gcm");
assert.equal(registration.registrationId, "{Registration Id}");
assert.equal(registration.gcmRegistrationId, "{GCM Registration Id}");
assert.deepEqual(registration.tags, ["myTag", "myOtherTag"]);
});
it("should parse a GCM template registration description", async () => {
const registration = (await registrationDescriptionParser.parseRegistrationEntry(
GCM_TEMPLATE_REGISTRATION
)) as GcmTemplateRegistrationDescription;
assert.equal(registration.type, "GcmTemplate");
assert.equal(registration.registrationId, "{Registration Id}");
assert.equal(registration.gcmRegistrationId, "{GCM Registration Id}");
assert.deepEqual(registration.tags, ["myTag", "myOtherTag"]);
assert.equal(registration.bodyTemplate, "{Template for the body}");
});
it("should parse an FCM registration description", async () => {
const registration = (await registrationDescriptionParser.parseRegistrationEntry(
FCM_REGISTRATION
)) as FcmRegistrationDescription;
assert.equal(registration.type, "Fcm");
assert.equal(registration.registrationId, "{Registration Id}");
assert.equal(registration.fcmRegistrationId, "{FCM Registration Id}");
assert.deepEqual(registration.tags, ["myTag", "myOtherTag"]);
});
it("should parse an FCM template registration description", async () => {
const registration = (await registrationDescriptionParser.parseRegistrationEntry(
FCM_TEMPLATE_REGISTRATION
)) as FcmTemplateRegistrationDescription;
assert.equal(registration.type, "FcmTemplate");
assert.equal(registration.registrationId, "{Registration Id}");
assert.equal(registration.fcmRegistrationId, "{FCM Registration Id}");
assert.deepEqual(registration.tags, ["myTag", "myOtherTag"]);
assert.equal(registration.bodyTemplate, "{Template for the body}");
});
it("should parse an MPNS registration description", async () => {
const registration = (await registrationDescriptionParser.parseRegistrationEntry(
MPNS_REGISTRATION
)) as MpnsRegistrationDescription;
assert.equal(registration.type, "Mpns");
assert.equal(registration.registrationId, "{Registration Id}");
assert.equal(registration.channelUri, "https://www.microsoft.com/");
assert.deepEqual(registration.tags, ["myTag", "myOtherTag"]);
});
it("should parse an MPNS template registration description", async () => {
const registration = (await registrationDescriptionParser.parseRegistrationEntry(
MPNS_TEMPLATE_REGISTRATION
)) as MpnsTemplateRegistrationDescription;
assert.equal(registration.type, "MpnsTemplate");
assert.equal(registration.registrationId, "{Registration Id}");
assert.equal(registration.channelUri, "https://www.microsoft.com/");
assert.deepEqual(registration.tags, ["myTag", "myOtherTag"]);
assert.equal(registration.bodyTemplate, "{Template for the body}");
assert.equal(registration.mpnsHeaders!["X-WindowsPhone-Target"], "toast");
assert.equal(registration.mpnsHeaders!["X-NotificationClass"], "[batching interval]");
});
it("should parse an Windows registration description", async () => {
const registration = (await registrationDescriptionParser.parseRegistrationEntry(
WNS_REGISTRATION
)) as WindowsRegistrationDescription;
assert.equal(registration.type, "Windows");
assert.equal(registration.registrationId, "{Registration Id}");
assert.equal(registration.channelUri, "https://www.microsoft.com/");
assert.deepEqual(registration.tags, ["myTag", "myOtherTag"]);
});
it("should parse an Windows template registration description", async () => {
const registration = (await registrationDescriptionParser.parseRegistrationEntry(
WINDOWS_TEMPLATE_REGISTRATION
)) as WindowsTemplateRegistrationDescription;
assert.equal(registration.type, "WindowsTemplate");
assert.equal(registration.registrationId, "{Registration Id}");
assert.equal(registration.channelUri, "https://www.microsoft.com/");
assert.deepEqual(registration.tags, ["myTag", "myOtherTag"]);
assert.equal(registration.bodyTemplate, "{Template for the body}");
assert.equal(registration.wnsHeaders!["X-WNS-Type"], "toast");
assert.equal(registration.wnsHeaders!["X-NotificationClass"], "[batching interval]");
});
});
const REGISTRATION_FEED = `<?xml version="1.0" encoding="utf-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="/{NotificationTopic}/channels/{channel hash}" />
<id> https://{tenant}.windows.net/{NotificationTopic}/channels/{channel hash}</id>
<updated>2012-08-17T17:32:00Z</updated>
<entry xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:etag="W/"1234567890"">
<id>https://{tenant}.windows.net/{NotificationTopic}/registrations/{registrationId}</id>
<title type="text"> /{NotificationTopic}/registrations/{registrationId}</title>
<updated>2012-08-17T17:32:00Z</updated>
<content type="application/xml">
<WindowsRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<ETag>{ETag}</ETag>
<ExpirationTime>2012-07-16T19:20+01:00</ExpirationTime>
<RegistrationId>{Registration Id}</RegistrationId>
<Tags>myTag,myOtherTag</Tags>
<ChannelUri>https://www.microsoft.com/</ChannelUri>
</WindowsRegistrationDescription>
</content>
</entry>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<AppleTemplateRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag,myOtherTag</Tags>
<RegistrationId>{Registration Id}</RegistrationId>
<DeviceToken>{DeviceToken}</DeviceToken>
<BodyTemplate><![CDATA[{Template for the body}]]></BodyTemplate>
<Expiry>2011-10-05T14:48:00.000Z</Expiry>
</AppleTemplateRegistrationDescription>
</content>
</entry>
</feed>`;
const EMPTY_REGISTRATION_FEED = `<?xml version="1.0" encoding="utf-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">Registrations</title>
<id>https://testns.servicebus.windows.net/testhub/registrations/?api-version=2020-06</id>
<updated>2022-09-06T20:06:33Z</updated>
<link rel="self" href="https://testns.servicebus.windows.net/testhub/registrations/?api-version=2020-06" />
</feed>`;
describe("parseRegistrationFeed", () => {
it("should parse a registration feed", async () => {
const registrations = await registrationDescriptionParser.parseRegistrationFeed(
REGISTRATION_FEED
);
const windowsRegistration = registrations[0] as WindowsRegistrationDescription;
assert.equal(windowsRegistration.type, "Windows");
assert.equal(windowsRegistration.registrationId, "{Registration Id}");
assert.equal(windowsRegistration.channelUri, "https://www.microsoft.com/");
assert.deepEqual(windowsRegistration.tags, ["myTag", "myOtherTag"]);
const appleRegistration = registrations[1] as AppleTemplateRegistrationDescription;
assert.equal(appleRegistration.type, "AppleTemplate");
assert.equal(appleRegistration.registrationId, "{Registration Id}");
assert.equal(appleRegistration.deviceToken, "{DeviceToken}");
assert.deepEqual(appleRegistration.tags, ["myTag", "myOtherTag"]);
});
it("should parse an empty feed", async () => {
const registrations = await registrationDescriptionParser.parseRegistrationFeed(
EMPTY_REGISTRATION_FEED
);
assert.equal(registrations.length, 0);
});
});
describe("serializeRegistrationDescription", () => {
it("should serialize an AdmRegistrationDescription", () => {
const registration = createAdmRegistrationDescription({
admRegistrationId: "{ADM Registration ID}",
tags: ["myTag", "myOtherTag"],
});
const xml = registrationDescriptionSerializer.serializeRegistrationDescription(registration);
assert.isTrue(xml.indexOf("<AdmRegistrationDescription") !== -1);
assert.isTrue(
xml.indexOf("<AdmRegistrationId>{ADM Registration ID}</AdmRegistrationId>") !== -1
);
assert.isTrue(xml.indexOf("<Tags>myTag,myOtherTag</Tags>") !== -1);
assert.isTrue(xml.indexOf("</AdmRegistrationDescription>") !== -1);
});
it("should serialize an AdmTemplateRegistrationDescription", () => {
const registration = createAdmTemplateRegistrationDescription({
admRegistrationId: "{ADM Registration ID}",
tags: ["myTag", "myOtherTag"],
bodyTemplate: "{Template for the body}",
});
const xml = registrationDescriptionSerializer.serializeRegistrationDescription(registration);
assert.isTrue(xml.indexOf("<AdmTemplateRegistrationDescription") !== -1);
assert.isTrue(
xml.indexOf("<AdmRegistrationId>{ADM Registration ID}</AdmRegistrationId>") !== -1
);
assert.isTrue(xml.indexOf("<Tags>myTag,myOtherTag</Tags>") !== -1);
assert.isTrue(
xml.indexOf("<BodyTemplate><![CDATA[{Template for the body}]]></BodyTemplate>") !== -1
);
assert.isTrue(xml.indexOf("</AdmTemplateRegistrationDescription>") !== -1);
});
it("should serialize an AppleRegistrationDescription", () => {
const registration = createAppleRegistrationDescription({
deviceToken: "{DeviceToken}",
tags: ["myTag", "myOtherTag"],
});
const xml = registrationDescriptionSerializer.serializeRegistrationDescription(registration);
assert.isTrue(xml.indexOf("<AppleRegistrationDescription") !== -1);
assert.isTrue(xml.indexOf("<DeviceToken>{DeviceToken}</DeviceToken>") !== -1);
assert.isTrue(xml.indexOf("<Tags>myTag,myOtherTag</Tags>") !== -1);
assert.isTrue(xml.indexOf("</AppleRegistrationDescription>") !== -1);
});
it("should serialize an AppleTemplateRegistrationDescription", () => {
const registration = createAppleTemplateRegistrationDescription({
deviceToken: "{DeviceToken}",
tags: ["myTag", "myOtherTag"],
bodyTemplate: "{Template for the body}",
apnsHeaders: {
"apns-topic": "com.microsoft.SampleApp",
"apns-priority": "10",
},
});
const xml = registrationDescriptionSerializer.serializeRegistrationDescription(registration);
assert.isTrue(xml.indexOf("<AppleTemplateRegistrationDescription") !== -1);
assert.isTrue(xml.indexOf("<DeviceToken>{DeviceToken}</DeviceToken>") !== -1);
assert.isTrue(xml.indexOf("<Tags>myTag,myOtherTag</Tags>") !== -1);
assert.isTrue(
xml.indexOf("<BodyTemplate><![CDATA[{Template for the body}]]></BodyTemplate>") !== -1
);
assert.isTrue(xml.indexOf("<ApnsHeaders>") !== -1);
assert.isTrue(xml.indexOf("<Header>apns-topic</Header>") !== -1);
assert.isTrue(xml.indexOf("<Value>com.microsoft.SampleApp</Value>") !== -1);
assert.isTrue(xml.indexOf("<Header>apns-priority</Header>") !== -1);
assert.isTrue(xml.indexOf("<Value>10</Value>") !== -1);
assert.isTrue(xml.indexOf("</ApnsHeaders>") !== -1);
assert.isTrue(xml.indexOf("</AppleTemplateRegistrationDescription>") !== -1);
});
it("should serialize a BaiduRegistrationDescription", () => {
const registration = createBaiduRegistrationDescription({
baiduChannelId: "{Baidu Channel ID}",
baiduUserId: "{Baidu User ID}",
tags: ["myTag", "myOtherTag"],
});
const xml = registrationDescriptionSerializer.serializeRegistrationDescription(registration);
assert.isTrue(xml.indexOf("<BaiduRegistrationDescription") !== -1);
assert.isTrue(xml.indexOf("<BaiduChannelId>{Baidu Channel ID}</BaiduChannelId>") !== -1);
assert.isTrue(xml.indexOf("<BaiduUserId>{Baidu User ID}</BaiduUserId>") !== -1);
assert.isTrue(xml.indexOf("<Tags>myTag,myOtherTag</Tags>") !== -1);
assert.isTrue(xml.indexOf("</BaiduRegistrationDescription>") !== -1);
});
it("should serialize a BaiduTemplateRegistrationDescription", () => {
const registration = createBaiduTemplateRegistrationDescription({
baiduChannelId: "{Baidu Channel ID}",
baiduUserId: "{Baidu User ID}",
tags: ["myTag", "myOtherTag"],
bodyTemplate: "{Template for the body}",
});
const xml = registrationDescriptionSerializer.serializeRegistrationDescription(registration);
assert.isTrue(xml.indexOf("<BaiduTemplateRegistrationDescription") !== -1);
assert.isTrue(xml.indexOf("<BaiduChannelId>{Baidu Channel ID}</BaiduChannelId>") !== -1);
assert.isTrue(xml.indexOf("<BaiduUserId>{Baidu User ID}</BaiduUserId>") !== -1);
assert.isTrue(xml.indexOf("<Tags>myTag,myOtherTag</Tags>") !== -1);
assert.isTrue(
xml.indexOf("<BodyTemplate><![CDATA[{Template for the body}]]></BodyTemplate>") !== -1
);
assert.isTrue(xml.indexOf("</BaiduTemplateRegistrationDescription>") !== -1);
});
it("should serialize a BrowserRegistrationDescription", () => {
const registration = createBrowserRegistrationDescription({
endpoint: "https://www.microsoft.com/",
p256dh: "{P256DH}",
auth: "{Auth Secret}",
tags: ["myTag", "myOtherTag"],
});
const xml = registrationDescriptionSerializer.serializeRegistrationDescription(registration);
assert.isTrue(xml.indexOf("<BrowserRegistrationDescription") !== -1);
assert.isTrue(xml.indexOf("<Endpoint>https://www.microsoft.com/</Endpoint>") !== -1);
assert.isTrue(xml.indexOf("<P256DH>{P256DH}</P256DH>") !== -1);
assert.isTrue(xml.indexOf("<Auth>{Auth Secret}</Auth>") !== -1);
assert.isTrue(xml.indexOf("<Tags>myTag,myOtherTag</Tags>") !== -1);
assert.isTrue(xml.indexOf("</BrowserRegistrationDescription>") !== -1);
});
it("should serialize a BrowserTemplateRegistrationDescription", () => {
const registration = createBrowserTemplateRegistrationDescription({
endpoint: "https://www.microsoft.com/",
p256dh: "{P256DH}",
auth: "{Auth Secret}",
tags: ["myTag", "myOtherTag"],
bodyTemplate: "{Template for the body}",
});
const xml = registrationDescriptionSerializer.serializeRegistrationDescription(registration);
assert.isTrue(xml.indexOf("<BrowserTemplateRegistrationDescription") !== -1);
assert.isTrue(xml.indexOf("<Endpoint>https://www.microsoft.com/</Endpoint>") !== -1);
assert.isTrue(xml.indexOf("<P256DH>{P256DH}</P256DH>") !== -1);
assert.isTrue(xml.indexOf("<Auth>{Auth Secret}</Auth>") !== -1);
assert.isTrue(xml.indexOf("<Tags>myTag,myOtherTag</Tags>") !== -1);
assert.isTrue(
xml.indexOf("<BodyTemplate><![CDATA[{Template for the body}]]></BodyTemplate>") !== -1
);
assert.isTrue(xml.indexOf("</BrowserTemplateRegistrationDescription>") !== -1);
});
it("should serialize a GcmRegistrationDescription", () => {
const registration = createGcmRegistrationDescription({
gcmRegistrationId: "{GCM Registration ID}",
tags: ["myTag", "myOtherTag"],
});
const xml = registrationDescriptionSerializer.serializeRegistrationDescription(registration);
assert.isTrue(xml.indexOf("<GcmRegistrationDescription") !== -1);
assert.isTrue(
xml.indexOf("<GcmRegistrationId>{GCM Registration ID}</GcmRegistrationId>") !== -1
);
assert.isTrue(xml.indexOf("<Tags>myTag,myOtherTag</Tags>") !== -1);
assert.isTrue(xml.indexOf("</GcmRegistrationDescription>") !== -1);
});
it("should serialize a GcmTemplateRegistrationDescription", () => {
const registration = createGcmTemplateRegistrationDescription({
gcmRegistrationId: "{GCM Registration ID}",
tags: ["myTag", "myOtherTag"],
bodyTemplate: "{Template for the body}",
});
const xml = registrationDescriptionSerializer.serializeRegistrationDescription(registration);
assert.isTrue(xml.indexOf("<GcmTemplateRegistrationDescription") !== -1);
assert.isTrue(
xml.indexOf("<GcmRegistrationId>{GCM Registration ID}</GcmRegistrationId>") !== -1
);
assert.isTrue(xml.indexOf("<Tags>myTag,myOtherTag</Tags>") !== -1);
assert.isTrue(
xml.indexOf("<BodyTemplate><![CDATA[{Template for the body}]]></BodyTemplate>") !== -1
);
assert.isTrue(xml.indexOf("</GcmTemplateRegistrationDescription>") !== -1);
});
it("should serialize an FcmRegistrationDescription", () => {
const registration = createFcmRegistrationDescription({
fcmRegistrationId: "{FCM Registration ID}",
tags: ["myTag", "myOtherTag"],
});
const xml = registrationDescriptionSerializer.serializeRegistrationDescription(registration);
assert.isTrue(xml.indexOf("<FcmRegistrationDescription") !== -1);
assert.isTrue(
xml.indexOf("<FcmRegistrationId>{FCM Registration ID}</FcmRegistrationId>") !== -1
);
assert.isTrue(xml.indexOf("<Tags>myTag,myOtherTag</Tags>") !== -1);
assert.isTrue(xml.indexOf("</FcmRegistrationDescription>") !== -1);
});
it("should serialize an FcmTemplateRegistrationDescription", () => {
const registration = createFcmTemplateRegistrationDescription({
fcmRegistrationId: "{FCM Registration ID}",
tags: ["myTag", "myOtherTag"],
bodyTemplate: "{Template for the body}",
});
const xml = registrationDescriptionSerializer.serializeRegistrationDescription(registration);
assert.isTrue(xml.indexOf("<FcmTemplateRegistrationDescription") !== -1);
assert.isTrue(
xml.indexOf("<FcmRegistrationId>{FCM Registration ID}</FcmRegistrationId>") !== -1
);
assert.isTrue(xml.indexOf("<Tags>myTag,myOtherTag</Tags>") !== -1);
assert.isTrue(
xml.indexOf("<BodyTemplate><![CDATA[{Template for the body}]]></BodyTemplate>") !== -1
);
assert.isTrue(xml.indexOf("</FcmTemplateRegistrationDescription>") !== -1);
});
it("should serialize an MpnsRegistrationDescription", () => {
const registration = createMpnsRegistrationDescription({
channelUri: "https://www.microsoft.com/",
tags: ["myTag", "myOtherTag"],
});
const xml = registrationDescriptionSerializer.serializeRegistrationDescription(registration);
assert.isTrue(xml.indexOf("<MpnsRegistrationDescription") !== -1);
assert.isTrue(xml.indexOf("<ChannelUri>https://www.microsoft.com/</ChannelUri>") !== -1);
assert.isTrue(xml.indexOf("<Tags>myTag,myOtherTag</Tags>") !== -1);
assert.isTrue(xml.indexOf("</MpnsRegistrationDescription>") !== -1);
});
it("should serialize an MpnsTemplateRegistrationDescription", () => {
const registration = createMpnsTemplateRegistrationDescription({
channelUri: "https://www.microsoft.com/",
tags: ["myTag", "myOtherTag"],
bodyTemplate: "{Template for the body}",
mpnsHeaders: {
"X-MPNS-TYPE": "mpns/tile",
},
});
const xml = registrationDescriptionSerializer.serializeRegistrationDescription(registration);
assert.isTrue(xml.indexOf("<MpnsTemplateRegistrationDescription") !== -1);
assert.isTrue(xml.indexOf("<ChannelUri>https://www.microsoft.com/</ChannelUri>") !== -1);
assert.isTrue(xml.indexOf("<Tags>myTag,myOtherTag</Tags>") !== -1);
assert.isTrue(
xml.indexOf("<BodyTemplate><![CDATA[{Template for the body}]]></BodyTemplate>") !== -1
);
assert.isTrue(xml.indexOf("<MpnsHeaders>") !== -1);
assert.isTrue(xml.indexOf("<Header>X-MPNS-TYPE</Header>") !== -1);
assert.isTrue(xml.indexOf("<Value>mpns/tile</Value>") !== -1);
assert.isTrue(xml.indexOf("</MpnsHeaders>") !== -1);
assert.isTrue(xml.indexOf("</MpnsTemplateRegistrationDescription>") !== -1);
});
it("should serialize an WindowsRegistrationDescription", () => {
const registration = createWindowsRegistrationDescription({
channelUri: "https://www.microsoft.com/",
tags: ["myTag", "myOtherTag"],
});
const xml = registrationDescriptionSerializer.serializeRegistrationDescription(registration);
assert.isTrue(xml.indexOf("<WindowsRegistrationDescription") !== -1);
assert.isTrue(xml.indexOf("<ChannelUri>https://www.microsoft.com/</ChannelUri>") !== -1);
assert.isTrue(xml.indexOf("<Tags>myTag,myOtherTag</Tags>") !== -1);
assert.isTrue(xml.indexOf("</WindowsRegistrationDescription>") !== -1);
});
it("should serialize an WindowsTemplateRegistrationDescription", () => {
const registration = createWindowsTemplateRegistrationDescription({
channelUri: "https://www.microsoft.com/",
tags: ["myTag", "myOtherTag"],
bodyTemplate: "{Template for the body}",
wnsHeaders: {
"X-WNS-TYPE": "wns/tile",
},
});
const xml = registrationDescriptionSerializer.serializeRegistrationDescription(registration);
assert.isTrue(xml.indexOf("<WindowsTemplateRegistrationDescription") !== -1);
assert.isTrue(xml.indexOf("<ChannelUri>https://www.microsoft.com/</ChannelUri>") !== -1);
assert.isTrue(xml.indexOf("<Tags>myTag,myOtherTag</Tags>") !== -1);
assert.isTrue(
xml.indexOf("<BodyTemplate><![CDATA[{Template for the body}]]></BodyTemplate>") !== -1
);
assert.isTrue(xml.indexOf("<WnsHeaders>") !== -1);
assert.isTrue(xml.indexOf("<Header>X-WNS-TYPE</Header>") !== -1);
assert.isTrue(xml.indexOf("<Value>wns/tile</Value>") !== -1);
assert.isTrue(xml.indexOf("</WnsHeaders>") !== -1);
assert.isTrue(xml.indexOf("</WindowsTemplateRegistrationDescription>") !== -1);
});
});