@purchasely/cordova-plugin-purchasely 5.6.0 → 5.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,946 @@
1
+ /**
2
+ * Unit tests for Purchasely.js
3
+ */
4
+
5
+ // Mock cordova/exec
6
+ const mockExec = jest.fn();
7
+ jest.mock('cordova/exec', () => mockExec, { virtual: true });
8
+
9
+ // Mock cordova global
10
+ global.cordova = {
11
+ define: {
12
+ moduleMap: {
13
+ 'cordova/plugin_list': {
14
+ exports: {
15
+ metadata: {
16
+ 'cordova-plugin-purchasely': '5.6.2'
17
+ }
18
+ }
19
+ }
20
+ }
21
+ }
22
+ };
23
+
24
+ // Import the module after mocks are set up
25
+ const Purchasely = require('../www/Purchasely');
26
+
27
+ describe('Purchasely', () => {
28
+ beforeEach(() => {
29
+ mockExec.mockClear();
30
+ });
31
+
32
+ describe('Constants', () => {
33
+ describe('LogLevel', () => {
34
+ it('should have correct log level values', () => {
35
+ expect(Purchasely.LogLevel.DEBUG).toBe(0);
36
+ expect(Purchasely.LogLevel.INFO).toBe(1);
37
+ expect(Purchasely.LogLevel.WARN).toBe(2);
38
+ expect(Purchasely.LogLevel.ERROR).toBe(3);
39
+ });
40
+ });
41
+
42
+ describe('Attribute', () => {
43
+ it('should have correct attribute values', () => {
44
+ expect(Purchasely.Attribute.FIREBASE_APP_INSTANCE_ID).toBe(0);
45
+ expect(Purchasely.Attribute.AIRSHIP_CHANNEL_ID).toBe(1);
46
+ expect(Purchasely.Attribute.ADJUST_ID).toBe(4);
47
+ expect(Purchasely.Attribute.APPSFLYER_ID).toBe(5);
48
+ expect(Purchasely.Attribute.AMPLITUDE_USER_ID).toBe(16);
49
+ expect(Purchasely.Attribute.BATCH_CUSTOM_USER_ID).toBe(20);
50
+ });
51
+ });
52
+
53
+ describe('DataProcessingLegalBasis', () => {
54
+ it('should have correct legal basis values', () => {
55
+ expect(Purchasely.DataProcessingLegalBasis.essential).toBe('ESSENTIAL');
56
+ expect(Purchasely.DataProcessingLegalBasis.optional).toBe('OPTIONAL');
57
+ });
58
+ });
59
+
60
+ describe('DataProcessingPurpose', () => {
61
+ it('should have correct purpose values', () => {
62
+ expect(Purchasely.DataProcessingPurpose.allNonEssentials).toBe('ALL_NON_ESSENTIALS');
63
+ expect(Purchasely.DataProcessingPurpose.analytics).toBe('ANALYTICS');
64
+ expect(Purchasely.DataProcessingPurpose.identifiedAnalytics).toBe('IDENTIFIED_ANALYTICS');
65
+ expect(Purchasely.DataProcessingPurpose.campaigns).toBe('CAMPAIGNS');
66
+ expect(Purchasely.DataProcessingPurpose.personalization).toBe('PERSONALIZATION');
67
+ expect(Purchasely.DataProcessingPurpose.thirdPartyIntegrations).toBe('THIRD_PARTY_INTEGRATIONS');
68
+ });
69
+ });
70
+
71
+ describe('PurchaseResult', () => {
72
+ it('should have correct purchase result values', () => {
73
+ expect(Purchasely.PurchaseResult.PURCHASED).toBe(0);
74
+ expect(Purchasely.PurchaseResult.CANCELLED).toBe(1);
75
+ expect(Purchasely.PurchaseResult.RESTORED).toBe(2);
76
+ });
77
+ });
78
+
79
+ describe('SubscriptionSource', () => {
80
+ it('should have correct subscription source values', () => {
81
+ expect(Purchasely.SubscriptionSource.appleAppStore).toBe(0);
82
+ expect(Purchasely.SubscriptionSource.googlePlayStore).toBe(1);
83
+ expect(Purchasely.SubscriptionSource.amazonAppstore).toBe(2);
84
+ expect(Purchasely.SubscriptionSource.huaweiAppGallery).toBe(3);
85
+ expect(Purchasely.SubscriptionSource.none).toBe(4);
86
+ });
87
+ });
88
+
89
+ describe('PlanType', () => {
90
+ it('should have correct plan type values', () => {
91
+ expect(Purchasely.PlanType.consumable).toBe(0);
92
+ expect(Purchasely.PlanType.nonConsumable).toBe(1);
93
+ expect(Purchasely.PlanType.autoRenewingSubscription).toBe(2);
94
+ expect(Purchasely.PlanType.nonRenewingSubscription).toBe(3);
95
+ expect(Purchasely.PlanType.unknown).toBe(4);
96
+ });
97
+ });
98
+
99
+ describe('RunningMode', () => {
100
+ it('should have correct running mode values', () => {
101
+ expect(Purchasely.RunningMode.paywallObserver).toBe(2);
102
+ expect(Purchasely.RunningMode.full).toBe(3);
103
+ });
104
+ });
105
+
106
+ describe('PaywallAction', () => {
107
+ it('should have correct paywall action values', () => {
108
+ expect(Purchasely.PaywallAction.close).toBe('close');
109
+ expect(Purchasely.PaywallAction.close_all).toBe('close_all');
110
+ expect(Purchasely.PaywallAction.login).toBe('login');
111
+ expect(Purchasely.PaywallAction.navigate).toBe('navigate');
112
+ expect(Purchasely.PaywallAction.purchase).toBe('purchase');
113
+ expect(Purchasely.PaywallAction.restore).toBe('restore');
114
+ expect(Purchasely.PaywallAction.open_presentation).toBe('open_presentation');
115
+ expect(Purchasely.PaywallAction.open_placement).toBe('open_placement');
116
+ expect(Purchasely.PaywallAction.promo_code).toBe('promo_code');
117
+ expect(Purchasely.PaywallAction.web_checkout).toBe('web_checkout');
118
+ });
119
+ });
120
+
121
+ describe('ThemeMode', () => {
122
+ it('should have correct theme mode values', () => {
123
+ expect(Purchasely.ThemeMode.light).toBe(0);
124
+ expect(Purchasely.ThemeMode.dark).toBe(1);
125
+ expect(Purchasely.ThemeMode.system).toBe(2);
126
+ });
127
+ });
128
+
129
+ describe('UserAttributeAction', () => {
130
+ it('should have correct user attribute action values', () => {
131
+ expect(Purchasely.UserAttributeAction.ADD).toBe('add');
132
+ expect(Purchasely.UserAttributeAction.REMOVE).toBe('remove');
133
+ });
134
+ });
135
+ });
136
+
137
+ describe('start', () => {
138
+ it('should call exec with correct parameters', () => {
139
+ const success = jest.fn();
140
+ const error = jest.fn();
141
+
142
+ Purchasely.start('API_KEY', ['GOOGLE'], false, 'user123', 1, 3, success, error);
143
+
144
+ expect(mockExec).toHaveBeenCalledWith(
145
+ success,
146
+ error,
147
+ 'Purchasely',
148
+ 'start',
149
+ ['API_KEY', ['GOOGLE'], false, 'user123', 1, 3, '5.6.2']
150
+ );
151
+ });
152
+ });
153
+
154
+ describe('addEventsListener', () => {
155
+ it('should call exec with correct parameters', () => {
156
+ const success = jest.fn();
157
+ const error = jest.fn();
158
+
159
+ Purchasely.addEventsListener(success, error);
160
+
161
+ expect(mockExec).toHaveBeenCalledWith(success, error, 'Purchasely', 'addEventsListener', []);
162
+ });
163
+ });
164
+
165
+ describe('addUserAttributeListener', () => {
166
+ it('should call exec with correct parameters', () => {
167
+ const success = jest.fn();
168
+ const error = jest.fn();
169
+
170
+ Purchasely.addUserAttributeListener(success, error);
171
+
172
+ expect(mockExec).toHaveBeenCalledWith(success, error, 'Purchasely', 'addUserAttributeListener', []);
173
+ });
174
+ });
175
+
176
+ describe('removeEventsListener', () => {
177
+ it('should call exec with correct parameters', () => {
178
+ Purchasely.removeEventsListener();
179
+
180
+ expect(mockExec).toHaveBeenCalledWith(
181
+ expect.any(Function),
182
+ expect.any(Function),
183
+ 'Purchasely',
184
+ 'removeEventsListener',
185
+ []
186
+ );
187
+ });
188
+ });
189
+
190
+ describe('removeUserAttributeListener', () => {
191
+ it('should call exec with correct parameters', () => {
192
+ Purchasely.removeUserAttributeListener();
193
+
194
+ expect(mockExec).toHaveBeenCalledWith(
195
+ expect.any(Function),
196
+ expect.any(Function),
197
+ 'Purchasely',
198
+ 'removeUserAttributeListener',
199
+ []
200
+ );
201
+ });
202
+ });
203
+
204
+ describe('getAnonymousUserId', () => {
205
+ it('should call exec with correct parameters', () => {
206
+ const success = jest.fn();
207
+ const error = jest.fn();
208
+
209
+ Purchasely.getAnonymousUserId(success, error);
210
+
211
+ expect(mockExec).toHaveBeenCalledWith(success, error, 'Purchasely', 'getAnonymousUserId', []);
212
+ });
213
+ });
214
+
215
+ describe('userLogin', () => {
216
+ it('should call exec with correct parameters', () => {
217
+ const success = jest.fn();
218
+
219
+ Purchasely.userLogin('user123', success);
220
+
221
+ expect(mockExec).toHaveBeenCalledWith(
222
+ success,
223
+ expect.any(Function),
224
+ 'Purchasely',
225
+ 'userLogin',
226
+ ['user123']
227
+ );
228
+ });
229
+ });
230
+
231
+ describe('userLogout', () => {
232
+ it('should call exec with correct parameters', () => {
233
+ Purchasely.userLogout();
234
+
235
+ expect(mockExec).toHaveBeenCalledWith(
236
+ expect.any(Function),
237
+ expect.any(Function),
238
+ 'Purchasely',
239
+ 'userLogout',
240
+ []
241
+ );
242
+ });
243
+ });
244
+
245
+ describe('setLogLevel', () => {
246
+ it('should call exec with correct parameters', () => {
247
+ Purchasely.setLogLevel(Purchasely.LogLevel.DEBUG);
248
+
249
+ expect(mockExec).toHaveBeenCalledWith(
250
+ expect.any(Function),
251
+ expect.any(Function),
252
+ 'Purchasely',
253
+ 'setLogLevel',
254
+ [0]
255
+ );
256
+ });
257
+ });
258
+
259
+ describe('setAttribute', () => {
260
+ it('should call exec with correct parameters', () => {
261
+ Purchasely.setAttribute(Purchasely.Attribute.FIREBASE_APP_INSTANCE_ID, 'firebase123');
262
+
263
+ expect(mockExec).toHaveBeenCalledWith(
264
+ expect.any(Function),
265
+ expect.any(Function),
266
+ 'Purchasely',
267
+ 'setAttribute',
268
+ [0, 'firebase123']
269
+ );
270
+ });
271
+ });
272
+
273
+ describe('readyToOpenDeeplink', () => {
274
+ it('should call exec with correct parameters', () => {
275
+ Purchasely.readyToOpenDeeplink(true);
276
+
277
+ expect(mockExec).toHaveBeenCalledWith(
278
+ expect.any(Function),
279
+ expect.any(Function),
280
+ 'Purchasely',
281
+ 'readyToOpenDeeplink',
282
+ [true]
283
+ );
284
+ });
285
+ });
286
+
287
+ describe('setDefaultPresentationResultHandler', () => {
288
+ it('should call exec with correct parameters', () => {
289
+ const success = jest.fn();
290
+ const error = jest.fn();
291
+
292
+ Purchasely.setDefaultPresentationResultHandler(success, error);
293
+
294
+ expect(mockExec).toHaveBeenCalledWith(success, error, 'Purchasely', 'setDefaultPresentationResultHandler', []);
295
+ });
296
+ });
297
+
298
+ describe('synchronize', () => {
299
+ it('should call exec with correct parameters', () => {
300
+ Purchasely.synchronize();
301
+
302
+ expect(mockExec).toHaveBeenCalledWith(
303
+ expect.any(Function),
304
+ expect.any(Function),
305
+ 'Purchasely',
306
+ 'synchronize',
307
+ []
308
+ );
309
+ });
310
+ });
311
+
312
+ describe('presentPresentationWithIdentifier', () => {
313
+ it('should call exec with correct parameters', () => {
314
+ const success = jest.fn();
315
+ const error = jest.fn();
316
+
317
+ Purchasely.presentPresentationWithIdentifier('presentation1', 'content1', true, success, error);
318
+
319
+ expect(mockExec).toHaveBeenCalledWith(
320
+ success,
321
+ error,
322
+ 'Purchasely',
323
+ 'presentPresentationWithIdentifier',
324
+ ['presentation1', 'content1', true]
325
+ );
326
+ });
327
+ });
328
+
329
+ describe('presentPresentationForPlacement', () => {
330
+ it('should call exec with correct parameters', () => {
331
+ const success = jest.fn();
332
+ const error = jest.fn();
333
+
334
+ Purchasely.presentPresentationForPlacement('placement1', 'content1', false, success, error);
335
+
336
+ expect(mockExec).toHaveBeenCalledWith(
337
+ success,
338
+ error,
339
+ 'Purchasely',
340
+ 'presentPresentationForPlacement',
341
+ ['placement1', 'content1', false]
342
+ );
343
+ });
344
+ });
345
+
346
+ describe('presentProductWithIdentifier', () => {
347
+ it('should call exec with correct parameters', () => {
348
+ const success = jest.fn();
349
+ const error = jest.fn();
350
+
351
+ Purchasely.presentProductWithIdentifier('product1', 'presentation1', 'content1', true, success, error);
352
+
353
+ expect(mockExec).toHaveBeenCalledWith(
354
+ success,
355
+ error,
356
+ 'Purchasely',
357
+ 'presentProductWithIdentifier',
358
+ ['product1', 'presentation1', 'content1', true]
359
+ );
360
+ });
361
+ });
362
+
363
+ describe('presentPlanWithIdentifier', () => {
364
+ it('should call exec with correct parameters', () => {
365
+ const success = jest.fn();
366
+ const error = jest.fn();
367
+
368
+ Purchasely.presentPlanWithIdentifier('plan1', 'presentation1', 'content1', false, success, error);
369
+
370
+ expect(mockExec).toHaveBeenCalledWith(
371
+ success,
372
+ error,
373
+ 'Purchasely',
374
+ 'presentPlanWithIdentifier',
375
+ ['plan1', 'presentation1', 'content1', false]
376
+ );
377
+ });
378
+ });
379
+
380
+ describe('fetchPresentation', () => {
381
+ it('should call exec with correct parameters', () => {
382
+ const success = jest.fn();
383
+ const error = jest.fn();
384
+
385
+ Purchasely.fetchPresentation('presentation1', 'content1', success, error);
386
+
387
+ expect(mockExec).toHaveBeenCalledWith(
388
+ success,
389
+ error,
390
+ 'Purchasely',
391
+ 'fetchPresentation',
392
+ [null, 'presentation1', 'content1']
393
+ );
394
+ });
395
+ });
396
+
397
+ describe('fetchPresentationForPlacement', () => {
398
+ it('should call exec with correct parameters', () => {
399
+ const success = jest.fn();
400
+ const error = jest.fn();
401
+
402
+ Purchasely.fetchPresentationForPlacement('placement1', 'content1', success, error);
403
+
404
+ expect(mockExec).toHaveBeenCalledWith(
405
+ success,
406
+ error,
407
+ 'Purchasely',
408
+ 'fetchPresentation',
409
+ ['placement1', null, 'content1']
410
+ );
411
+ });
412
+ });
413
+
414
+ describe('presentPresentation', () => {
415
+ it('should call exec with correct parameters', () => {
416
+ const success = jest.fn();
417
+ const error = jest.fn();
418
+ const presentation = { id: 'test' };
419
+
420
+ Purchasely.presentPresentation(presentation, true, '#FFFFFF', success, error);
421
+
422
+ expect(mockExec).toHaveBeenCalledWith(
423
+ success,
424
+ error,
425
+ 'Purchasely',
426
+ 'presentPresentation',
427
+ [presentation, true, '#FFFFFF']
428
+ );
429
+ });
430
+ });
431
+
432
+ describe('presentSubscriptions', () => {
433
+ it('should call exec with correct parameters', () => {
434
+ Purchasely.presentSubscriptions();
435
+
436
+ expect(mockExec).toHaveBeenCalledWith(
437
+ expect.any(Function),
438
+ expect.any(Function),
439
+ 'Purchasely',
440
+ 'presentSubscriptions',
441
+ []
442
+ );
443
+ });
444
+ });
445
+
446
+ describe('purchaseWithPlanVendorId', () => {
447
+ it('should call exec with correct parameters', () => {
448
+ const success = jest.fn();
449
+ const error = jest.fn();
450
+
451
+ Purchasely.purchaseWithPlanVendorId('plan1', 'offer1', 'content1', success, error);
452
+
453
+ expect(mockExec).toHaveBeenCalledWith(
454
+ success,
455
+ error,
456
+ 'Purchasely',
457
+ 'purchaseWithPlanVendorId',
458
+ ['plan1', 'offer1', 'content1']
459
+ );
460
+ });
461
+ });
462
+
463
+ describe('restoreAllProducts', () => {
464
+ it('should call exec with correct parameters', () => {
465
+ const success = jest.fn();
466
+ const error = jest.fn();
467
+
468
+ Purchasely.restoreAllProducts(success, error);
469
+
470
+ expect(mockExec).toHaveBeenCalledWith(success, error, 'Purchasely', 'restoreAllProducts', []);
471
+ });
472
+ });
473
+
474
+ describe('silentRestoreAllProducts', () => {
475
+ it('should call exec with correct parameters', () => {
476
+ const success = jest.fn();
477
+ const error = jest.fn();
478
+
479
+ Purchasely.silentRestoreAllProducts(success, error);
480
+
481
+ expect(mockExec).toHaveBeenCalledWith(success, error, 'Purchasely', 'silentRestoreAllProducts', []);
482
+ });
483
+ });
484
+
485
+ describe('purchasedSubscription', () => {
486
+ it('should call exec with correct parameters', () => {
487
+ const success = jest.fn();
488
+ const error = jest.fn();
489
+
490
+ Purchasely.purchasedSubscription(success, error);
491
+
492
+ expect(mockExec).toHaveBeenCalledWith(success, error, 'Purchasely', 'purchasedSubscription', []);
493
+ });
494
+ });
495
+
496
+ describe('isDeeplinkHandled', () => {
497
+ it('should call exec with correct parameters', () => {
498
+ const success = jest.fn();
499
+ const error = jest.fn();
500
+
501
+ Purchasely.isDeeplinkHandled('https://example.com/deeplink', success, error);
502
+
503
+ expect(mockExec).toHaveBeenCalledWith(
504
+ success,
505
+ error,
506
+ 'Purchasely',
507
+ 'isDeeplinkHandled',
508
+ ['https://example.com/deeplink']
509
+ );
510
+ });
511
+ });
512
+
513
+ describe('allProducts', () => {
514
+ it('should call exec with correct parameters', () => {
515
+ const success = jest.fn();
516
+ const error = jest.fn();
517
+
518
+ Purchasely.allProducts(success, error);
519
+
520
+ expect(mockExec).toHaveBeenCalledWith(
521
+ success,
522
+ expect.any(Function),
523
+ 'Purchasely',
524
+ 'allProducts',
525
+ []
526
+ );
527
+ });
528
+ });
529
+
530
+ describe('planWithIdentifier', () => {
531
+ it('should call exec with correct parameters', () => {
532
+ const success = jest.fn();
533
+
534
+ Purchasely.planWithIdentifier('plan1', success);
535
+
536
+ expect(mockExec).toHaveBeenCalledWith(
537
+ success,
538
+ expect.any(Function),
539
+ 'Purchasely',
540
+ 'planWithIdentifier',
541
+ ['plan1']
542
+ );
543
+ });
544
+ });
545
+
546
+ describe('productWithIdentifier', () => {
547
+ it('should call exec with correct parameters', () => {
548
+ const success = jest.fn();
549
+
550
+ Purchasely.productWithIdentifier('product1', success);
551
+
552
+ expect(mockExec).toHaveBeenCalledWith(
553
+ success,
554
+ expect.any(Function),
555
+ 'Purchasely',
556
+ 'productWithIdentifier',
557
+ ['product1']
558
+ );
559
+ });
560
+ });
561
+
562
+ describe('setPaywallActionInterceptor', () => {
563
+ it('should call exec with correct parameters', () => {
564
+ const success = jest.fn();
565
+
566
+ Purchasely.setPaywallActionInterceptor(success);
567
+
568
+ expect(mockExec).toHaveBeenCalledWith(
569
+ success,
570
+ expect.any(Function),
571
+ 'Purchasely',
572
+ 'setPaywallActionInterceptor',
573
+ []
574
+ );
575
+ });
576
+ });
577
+
578
+ describe('onProcessAction', () => {
579
+ it('should call exec with correct parameters', () => {
580
+ Purchasely.onProcessAction(true);
581
+
582
+ expect(mockExec).toHaveBeenCalledWith(
583
+ expect.any(Function),
584
+ expect.any(Function),
585
+ 'Purchasely',
586
+ 'onProcessAction',
587
+ [true]
588
+ );
589
+ });
590
+ });
591
+
592
+ describe('userDidConsumeSubscriptionContent', () => {
593
+ it('should call exec with correct parameters', () => {
594
+ Purchasely.userDidConsumeSubscriptionContent();
595
+
596
+ expect(mockExec).toHaveBeenCalledWith(
597
+ expect.any(Function),
598
+ expect.any(Function),
599
+ 'Purchasely',
600
+ 'userDidConsumeSubscriptionContent',
601
+ []
602
+ );
603
+ });
604
+ });
605
+
606
+ describe('userSubscriptions', () => {
607
+ it('should call exec with correct parameters', () => {
608
+ const success = jest.fn();
609
+ const error = jest.fn();
610
+
611
+ Purchasely.userSubscriptions(success, error);
612
+
613
+ expect(mockExec).toHaveBeenCalledWith(
614
+ success,
615
+ expect.any(Function),
616
+ 'Purchasely',
617
+ 'userSubscriptions',
618
+ []
619
+ );
620
+ });
621
+ });
622
+
623
+ describe('userSubscriptionsHistory', () => {
624
+ it('should call exec with correct parameters', () => {
625
+ const success = jest.fn();
626
+ const error = jest.fn();
627
+
628
+ Purchasely.userSubscriptionsHistory(success, error);
629
+
630
+ expect(mockExec).toHaveBeenCalledWith(
631
+ success,
632
+ expect.any(Function),
633
+ 'Purchasely',
634
+ 'userSubscriptionsHistory',
635
+ []
636
+ );
637
+ });
638
+ });
639
+
640
+ describe('setLanguage', () => {
641
+ it('should call exec with correct parameters', () => {
642
+ Purchasely.setLanguage('fr');
643
+
644
+ expect(mockExec).toHaveBeenCalledWith(
645
+ expect.any(Function),
646
+ expect.any(Function),
647
+ 'Purchasely',
648
+ 'setLanguage',
649
+ ['fr']
650
+ );
651
+ });
652
+ });
653
+
654
+ describe('showPresentation', () => {
655
+ it('should call exec with correct parameters', () => {
656
+ Purchasely.showPresentation();
657
+
658
+ expect(mockExec).toHaveBeenCalledWith(
659
+ expect.any(Function),
660
+ expect.any(Function),
661
+ 'Purchasely',
662
+ 'showPresentation',
663
+ []
664
+ );
665
+ });
666
+ });
667
+
668
+ describe('hidePresentation', () => {
669
+ it('should call exec with correct parameters', () => {
670
+ Purchasely.hidePresentation();
671
+
672
+ expect(mockExec).toHaveBeenCalledWith(
673
+ expect.any(Function),
674
+ expect.any(Function),
675
+ 'Purchasely',
676
+ 'hidePresentation',
677
+ []
678
+ );
679
+ });
680
+ });
681
+
682
+ describe('closePresentation', () => {
683
+ it('should call exec with correct parameters', () => {
684
+ Purchasely.closePresentation();
685
+
686
+ expect(mockExec).toHaveBeenCalledWith(
687
+ expect.any(Function),
688
+ expect.any(Function),
689
+ 'Purchasely',
690
+ 'closePresentation',
691
+ []
692
+ );
693
+ });
694
+ });
695
+
696
+ describe('User Attributes', () => {
697
+ describe('setUserAttributeWithString', () => {
698
+ it('should call exec with correct parameters', () => {
699
+ Purchasely.setUserAttributeWithString('name', 'John', 'ESSENTIAL');
700
+
701
+ expect(mockExec).toHaveBeenCalledWith(
702
+ expect.any(Function),
703
+ expect.any(Function),
704
+ 'Purchasely',
705
+ 'setUserAttributeWithString',
706
+ ['name', 'John', 'ESSENTIAL']
707
+ );
708
+ });
709
+ });
710
+
711
+ describe('setUserAttributeWithBoolean', () => {
712
+ it('should call exec with correct parameters', () => {
713
+ Purchasely.setUserAttributeWithBoolean('isPremium', true, 'OPTIONAL');
714
+
715
+ expect(mockExec).toHaveBeenCalledWith(
716
+ expect.any(Function),
717
+ expect.any(Function),
718
+ 'Purchasely',
719
+ 'setUserAttributeWithBoolean',
720
+ ['isPremium', true, 'OPTIONAL']
721
+ );
722
+ });
723
+ });
724
+
725
+ describe('setUserAttributeWithInt', () => {
726
+ it('should call exec with correct parameters', () => {
727
+ Purchasely.setUserAttributeWithInt('age', 25, 'ESSENTIAL');
728
+
729
+ expect(mockExec).toHaveBeenCalledWith(
730
+ expect.any(Function),
731
+ expect.any(Function),
732
+ 'Purchasely',
733
+ 'setUserAttributeWithInt',
734
+ ['age', 25, 'ESSENTIAL']
735
+ );
736
+ });
737
+ });
738
+
739
+ describe('setUserAttributeWithDouble', () => {
740
+ it('should call exec with correct parameters', () => {
741
+ Purchasely.setUserAttributeWithDouble('balance', 99.99, 'ESSENTIAL');
742
+
743
+ expect(mockExec).toHaveBeenCalledWith(
744
+ expect.any(Function),
745
+ expect.any(Function),
746
+ 'Purchasely',
747
+ 'setUserAttributeWithDouble',
748
+ ['balance', 99.99, 'ESSENTIAL']
749
+ );
750
+ });
751
+ });
752
+
753
+ describe('setUserAttributeWithDate', () => {
754
+ it('should call exec with correct parameters', () => {
755
+ Purchasely.setUserAttributeWithDate('birthdate', '1990-01-01', 'ESSENTIAL');
756
+
757
+ expect(mockExec).toHaveBeenCalledWith(
758
+ expect.any(Function),
759
+ expect.any(Function),
760
+ 'Purchasely',
761
+ 'setUserAttributeWithDate',
762
+ ['birthdate', '1990-01-01', 'ESSENTIAL']
763
+ );
764
+ });
765
+ });
766
+
767
+ describe('setUserAttributeWithStringArray', () => {
768
+ it('should call exec with correct parameters', () => {
769
+ Purchasely.setUserAttributeWithStringArray('tags', ['a', 'b'], 'ESSENTIAL');
770
+
771
+ expect(mockExec).toHaveBeenCalledWith(
772
+ expect.any(Function),
773
+ expect.any(Function),
774
+ 'Purchasely',
775
+ 'setUserAttributeWithStringArray',
776
+ ['tags', ['a', 'b'], 'ESSENTIAL']
777
+ );
778
+ });
779
+ });
780
+
781
+ describe('setUserAttributeWithIntArray', () => {
782
+ it('should call exec with correct parameters', () => {
783
+ Purchasely.setUserAttributeWithIntArray('scores', [1, 2, 3], 'ESSENTIAL');
784
+
785
+ expect(mockExec).toHaveBeenCalledWith(
786
+ expect.any(Function),
787
+ expect.any(Function),
788
+ 'Purchasely',
789
+ 'setUserAttributeWithIntArray',
790
+ ['scores', [1, 2, 3], 'ESSENTIAL']
791
+ );
792
+ });
793
+ });
794
+
795
+ describe('setUserAttributeWithDoubleArray', () => {
796
+ it('should call exec with correct parameters', () => {
797
+ Purchasely.setUserAttributeWithDoubleArray('prices', [1.1, 2.2], 'ESSENTIAL');
798
+
799
+ expect(mockExec).toHaveBeenCalledWith(
800
+ expect.any(Function),
801
+ expect.any(Function),
802
+ 'Purchasely',
803
+ 'setUserAttributeWithDoubleArray',
804
+ ['prices', [1.1, 2.2], 'ESSENTIAL']
805
+ );
806
+ });
807
+ });
808
+
809
+ describe('setUserAttributeWithBooleanArray', () => {
810
+ it('should call exec with correct parameters', () => {
811
+ Purchasely.setUserAttributeWithBooleanArray('flags', [true, false], 'ESSENTIAL');
812
+
813
+ expect(mockExec).toHaveBeenCalledWith(
814
+ expect.any(Function),
815
+ expect.any(Function),
816
+ 'Purchasely',
817
+ 'setUserAttributeWithBooleanArray',
818
+ ['flags', [true, false], 'ESSENTIAL']
819
+ );
820
+ });
821
+ });
822
+
823
+ describe('userAttribute', () => {
824
+ it('should call exec with correct parameters', () => {
825
+ const success = jest.fn();
826
+ const error = jest.fn();
827
+
828
+ Purchasely.userAttribute('name', success, error);
829
+
830
+ expect(mockExec).toHaveBeenCalledWith(success, error, 'Purchasely', 'userAttribute', ['name']);
831
+ });
832
+ });
833
+
834
+ describe('clearUserAttribute', () => {
835
+ it('should call exec with correct parameters', () => {
836
+ Purchasely.clearUserAttribute('name');
837
+
838
+ expect(mockExec).toHaveBeenCalledWith(
839
+ expect.any(Function),
840
+ expect.any(Function),
841
+ 'Purchasely',
842
+ 'clearUserAttribute',
843
+ ['name']
844
+ );
845
+ });
846
+ });
847
+
848
+ describe('clearUserAttributes', () => {
849
+ it('should call exec with correct parameters', () => {
850
+ Purchasely.clearUserAttributes();
851
+
852
+ expect(mockExec).toHaveBeenCalledWith(
853
+ expect.any(Function),
854
+ expect.any(Function),
855
+ 'Purchasely',
856
+ 'clearUserAttributes',
857
+ []
858
+ );
859
+ });
860
+ });
861
+
862
+ describe('clearBuiltInAttributes', () => {
863
+ it('should call exec with correct parameters', () => {
864
+ Purchasely.clearBuiltInAttributes();
865
+
866
+ expect(mockExec).toHaveBeenCalledWith(
867
+ expect.any(Function),
868
+ expect.any(Function),
869
+ 'Purchasely',
870
+ 'clearBuiltInAttributes',
871
+ []
872
+ );
873
+ });
874
+ });
875
+ });
876
+
877
+ describe('isEligibleForIntroOffer', () => {
878
+ it('should call exec with correct parameters', () => {
879
+ const success = jest.fn();
880
+ const error = jest.fn();
881
+
882
+ Purchasely.isEligibleForIntroOffer('plan1', success, error);
883
+
884
+ expect(mockExec).toHaveBeenCalledWith(success, error, 'Purchasely', 'isEligibleForIntroOffer', ['plan1']);
885
+ });
886
+ });
887
+
888
+ describe('signPromotionalOffer', () => {
889
+ it('should call exec with correct parameters', () => {
890
+ const success = jest.fn();
891
+ const error = jest.fn();
892
+
893
+ Purchasely.signPromotionalOffer('product1', 'offer1', success, error);
894
+
895
+ expect(mockExec).toHaveBeenCalledWith(
896
+ success,
897
+ error,
898
+ 'Purchasely',
899
+ 'signPromotionalOffer',
900
+ ['product1', 'offer1']
901
+ );
902
+ });
903
+ });
904
+
905
+ describe('setThemeMode', () => {
906
+ it('should call exec with correct parameters', () => {
907
+ Purchasely.setThemeMode(Purchasely.ThemeMode.dark);
908
+
909
+ expect(mockExec).toHaveBeenCalledWith(
910
+ expect.any(Function),
911
+ expect.any(Function),
912
+ 'Purchasely',
913
+ 'setThemeMode',
914
+ [1]
915
+ );
916
+ });
917
+ });
918
+
919
+ describe('revokeDataProcessingConsent', () => {
920
+ it('should call exec with correct parameters', () => {
921
+ Purchasely.revokeDataProcessingConsent(['ANALYTICS', 'CAMPAIGNS']);
922
+
923
+ expect(mockExec).toHaveBeenCalledWith(
924
+ expect.any(Function),
925
+ expect.any(Function),
926
+ 'Purchasely',
927
+ 'revokeDataProcessingConsent',
928
+ [['ANALYTICS', 'CAMPAIGNS']]
929
+ );
930
+ });
931
+ });
932
+
933
+ describe('setDebugMode', () => {
934
+ it('should call exec with correct parameters', () => {
935
+ Purchasely.setDebugMode(true);
936
+
937
+ expect(mockExec).toHaveBeenCalledWith(
938
+ expect.any(Function),
939
+ expect.any(Function),
940
+ 'Purchasely',
941
+ 'setDebugMode',
942
+ [true]
943
+ );
944
+ });
945
+ });
946
+ });
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "..": {
21
21
  "name": "@purchasely/cordova-plugin-purchasely",
22
- "version": "5.6.0",
22
+ "version": "5.6.2",
23
23
  "dev": true,
24
24
  "license": "ISC",
25
25
  "engines": {
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "../../purchasely-google": {
35
35
  "name": "@purchasely/cordova-plugin-purchasely-google",
36
- "version": "5.6.0",
36
+ "version": "5.6.2",
37
37
  "dev": true,
38
38
  "license": "ISC"
39
39
  },
@@ -30,4 +30,4 @@
30
30
  "android"
31
31
  ]
32
32
  }
33
- }
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purchasely/cordova-plugin-purchasely",
3
- "version": "5.6.0",
3
+ "version": "5.6.2",
4
4
  "description": "Purchasely is a solution to ease the integration and boost your In-App Purchases & Subscriptions on the App Store, Google Play Store, Amazon Appstore and Huawei App Gallery.",
5
5
  "cordova": {
6
6
  "id": "@purchasely/cordova-plugin-purchasely",
@@ -45,7 +45,10 @@
45
45
  "example": "example"
46
46
  },
47
47
  "scripts": {
48
- "test": "echo \"Error: no test specified\" && exit 1"
48
+ "test": "jest"
49
+ },
50
+ "devDependencies": {
51
+ "jest": "^29.7.0"
49
52
  },
50
53
  "repository": {
51
54
  "type": "git",
package/plugin.xml CHANGED
@@ -1,5 +1,5 @@
1
1
  <?xml version='1.0' encoding='utf-8'?>
2
- <plugin id="@purchasely/cordova-plugin-purchasely" version="5.6.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <plugin id="@purchasely/cordova-plugin-purchasely" version="5.6.2" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
3
3
  <name>Purchasely</name>
4
4
  <js-module name="Purchasely" src="www/Purchasely.js">
5
5
  <clobbers target="Purchasely" />
@@ -38,7 +38,7 @@
38
38
  <source url="https://github.com/CocoaPods/Specs.git"/>
39
39
  </config>
40
40
  <pods use-frameworks="true">
41
- <pod name="Purchasely" spec="5.6.0"/>
41
+ <pod name="Purchasely" spec="5.6.4"/>
42
42
  </pods>
43
43
  </podspec>
44
44
  </platform>
package/www/Purchasely.js CHANGED
@@ -5,7 +5,7 @@ var defaultError = (e) => { console.log(e); }
5
5
  exports.start = function (apiKey, stores, storekit1, userId, logLevel, runningMode, success, error) {
6
6
  var cordovaSdkVersion = cordova.define.moduleMap['cordova/plugin_list'].exports['metadata']['cordova-plugin-purchasely']
7
7
  if(!cordovaSdkVersion) {
8
- cordovaSdkVersion = "5.6.0";
8
+ cordovaSdkVersion = "5.6.2";
9
9
  }
10
10
  exec(success, error, 'Purchasely', 'start', [apiKey, stores, storekit1, userId, logLevel, runningMode, cordovaSdkVersion]);
11
11
  };