@stevenkellner/team-conduct-api 1.0.35 → 2.0.1
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.
- package/lib/src/firebase/FirebaseConfiguration.d.ts +45 -1
- package/lib/src/firebase/FirebaseConfiguration.js +44 -0
- package/lib/src/firebase/Firestore.d.ts +196 -0
- package/lib/src/firebase/Firestore.js +235 -0
- package/lib/src/{FirestoreScheme.d.ts → firebase/FirestoreScheme.d.ts} +15 -1
- package/lib/src/firebase/Messaging.d.ts +64 -0
- package/lib/src/firebase/checkAuthentication.d.ts +37 -0
- package/lib/src/{checkAuthentication.js → firebase/checkAuthentication.js} +26 -1
- package/lib/src/firebase/index.d.ts +4 -0
- package/lib/src/firebase/index.js +4 -0
- package/lib/src/firebase/pushNotification.d.ts +39 -0
- package/lib/src/firebase/pushNotification.js +88 -0
- package/lib/src/functions/fine/add.d.ts +10 -13
- package/lib/src/functions/fine/add.js +3 -30
- package/lib/src/functions/fine/delete.d.ts +10 -13
- package/lib/src/functions/fine/delete.js +3 -27
- package/lib/src/functions/fine/update.d.ts +10 -13
- package/lib/src/functions/fine/update.js +3 -28
- package/lib/src/functions/fineTemplate/add.d.ts +6 -9
- package/lib/src/functions/fineTemplate/add.js +3 -12
- package/lib/src/functions/fineTemplate/delete.d.ts +6 -9
- package/lib/src/functions/fineTemplate/delete.js +3 -12
- package/lib/src/functions/fineTemplate/update.d.ts +6 -9
- package/lib/src/functions/fineTemplate/update.js +3 -12
- package/lib/src/functions/invitation/getInvitation.d.ts +41 -42
- package/lib/src/functions/invitation/getInvitation.js +58 -81
- package/lib/src/functions/invitation/invite.d.ts +1 -2
- package/lib/src/functions/invitation/invite.js +3 -18
- package/lib/src/functions/invitation/register.d.ts +6 -11
- package/lib/src/functions/invitation/register.js +3 -39
- package/lib/src/functions/invitation/withdraw.d.ts +1 -2
- package/lib/src/functions/invitation/withdraw.js +3 -13
- package/lib/src/functions/notification/register.d.ts +7 -10
- package/lib/src/functions/notification/register.js +3 -15
- package/lib/src/functions/notification/subscribe.d.ts +8 -11
- package/lib/src/functions/notification/subscribe.js +3 -14
- package/lib/src/functions/paypalMe/edit.d.ts +6 -9
- package/lib/src/functions/paypalMe/edit.js +3 -14
- package/lib/src/functions/person/add.d.ts +7 -10
- package/lib/src/functions/person/add.js +3 -12
- package/lib/src/functions/person/delete.d.ts +6 -9
- package/lib/src/functions/person/delete.js +3 -14
- package/lib/src/functions/person/update.d.ts +7 -10
- package/lib/src/functions/person/update.js +3 -13
- package/lib/src/functions/team/new.d.ts +9 -12
- package/lib/src/functions/team/new.js +3 -22
- package/lib/src/functions/user/kickout.d.ts +6 -9
- package/lib/src/functions/user/kickout.js +3 -25
- package/lib/src/functions/user/login.d.ts +1 -2
- package/lib/src/functions/user/login.js +3 -13
- package/lib/src/functions/user/roleEdit.d.ts +8 -11
- package/lib/src/functions/user/roleEdit.js +3 -18
- package/lib/src/index.d.ts +0 -5
- package/lib/src/index.js +0 -5
- package/lib/src/locales/de.d.ts +10 -67
- package/lib/src/locales/de.js +8 -0
- package/lib/src/locales/en.d.ts +10 -0
- package/lib/src/locales/en.js +19 -2
- package/lib/src/types/Configuration.d.ts +33 -15
- package/lib/src/types/Configuration.js +24 -12
- package/lib/src/types/Currency.d.ts +20 -0
- package/lib/src/types/Currency.js +19 -0
- package/lib/src/types/Fine.d.ts +41 -0
- package/lib/src/types/Fine.js +32 -0
- package/lib/src/types/FineAmount.d.ts +160 -9
- package/lib/src/types/FineAmount.js +128 -7
- package/lib/src/types/FineTemplate.d.ts +41 -0
- package/lib/src/types/FineTemplate.js +32 -0
- package/lib/src/types/FineTemplateRepetition.d.ts +72 -10
- package/lib/src/types/FineTemplateRepetition.js +66 -12
- package/lib/src/types/Invitation.d.ts +48 -0
- package/lib/src/types/Invitation.js +39 -0
- package/lib/src/types/Locale.d.ts +16 -0
- package/lib/src/types/Locale.js +16 -0
- package/lib/src/types/Localization.d.ts +74 -74
- package/lib/src/types/Localization.js +80 -41
- package/lib/src/types/MoneyAmount.d.ts +67 -1
- package/lib/src/types/MoneyAmount.js +62 -0
- package/lib/src/types/NotificationProperties.d.ts +70 -9
- package/lib/src/types/NotificationProperties.js +49 -5
- package/lib/src/types/PayedState.d.ts +25 -9
- package/lib/src/types/PayedState.js +17 -27
- package/lib/src/types/Person.d.ts +45 -0
- package/lib/src/types/Person.js +36 -0
- package/lib/src/types/PersonPrivateProperties.d.ts +28 -0
- package/lib/src/types/PersonPrivateProperties.js +25 -0
- package/lib/src/types/PersonSignInProperties.d.ts +30 -0
- package/lib/src/types/PersonSignInProperties.js +27 -0
- package/lib/src/types/Pluralization.d.ts +46 -0
- package/lib/src/types/Pluralization.js +46 -0
- package/lib/src/types/Team.d.ts +38 -0
- package/lib/src/types/Team.js +29 -0
- package/lib/src/types/User.d.ts +68 -3
- package/lib/src/types/User.js +59 -5
- package/lib/src/types/UserRole.d.ts +26 -4
- package/lib/src/types/UserRole.js +25 -9
- package/lib/src/types/index.d.ts +2 -0
- package/lib/src/types/index.js +2 -0
- package/lib/test/firebase/FirebaseConfiguration.test.js +155 -0
- package/lib/test/firebase/Firestore.test.js +46 -0
- package/lib/test/firebase/checkAuthentication.test.d.ts +1 -0
- package/lib/test/firebase/checkAuthentication.test.js +305 -0
- package/lib/test/firebase/firebase-utils.d.ts +32 -0
- package/lib/test/firebase/firebase-utils.js +131 -0
- package/lib/test/firebase/pushNotification.test.d.ts +1 -0
- package/lib/test/firebase/pushNotification.test.js +300 -0
- package/lib/test/locales/localization.de.test.d.ts +1 -0
- package/lib/test/locales/localization.de.test.js +144 -0
- package/lib/test/locales/localization.en.test.d.ts +1 -0
- package/lib/test/locales/localization.en.test.js +144 -0
- package/lib/test/types/Configuration.test.d.ts +1 -0
- package/lib/test/types/Configuration.test.js +84 -0
- package/lib/test/types/Currency.test.d.ts +1 -0
- package/lib/test/types/Currency.test.js +41 -0
- package/lib/test/types/Fine.test.d.ts +1 -0
- package/lib/test/types/Fine.test.js +265 -0
- package/lib/test/types/FineAmount.test.d.ts +1 -0
- package/lib/test/types/FineAmount.test.js +445 -0
- package/lib/test/types/FineTemplate.test.d.ts +1 -0
- package/lib/test/types/FineTemplate.test.js +271 -0
- package/lib/test/types/FineTemplateRepetition.test.d.ts +1 -0
- package/lib/test/types/FineTemplateRepetition.test.js +361 -0
- package/lib/test/types/Invitation.test.d.ts +1 -0
- package/lib/test/types/Invitation.test.js +269 -0
- package/lib/test/types/Locale.test.d.ts +1 -0
- package/lib/test/types/Locale.test.js +46 -0
- package/lib/test/types/Localization.test.d.ts +1 -0
- package/lib/test/types/Localization.test.js +241 -0
- package/lib/test/types/MoneyAmount.test.d.ts +1 -0
- package/lib/test/types/MoneyAmount.test.js +276 -0
- package/lib/test/types/NotificationProperties.test.d.ts +1 -0
- package/lib/test/types/NotificationProperties.test.js +258 -0
- package/lib/test/types/PayedState.test.d.ts +1 -0
- package/lib/test/types/PayedState.test.js +105 -0
- package/lib/test/types/Person.test.d.ts +1 -0
- package/lib/test/types/Person.test.js +266 -0
- package/lib/test/types/PersonPrivateProperties.test.d.ts +1 -0
- package/lib/test/types/PersonPrivateProperties.test.js +155 -0
- package/lib/test/types/PersonSignInProperties.test.d.ts +1 -0
- package/lib/test/types/PersonSignInProperties.test.js +208 -0
- package/lib/test/types/Pluralization.test.d.ts +1 -0
- package/lib/test/types/Pluralization.test.js +206 -0
- package/lib/test/types/Team.test.d.ts +1 -0
- package/lib/test/types/Team.test.js +145 -0
- package/lib/test/types/User.test.d.ts +1 -0
- package/lib/test/types/User.test.js +232 -0
- package/lib/test/types/UserRole.test.d.ts +1 -0
- package/lib/test/types/UserRole.test.js +140 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -9
- package/src/firebase/FirebaseConfiguration.ts +49 -1
- package/src/firebase/Firestore.ts +248 -0
- package/src/{FirestoreScheme.ts → firebase/FirestoreScheme.ts} +15 -1
- package/src/firebase/Messaging.ts +64 -0
- package/src/{checkAuthentication.ts → firebase/checkAuthentication.ts} +39 -1
- package/src/firebase/index.ts +5 -0
- package/src/firebase/pushNotification.ts +90 -0
- package/src/functions/fine/add.ts +10 -48
- package/src/functions/fine/delete.ts +9 -43
- package/src/functions/fine/update.ts +10 -44
- package/src/functions/fineTemplate/add.ts +7 -23
- package/src/functions/fineTemplate/delete.ts +7 -23
- package/src/functions/fineTemplate/update.ts +7 -24
- package/src/functions/index.ts +0 -1
- package/src/functions/invitation/getInvitation.ts +83 -109
- package/src/functions/invitation/invite.ts +2 -25
- package/src/functions/invitation/register.ts +9 -60
- package/src/functions/invitation/withdraw.ts +2 -16
- package/src/functions/notification/register.ts +7 -26
- package/src/functions/notification/subscribe.ts +8 -26
- package/src/functions/paypalMe/edit.ts +7 -25
- package/src/functions/person/add.ts +8 -24
- package/src/functions/person/delete.ts +6 -25
- package/src/functions/person/update.ts +8 -25
- package/src/functions/team/new.ts +12 -42
- package/src/functions/user/kickout.ts +8 -41
- package/src/functions/user/login.ts +2 -16
- package/src/functions/user/roleEdit.ts +8 -32
- package/src/index.ts +0 -5
- package/src/locales/de.ts +10 -1
- package/src/locales/en.ts +21 -2
- package/src/types/Configuration.ts +33 -23
- package/src/types/Currency.ts +24 -0
- package/src/types/Fine.ts +41 -0
- package/src/types/FineAmount.ts +162 -11
- package/src/types/FineTemplate.ts +41 -0
- package/src/types/FineTemplateRepetition.ts +75 -17
- package/src/types/Invitation.ts +48 -0
- package/src/types/Locale.ts +20 -0
- package/src/types/Localization.ts +96 -41
- package/src/types/MoneyAmount.ts +67 -1
- package/src/types/NotificationProperties.ts +67 -9
- package/src/types/PayedState.ts +25 -30
- package/src/types/Person.ts +45 -0
- package/src/types/PersonPrivateProperties.ts +28 -1
- package/src/types/PersonSignInProperties.ts +30 -0
- package/src/types/Pluralization.ts +46 -0
- package/src/types/Team.ts +38 -0
- package/src/types/User.ts +70 -4
- package/src/types/UserRole.ts +32 -16
- package/src/types/index.ts +2 -0
- package/lib/src/Firestore.d.ts +0 -24
- package/lib/src/Firestore.js +0 -62
- package/lib/src/checkAuthentication.d.ts +0 -6
- package/lib/src/firebaseFunctionsContext.d.ts +0 -39
- package/lib/src/firebaseFunctionsContext.js +0 -43
- package/lib/src/pushNotification.d.ts +0 -3
- package/lib/src/pushNotification.js +0 -35
- package/lib/test/localization-utils.d.ts +0 -1
- package/lib/test/localization-utils.js +0 -24
- package/lib/test/localization.de.test.js +0 -151
- package/lib/test/localization.en.test.js +0 -145
- package/src/Firestore.ts +0 -75
- package/src/firebaseFunctionsContext.ts +0 -48
- package/src/pushNotification.ts +0 -37
- /package/lib/src/{FirestoreScheme.js → firebase/FirestoreScheme.js} +0 -0
- /package/lib/test/{localization.de.test.d.ts → firebase/FirebaseConfiguration.test.d.ts} +0 -0
- /package/lib/test/{localization.en.test.d.ts → firebase/Firestore.test.d.ts} +0 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@assertive-ts/core");
|
|
4
|
+
const MoneyAmount_1 = require("../../src/types/MoneyAmount");
|
|
5
|
+
const Configuration_1 = require("../../src/types/Configuration");
|
|
6
|
+
describe('MoneyAmount', () => {
|
|
7
|
+
describe('MoneyAmount constructor', () => {
|
|
8
|
+
it('should create a money amount with value and subunit', () => {
|
|
9
|
+
const amount = new MoneyAmount_1.MoneyAmount(10, 50);
|
|
10
|
+
(0, core_1.expect)(amount.value).toBeEqual(10);
|
|
11
|
+
(0, core_1.expect)(amount.subunitValue).toBeEqual(50);
|
|
12
|
+
});
|
|
13
|
+
it('should create a money amount with zero value', () => {
|
|
14
|
+
const amount = new MoneyAmount_1.MoneyAmount(0, 0);
|
|
15
|
+
(0, core_1.expect)(amount.value).toBeEqual(0);
|
|
16
|
+
(0, core_1.expect)(amount.subunitValue).toBeEqual(0);
|
|
17
|
+
});
|
|
18
|
+
it('should create a money amount with only subunit value', () => {
|
|
19
|
+
const amount = new MoneyAmount_1.MoneyAmount(0, 75);
|
|
20
|
+
(0, core_1.expect)(amount.value).toBeEqual(0);
|
|
21
|
+
(0, core_1.expect)(amount.subunitValue).toBeEqual(75);
|
|
22
|
+
});
|
|
23
|
+
it('should create a money amount with large values', () => {
|
|
24
|
+
const amount = new MoneyAmount_1.MoneyAmount(1000, 99);
|
|
25
|
+
(0, core_1.expect)(amount.value).toBeEqual(1000);
|
|
26
|
+
(0, core_1.expect)(amount.subunitValue).toBeEqual(99);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
describe('MoneyAmount.zero', () => {
|
|
30
|
+
it('should return a money amount with zero value', () => {
|
|
31
|
+
const zero = MoneyAmount_1.MoneyAmount.zero;
|
|
32
|
+
(0, core_1.expect)(zero.value).toBeEqual(0);
|
|
33
|
+
(0, core_1.expect)(zero.subunitValue).toBeEqual(0);
|
|
34
|
+
});
|
|
35
|
+
it('should return a new instance each time', () => {
|
|
36
|
+
const zero1 = MoneyAmount_1.MoneyAmount.zero;
|
|
37
|
+
const zero2 = MoneyAmount_1.MoneyAmount.zero;
|
|
38
|
+
(0, core_1.expect)(zero1.value).toBeEqual(zero2.value);
|
|
39
|
+
(0, core_1.expect)(zero1.subunitValue).toBeEqual(zero2.subunitValue);
|
|
40
|
+
});
|
|
41
|
+
it('should have complete value of zero', () => {
|
|
42
|
+
const zero = MoneyAmount_1.MoneyAmount.zero;
|
|
43
|
+
(0, core_1.expect)(zero.completeValue).toBeEqual(0);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
describe('MoneyAmount.added', () => {
|
|
47
|
+
it('should add two money amounts without carry', () => {
|
|
48
|
+
const amount1 = new MoneyAmount_1.MoneyAmount(10, 25);
|
|
49
|
+
const amount2 = new MoneyAmount_1.MoneyAmount(5, 30);
|
|
50
|
+
const result = amount1.added(amount2);
|
|
51
|
+
(0, core_1.expect)(result.value).toBeEqual(15);
|
|
52
|
+
(0, core_1.expect)(result.subunitValue).toBeEqual(55);
|
|
53
|
+
});
|
|
54
|
+
it('should add two money amounts with carry', () => {
|
|
55
|
+
const amount1 = new MoneyAmount_1.MoneyAmount(10, 60);
|
|
56
|
+
const amount2 = new MoneyAmount_1.MoneyAmount(5, 50);
|
|
57
|
+
const result = amount1.added(amount2);
|
|
58
|
+
(0, core_1.expect)(result.value).toBeEqual(16);
|
|
59
|
+
(0, core_1.expect)(result.subunitValue).toBeEqual(10);
|
|
60
|
+
});
|
|
61
|
+
it('should add zero to amount', () => {
|
|
62
|
+
const amount = new MoneyAmount_1.MoneyAmount(10, 50);
|
|
63
|
+
const result = amount.added(MoneyAmount_1.MoneyAmount.zero);
|
|
64
|
+
(0, core_1.expect)(result.value).toBeEqual(10);
|
|
65
|
+
(0, core_1.expect)(result.subunitValue).toBeEqual(50);
|
|
66
|
+
});
|
|
67
|
+
it('should handle multiple carries', () => {
|
|
68
|
+
const amount1 = new MoneyAmount_1.MoneyAmount(10, 99);
|
|
69
|
+
const amount2 = new MoneyAmount_1.MoneyAmount(5, 99);
|
|
70
|
+
const result = amount1.added(amount2);
|
|
71
|
+
(0, core_1.expect)(result.value).toBeEqual(16);
|
|
72
|
+
(0, core_1.expect)(result.subunitValue).toBeEqual(98);
|
|
73
|
+
});
|
|
74
|
+
it('should add amounts with only subunit values', () => {
|
|
75
|
+
const amount1 = new MoneyAmount_1.MoneyAmount(0, 40);
|
|
76
|
+
const amount2 = new MoneyAmount_1.MoneyAmount(0, 30);
|
|
77
|
+
const result = amount1.added(amount2);
|
|
78
|
+
(0, core_1.expect)(result.value).toBeEqual(0);
|
|
79
|
+
(0, core_1.expect)(result.subunitValue).toBeEqual(70);
|
|
80
|
+
});
|
|
81
|
+
it('should carry over from subunit addition', () => {
|
|
82
|
+
const amount1 = new MoneyAmount_1.MoneyAmount(0, 80);
|
|
83
|
+
const amount2 = new MoneyAmount_1.MoneyAmount(0, 50);
|
|
84
|
+
const result = amount1.added(amount2);
|
|
85
|
+
(0, core_1.expect)(result.value).toBeEqual(1);
|
|
86
|
+
(0, core_1.expect)(result.subunitValue).toBeEqual(30);
|
|
87
|
+
});
|
|
88
|
+
it('should not modify original amounts', () => {
|
|
89
|
+
const amount1 = new MoneyAmount_1.MoneyAmount(10, 50);
|
|
90
|
+
const amount2 = new MoneyAmount_1.MoneyAmount(5, 30);
|
|
91
|
+
amount1.added(amount2);
|
|
92
|
+
(0, core_1.expect)(amount1.value).toBeEqual(10);
|
|
93
|
+
(0, core_1.expect)(amount1.subunitValue).toBeEqual(50);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe('MoneyAmount.multiplied', () => {
|
|
97
|
+
it('should multiply money amount by integer', () => {
|
|
98
|
+
const amount = new MoneyAmount_1.MoneyAmount(10, 25);
|
|
99
|
+
const result = amount.multiplied(2);
|
|
100
|
+
(0, core_1.expect)(result.value).toBeEqual(20);
|
|
101
|
+
(0, core_1.expect)(result.subunitValue).toBeEqual(50);
|
|
102
|
+
});
|
|
103
|
+
it('should multiply with carry from subunit', () => {
|
|
104
|
+
const amount = new MoneyAmount_1.MoneyAmount(10, 60);
|
|
105
|
+
const result = amount.multiplied(2);
|
|
106
|
+
(0, core_1.expect)(result.value).toBeEqual(21);
|
|
107
|
+
(0, core_1.expect)(result.subunitValue).toBeEqual(20);
|
|
108
|
+
});
|
|
109
|
+
it('should multiply by zero', () => {
|
|
110
|
+
const amount = new MoneyAmount_1.MoneyAmount(10, 50);
|
|
111
|
+
const result = amount.multiplied(0);
|
|
112
|
+
(0, core_1.expect)(result.value).toBeEqual(0);
|
|
113
|
+
(0, core_1.expect)(result.subunitValue).toBeEqual(0);
|
|
114
|
+
});
|
|
115
|
+
it('should multiply by one', () => {
|
|
116
|
+
const amount = new MoneyAmount_1.MoneyAmount(10, 50);
|
|
117
|
+
const result = amount.multiplied(1);
|
|
118
|
+
(0, core_1.expect)(result.value).toBeEqual(10);
|
|
119
|
+
(0, core_1.expect)(result.subunitValue).toBeEqual(50);
|
|
120
|
+
});
|
|
121
|
+
it('should multiply by decimal factor', () => {
|
|
122
|
+
const amount = new MoneyAmount_1.MoneyAmount(10, 0);
|
|
123
|
+
const result = amount.multiplied(1.5);
|
|
124
|
+
(0, core_1.expect)(result.value).toBeEqual(15);
|
|
125
|
+
(0, core_1.expect)(result.subunitValue).toBeEqual(0);
|
|
126
|
+
});
|
|
127
|
+
it('should handle large multipliers', () => {
|
|
128
|
+
const amount = new MoneyAmount_1.MoneyAmount(5, 25);
|
|
129
|
+
const result = amount.multiplied(10);
|
|
130
|
+
(0, core_1.expect)(result.value).toBeEqual(52);
|
|
131
|
+
(0, core_1.expect)(result.subunitValue).toBeEqual(50);
|
|
132
|
+
});
|
|
133
|
+
it('should not modify original amount', () => {
|
|
134
|
+
const amount = new MoneyAmount_1.MoneyAmount(10, 50);
|
|
135
|
+
amount.multiplied(3);
|
|
136
|
+
(0, core_1.expect)(amount.value).toBeEqual(10);
|
|
137
|
+
(0, core_1.expect)(amount.subunitValue).toBeEqual(50);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
describe('MoneyAmount.formatted', () => {
|
|
141
|
+
it('should format money amount in USD with en locale', () => {
|
|
142
|
+
const amount = new MoneyAmount_1.MoneyAmount(10, 50);
|
|
143
|
+
const config = new Configuration_1.Configuration('USD', 'en');
|
|
144
|
+
const formatted = amount.formatted('USD', config);
|
|
145
|
+
(0, core_1.expect)(typeof formatted).toBeEqual('string');
|
|
146
|
+
(0, core_1.expect)(formatted.length).not.toBeEqual(0);
|
|
147
|
+
});
|
|
148
|
+
it('should format money amount in EUR with de locale', () => {
|
|
149
|
+
const amount = new MoneyAmount_1.MoneyAmount(10, 50);
|
|
150
|
+
const config = new Configuration_1.Configuration('EUR', 'de');
|
|
151
|
+
const formatted = amount.formatted('EUR', config);
|
|
152
|
+
(0, core_1.expect)(typeof formatted).toBeEqual('string');
|
|
153
|
+
(0, core_1.expect)(formatted.length).not.toBeEqual(0);
|
|
154
|
+
});
|
|
155
|
+
it('should format zero amount', () => {
|
|
156
|
+
const amount = MoneyAmount_1.MoneyAmount.zero;
|
|
157
|
+
const config = new Configuration_1.Configuration('USD', 'en');
|
|
158
|
+
const formatted = amount.formatted('USD', config);
|
|
159
|
+
(0, core_1.expect)(typeof formatted).toBeEqual('string');
|
|
160
|
+
(0, core_1.expect)(formatted.length).not.toBeEqual(0);
|
|
161
|
+
});
|
|
162
|
+
it('should format large amounts', () => {
|
|
163
|
+
const amount = new MoneyAmount_1.MoneyAmount(1000, 99);
|
|
164
|
+
const config = new Configuration_1.Configuration('USD', 'en');
|
|
165
|
+
const formatted = amount.formatted('USD', config);
|
|
166
|
+
(0, core_1.expect)(typeof formatted).toBeEqual('string');
|
|
167
|
+
(0, core_1.expect)(formatted.includes('1000') || formatted.includes('1,000')).toBeTrue();
|
|
168
|
+
});
|
|
169
|
+
it('should handle different currencies', () => {
|
|
170
|
+
const amount = new MoneyAmount_1.MoneyAmount(15, 75);
|
|
171
|
+
const usdConfig = new Configuration_1.Configuration('USD', 'en');
|
|
172
|
+
const eurConfig = new Configuration_1.Configuration('EUR', 'de');
|
|
173
|
+
const usdFormatted = amount.formatted('USD', usdConfig);
|
|
174
|
+
const eurFormatted = amount.formatted('EUR', eurConfig);
|
|
175
|
+
(0, core_1.expect)(usdFormatted).not.toBeEqual(eurFormatted);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
describe('MoneyAmount.completeValue', () => {
|
|
179
|
+
it('should return complete value as decimal', () => {
|
|
180
|
+
const amount = new MoneyAmount_1.MoneyAmount(10, 50);
|
|
181
|
+
(0, core_1.expect)(amount.completeValue).toBeEqual(10.5);
|
|
182
|
+
});
|
|
183
|
+
it('should return zero for zero amount', () => {
|
|
184
|
+
const amount = MoneyAmount_1.MoneyAmount.zero;
|
|
185
|
+
(0, core_1.expect)(amount.completeValue).toBeEqual(0);
|
|
186
|
+
});
|
|
187
|
+
it('should handle only subunit values', () => {
|
|
188
|
+
const amount = new MoneyAmount_1.MoneyAmount(0, 75);
|
|
189
|
+
(0, core_1.expect)(amount.completeValue).toBeEqual(0.75);
|
|
190
|
+
});
|
|
191
|
+
it('should handle whole numbers', () => {
|
|
192
|
+
const amount = new MoneyAmount_1.MoneyAmount(15, 0);
|
|
193
|
+
(0, core_1.expect)(amount.completeValue).toBeEqual(15);
|
|
194
|
+
});
|
|
195
|
+
it('should handle 99 subunits', () => {
|
|
196
|
+
const amount = new MoneyAmount_1.MoneyAmount(10, 99);
|
|
197
|
+
(0, core_1.expect)(amount.completeValue).toBeEqual(10.99);
|
|
198
|
+
});
|
|
199
|
+
it('should handle single digit subunits', () => {
|
|
200
|
+
const amount = new MoneyAmount_1.MoneyAmount(10, 5);
|
|
201
|
+
(0, core_1.expect)(amount.completeValue).toBeEqual(10.05);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
describe('MoneyAmount.flatten', () => {
|
|
205
|
+
it('should return flattened value as decimal', () => {
|
|
206
|
+
const amount = new MoneyAmount_1.MoneyAmount(10, 50);
|
|
207
|
+
(0, core_1.expect)(amount.flatten).toBeEqual(10.5);
|
|
208
|
+
});
|
|
209
|
+
it('should flatten zero amount', () => {
|
|
210
|
+
const amount = MoneyAmount_1.MoneyAmount.zero;
|
|
211
|
+
(0, core_1.expect)(amount.flatten).toBeEqual(0);
|
|
212
|
+
});
|
|
213
|
+
it('should flatten amount with only subunits', () => {
|
|
214
|
+
const amount = new MoneyAmount_1.MoneyAmount(0, 99);
|
|
215
|
+
(0, core_1.expect)(amount.flatten).toBeEqual(0.99);
|
|
216
|
+
});
|
|
217
|
+
it('should match completeValue', () => {
|
|
218
|
+
const amount = new MoneyAmount_1.MoneyAmount(15, 75);
|
|
219
|
+
(0, core_1.expect)(amount.flatten).toBeEqual(amount.completeValue);
|
|
220
|
+
});
|
|
221
|
+
it('should return number type', () => {
|
|
222
|
+
const amount = new MoneyAmount_1.MoneyAmount(10, 50);
|
|
223
|
+
(0, core_1.expect)(typeof amount.flatten).toBeEqual('number');
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
describe('MoneyAmount.TypeBuilder', () => {
|
|
227
|
+
it('should build money amount from decimal value', () => {
|
|
228
|
+
const amount = MoneyAmount_1.MoneyAmount.builder.build(10.5);
|
|
229
|
+
(0, core_1.expect)(amount.value).toBeEqual(10);
|
|
230
|
+
(0, core_1.expect)(amount.subunitValue).toBeEqual(50);
|
|
231
|
+
});
|
|
232
|
+
it('should build money amount from zero', () => {
|
|
233
|
+
const amount = MoneyAmount_1.MoneyAmount.builder.build(0);
|
|
234
|
+
(0, core_1.expect)(amount.value).toBeEqual(0);
|
|
235
|
+
(0, core_1.expect)(amount.subunitValue).toBeEqual(0);
|
|
236
|
+
});
|
|
237
|
+
it('should build money amount from whole number', () => {
|
|
238
|
+
const amount = MoneyAmount_1.MoneyAmount.builder.build(15);
|
|
239
|
+
(0, core_1.expect)(amount.value).toBeEqual(15);
|
|
240
|
+
(0, core_1.expect)(amount.subunitValue).toBeEqual(0);
|
|
241
|
+
});
|
|
242
|
+
it('should build money amount from small decimal', () => {
|
|
243
|
+
const amount = MoneyAmount_1.MoneyAmount.builder.build(0.75);
|
|
244
|
+
(0, core_1.expect)(amount.value).toBeEqual(0);
|
|
245
|
+
(0, core_1.expect)(amount.subunitValue).toBeEqual(75);
|
|
246
|
+
});
|
|
247
|
+
it('should build money amount with 99 subunits', () => {
|
|
248
|
+
const amount = MoneyAmount_1.MoneyAmount.builder.build(10.99);
|
|
249
|
+
(0, core_1.expect)(amount.value).toBeEqual(10);
|
|
250
|
+
(0, core_1.expect)(amount.subunitValue).toBeEqual(99);
|
|
251
|
+
});
|
|
252
|
+
it('should round subunit values properly', () => {
|
|
253
|
+
const amount = MoneyAmount_1.MoneyAmount.builder.build(10.555);
|
|
254
|
+
(0, core_1.expect)(amount.value).toBeEqual(10);
|
|
255
|
+
(0, core_1.expect)(amount.subunitValue).toBeEqual(55);
|
|
256
|
+
});
|
|
257
|
+
it('should round-trip through flatten and build', () => {
|
|
258
|
+
const original = new MoneyAmount_1.MoneyAmount(15, 75);
|
|
259
|
+
const rebuilt = MoneyAmount_1.MoneyAmount.builder.build(original.flatten);
|
|
260
|
+
(0, core_1.expect)(rebuilt.value).toBeEqual(original.value);
|
|
261
|
+
(0, core_1.expect)(rebuilt.subunitValue).toBeEqual(original.subunitValue);
|
|
262
|
+
});
|
|
263
|
+
it('should round-trip with zero', () => {
|
|
264
|
+
const original = MoneyAmount_1.MoneyAmount.zero;
|
|
265
|
+
const rebuilt = MoneyAmount_1.MoneyAmount.builder.build(original.flatten);
|
|
266
|
+
(0, core_1.expect)(rebuilt.value).toBeEqual(0);
|
|
267
|
+
(0, core_1.expect)(rebuilt.subunitValue).toBeEqual(0);
|
|
268
|
+
});
|
|
269
|
+
it('should round-trip with large values', () => {
|
|
270
|
+
const original = new MoneyAmount_1.MoneyAmount(1000, 99);
|
|
271
|
+
const rebuilt = MoneyAmount_1.MoneyAmount.builder.build(original.flatten);
|
|
272
|
+
(0, core_1.expect)(rebuilt.value).toBeEqual(1000);
|
|
273
|
+
(0, core_1.expect)(rebuilt.subunitValue).toBeEqual(99);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@assertive-ts/core");
|
|
4
|
+
const NotificationProperties_1 = require("../../src/types/NotificationProperties");
|
|
5
|
+
const typescript_common_functionality_1 = require("@stevenkellner/typescript-common-functionality");
|
|
6
|
+
describe('NotificationProperties', () => {
|
|
7
|
+
describe('NotificationProperties.TokenId', () => {
|
|
8
|
+
describe('NotificationProperties.TokenId.create', () => {
|
|
9
|
+
it('should create a token ID from a device token', () => {
|
|
10
|
+
const token = 'device-token-12345';
|
|
11
|
+
const tokenId = NotificationProperties_1.NotificationProperties.TokenId.create(token);
|
|
12
|
+
(0, core_1.expect)(tokenId).not.toBeUndefined();
|
|
13
|
+
(0, core_1.expect)(tokenId.flatten.length).toBeEqual(16);
|
|
14
|
+
});
|
|
15
|
+
it('should create different token IDs for different tokens', () => {
|
|
16
|
+
const token1 = 'device-token-abc';
|
|
17
|
+
const token2 = 'device-token-xyz';
|
|
18
|
+
const tokenId1 = NotificationProperties_1.NotificationProperties.TokenId.create(token1);
|
|
19
|
+
const tokenId2 = NotificationProperties_1.NotificationProperties.TokenId.create(token2);
|
|
20
|
+
(0, core_1.expect)(tokenId1.flatten).not.toBeEqual(tokenId2.flatten);
|
|
21
|
+
});
|
|
22
|
+
it('should create consistent token IDs for the same token', () => {
|
|
23
|
+
const token = 'consistent-token';
|
|
24
|
+
const tokenId1 = NotificationProperties_1.NotificationProperties.TokenId.create(token);
|
|
25
|
+
const tokenId2 = NotificationProperties_1.NotificationProperties.TokenId.create(token);
|
|
26
|
+
(0, core_1.expect)(tokenId1.flatten).toBeEqual(tokenId2.flatten);
|
|
27
|
+
});
|
|
28
|
+
it('should create token IDs with hexadecimal characters', () => {
|
|
29
|
+
const token = 'test-token';
|
|
30
|
+
const tokenId = NotificationProperties_1.NotificationProperties.TokenId.create(token);
|
|
31
|
+
(0, core_1.expect)(tokenId.flatten).toMatchRegex(/^[0-9a-f]{16}$/);
|
|
32
|
+
});
|
|
33
|
+
it('should handle empty token string', () => {
|
|
34
|
+
const token = '';
|
|
35
|
+
const tokenId = NotificationProperties_1.NotificationProperties.TokenId.create(token);
|
|
36
|
+
(0, core_1.expect)(tokenId.flatten.length).toBeEqual(16);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
describe('NotificationProperties.TokenId.builder', () => {
|
|
40
|
+
it('should build token ID from string', () => {
|
|
41
|
+
const tokenIdString = '0123456789abcdef';
|
|
42
|
+
const tokenId = NotificationProperties_1.NotificationProperties.TokenId.builder.build(tokenIdString);
|
|
43
|
+
(0, core_1.expect)(tokenId.flatten).toBeEqual(tokenIdString);
|
|
44
|
+
});
|
|
45
|
+
it('should preserve token ID value', () => {
|
|
46
|
+
const tokenIdString = 'fedcba9876543210';
|
|
47
|
+
const tokenId = NotificationProperties_1.NotificationProperties.TokenId.builder.build(tokenIdString);
|
|
48
|
+
(0, core_1.expect)(tokenId.flatten).toBeEqual(tokenIdString);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
describe('NotificationProperties.Subscription', () => {
|
|
53
|
+
describe('NotificationProperties.Subscription type', () => {
|
|
54
|
+
it('should be valid subscription types', () => {
|
|
55
|
+
const sub1 = 'new-fine';
|
|
56
|
+
const sub2 = 'fine-reminder';
|
|
57
|
+
const sub3 = 'fine-state-change';
|
|
58
|
+
(0, core_1.expect)(sub1).toBeEqual('new-fine');
|
|
59
|
+
(0, core_1.expect)(sub2).toBeEqual('fine-reminder');
|
|
60
|
+
(0, core_1.expect)(sub3).toBeEqual('fine-state-change');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe('NotificationProperties.Subscription.all', () => {
|
|
64
|
+
it('should contain all subscription types', () => {
|
|
65
|
+
(0, core_1.expect)(NotificationProperties_1.NotificationProperties.Subscription.all.length).toBeEqual(3);
|
|
66
|
+
});
|
|
67
|
+
it('should contain new-fine subscription', () => {
|
|
68
|
+
(0, core_1.expect)(NotificationProperties_1.NotificationProperties.Subscription.all.includes('new-fine')).toBeTrue();
|
|
69
|
+
});
|
|
70
|
+
it('should contain fine-reminder subscription', () => {
|
|
71
|
+
(0, core_1.expect)(NotificationProperties_1.NotificationProperties.Subscription.all.includes('fine-reminder')).toBeTrue();
|
|
72
|
+
});
|
|
73
|
+
it('should contain fine-state-change subscription', () => {
|
|
74
|
+
(0, core_1.expect)(NotificationProperties_1.NotificationProperties.Subscription.all.includes('fine-state-change')).toBeTrue();
|
|
75
|
+
});
|
|
76
|
+
it('should contain only valid subscription strings', () => {
|
|
77
|
+
NotificationProperties_1.NotificationProperties.Subscription.all.forEach(subscription => {
|
|
78
|
+
(0, core_1.expect)(typeof subscription).toBeEqual('string');
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe('NotificationProperties.Subscription.builder', () => {
|
|
83
|
+
it('should build valid subscription from string', () => {
|
|
84
|
+
const subscription = NotificationProperties_1.NotificationProperties.Subscription.builder.build('new-fine');
|
|
85
|
+
(0, core_1.expect)(subscription).toBeEqual('new-fine');
|
|
86
|
+
});
|
|
87
|
+
it('should preserve subscription value', () => {
|
|
88
|
+
const subscription = NotificationProperties_1.NotificationProperties.Subscription.builder.build('fine-reminder');
|
|
89
|
+
(0, core_1.expect)(subscription).toBeEqual('fine-reminder');
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
describe('NotificationProperties', () => {
|
|
94
|
+
describe('NotificationProperties constructor', () => {
|
|
95
|
+
it('should create notification properties with empty tokens and subscriptions', () => {
|
|
96
|
+
const props = new NotificationProperties_1.NotificationProperties();
|
|
97
|
+
(0, core_1.expect)(props.tokens.values.length).toBeEqual(0);
|
|
98
|
+
(0, core_1.expect)(props.subscriptions.length).toBeEqual(0);
|
|
99
|
+
});
|
|
100
|
+
it('should create notification properties with tokens', () => {
|
|
101
|
+
const tokens = new typescript_common_functionality_1.Dictionary(NotificationProperties_1.NotificationProperties.TokenId.builder);
|
|
102
|
+
const tokenId = NotificationProperties_1.NotificationProperties.TokenId.create('test-token');
|
|
103
|
+
tokens.set(tokenId, 'test-token');
|
|
104
|
+
const props = new NotificationProperties_1.NotificationProperties(tokens);
|
|
105
|
+
(0, core_1.expect)(props.tokens.values.length).toBeEqual(1);
|
|
106
|
+
(0, core_1.expect)(props.tokens.get(tokenId)).toBeEqual('test-token');
|
|
107
|
+
});
|
|
108
|
+
it('should create notification properties with subscriptions', () => {
|
|
109
|
+
const subscriptions = ['new-fine', 'fine-reminder'];
|
|
110
|
+
const props = new NotificationProperties_1.NotificationProperties(new typescript_common_functionality_1.Dictionary(NotificationProperties_1.NotificationProperties.TokenId.builder), subscriptions);
|
|
111
|
+
(0, core_1.expect)(props.subscriptions.length).toBeEqual(2);
|
|
112
|
+
(0, core_1.expect)(props.subscriptions[0]).toBeEqual('new-fine');
|
|
113
|
+
(0, core_1.expect)(props.subscriptions[1]).toBeEqual('fine-reminder');
|
|
114
|
+
});
|
|
115
|
+
it('should create notification properties with both tokens and subscriptions', () => {
|
|
116
|
+
const tokens = new typescript_common_functionality_1.Dictionary(NotificationProperties_1.NotificationProperties.TokenId.builder);
|
|
117
|
+
const tokenId = NotificationProperties_1.NotificationProperties.TokenId.create('device-token');
|
|
118
|
+
tokens.set(tokenId, 'device-token');
|
|
119
|
+
const subscriptions = ['new-fine'];
|
|
120
|
+
const props = new NotificationProperties_1.NotificationProperties(tokens, subscriptions);
|
|
121
|
+
(0, core_1.expect)(props.tokens.values.length).toBeEqual(1);
|
|
122
|
+
(0, core_1.expect)(props.subscriptions.length).toBeEqual(1);
|
|
123
|
+
});
|
|
124
|
+
it('should create notification properties with multiple tokens', () => {
|
|
125
|
+
const tokens = new typescript_common_functionality_1.Dictionary(NotificationProperties_1.NotificationProperties.TokenId.builder);
|
|
126
|
+
const tokenId1 = NotificationProperties_1.NotificationProperties.TokenId.create('token-1');
|
|
127
|
+
const tokenId2 = NotificationProperties_1.NotificationProperties.TokenId.create('token-2');
|
|
128
|
+
tokens.set(tokenId1, 'token-1');
|
|
129
|
+
tokens.set(tokenId2, 'token-2');
|
|
130
|
+
const props = new NotificationProperties_1.NotificationProperties(tokens);
|
|
131
|
+
(0, core_1.expect)(props.tokens.values.length).toBeEqual(2);
|
|
132
|
+
});
|
|
133
|
+
it('should create notification properties with all subscription types', () => {
|
|
134
|
+
const subscriptions = ['new-fine', 'fine-reminder', 'fine-state-change'];
|
|
135
|
+
const props = new NotificationProperties_1.NotificationProperties(new typescript_common_functionality_1.Dictionary(NotificationProperties_1.NotificationProperties.TokenId.builder), subscriptions);
|
|
136
|
+
(0, core_1.expect)(props.subscriptions.length).toBeEqual(3);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
describe('NotificationProperties.flatten', () => {
|
|
140
|
+
it('should return flattened representation with empty tokens and subscriptions', () => {
|
|
141
|
+
const props = new NotificationProperties_1.NotificationProperties();
|
|
142
|
+
const flattened = props.flatten;
|
|
143
|
+
(0, core_1.expect)(Object.keys(flattened.tokens)).toBeEqual([]);
|
|
144
|
+
(0, core_1.expect)(flattened.subscriptions.length).toBeEqual(0);
|
|
145
|
+
});
|
|
146
|
+
it('should return flattened representation with tokens', () => {
|
|
147
|
+
const tokens = new typescript_common_functionality_1.Dictionary(NotificationProperties_1.NotificationProperties.TokenId.builder);
|
|
148
|
+
const tokenId = NotificationProperties_1.NotificationProperties.TokenId.create('flatten-token');
|
|
149
|
+
tokens.set(tokenId, 'flatten-token');
|
|
150
|
+
const props = new NotificationProperties_1.NotificationProperties(tokens);
|
|
151
|
+
const flattened = props.flatten;
|
|
152
|
+
(0, core_1.expect)(flattened.tokens[tokenId.flatten]).toBeEqual('flatten-token');
|
|
153
|
+
});
|
|
154
|
+
it('should return flattened representation with subscriptions', () => {
|
|
155
|
+
const subscriptions = ['new-fine', 'fine-state-change'];
|
|
156
|
+
const props = new NotificationProperties_1.NotificationProperties(new typescript_common_functionality_1.Dictionary(NotificationProperties_1.NotificationProperties.TokenId.builder), subscriptions);
|
|
157
|
+
const flattened = props.flatten;
|
|
158
|
+
(0, core_1.expect)(flattened.subscriptions.length).toBeEqual(2);
|
|
159
|
+
(0, core_1.expect)(flattened.subscriptions[0]).toBeEqual('new-fine');
|
|
160
|
+
(0, core_1.expect)(flattened.subscriptions[1]).toBeEqual('fine-state-change');
|
|
161
|
+
});
|
|
162
|
+
it('should match the original values', () => {
|
|
163
|
+
const tokens = new typescript_common_functionality_1.Dictionary(NotificationProperties_1.NotificationProperties.TokenId.builder);
|
|
164
|
+
const tokenId = NotificationProperties_1.NotificationProperties.TokenId.create('match-token');
|
|
165
|
+
tokens.set(tokenId, 'match-token');
|
|
166
|
+
const subscriptions = ['fine-reminder'];
|
|
167
|
+
const props = new NotificationProperties_1.NotificationProperties(tokens, subscriptions);
|
|
168
|
+
const flattened = props.flatten;
|
|
169
|
+
(0, core_1.expect)(flattened.subscriptions).toBeEqual(subscriptions);
|
|
170
|
+
});
|
|
171
|
+
it('should have correct structure', () => {
|
|
172
|
+
const props = new NotificationProperties_1.NotificationProperties();
|
|
173
|
+
const flattened = props.flatten;
|
|
174
|
+
(0, core_1.expect)(typeof flattened.tokens).toBeEqual('object');
|
|
175
|
+
(0, core_1.expect)(Array.isArray(flattened.subscriptions)).toBeTrue();
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
describe('NotificationProperties.TypeBuilder', () => {
|
|
179
|
+
it('should build notification properties from flattened data with empty values', () => {
|
|
180
|
+
const flattened = {
|
|
181
|
+
tokens: {},
|
|
182
|
+
subscriptions: []
|
|
183
|
+
};
|
|
184
|
+
const props = NotificationProperties_1.NotificationProperties.builder.build(flattened);
|
|
185
|
+
(0, core_1.expect)(props.tokens.values.length).toBeEqual(0);
|
|
186
|
+
(0, core_1.expect)(props.subscriptions.length).toBeEqual(0);
|
|
187
|
+
});
|
|
188
|
+
it('should build notification properties from flattened data with tokens', () => {
|
|
189
|
+
const tokenId = NotificationProperties_1.NotificationProperties.TokenId.create('build-token');
|
|
190
|
+
const flattened = {
|
|
191
|
+
tokens: {
|
|
192
|
+
[tokenId.flatten]: 'build-token'
|
|
193
|
+
},
|
|
194
|
+
subscriptions: []
|
|
195
|
+
};
|
|
196
|
+
const props = NotificationProperties_1.NotificationProperties.builder.build(flattened);
|
|
197
|
+
(0, core_1.expect)(props.tokens.values.length).toBeEqual(1);
|
|
198
|
+
(0, core_1.expect)(props.tokens.get(tokenId)).toBeEqual('build-token');
|
|
199
|
+
});
|
|
200
|
+
it('should build notification properties from flattened data with subscriptions', () => {
|
|
201
|
+
const flattened = {
|
|
202
|
+
tokens: {},
|
|
203
|
+
subscriptions: ['new-fine', 'fine-reminder']
|
|
204
|
+
};
|
|
205
|
+
const props = NotificationProperties_1.NotificationProperties.builder.build(flattened);
|
|
206
|
+
(0, core_1.expect)(props.subscriptions.length).toBeEqual(2);
|
|
207
|
+
(0, core_1.expect)(props.subscriptions[0]).toBeEqual('new-fine');
|
|
208
|
+
});
|
|
209
|
+
it('should build notification properties from flattened data with both', () => {
|
|
210
|
+
const tokenId = NotificationProperties_1.NotificationProperties.TokenId.create('both-token');
|
|
211
|
+
const flattened = {
|
|
212
|
+
tokens: {
|
|
213
|
+
[tokenId.flatten]: 'both-token'
|
|
214
|
+
},
|
|
215
|
+
subscriptions: ['fine-state-change']
|
|
216
|
+
};
|
|
217
|
+
const props = NotificationProperties_1.NotificationProperties.builder.build(flattened);
|
|
218
|
+
(0, core_1.expect)(props.tokens.values.length).toBeEqual(1);
|
|
219
|
+
(0, core_1.expect)(props.subscriptions.length).toBeEqual(1);
|
|
220
|
+
});
|
|
221
|
+
it('should round-trip through flatten and build with empty values', () => {
|
|
222
|
+
const original = new NotificationProperties_1.NotificationProperties();
|
|
223
|
+
const rebuilt = NotificationProperties_1.NotificationProperties.builder.build(original.flatten);
|
|
224
|
+
(0, core_1.expect)(rebuilt.tokens.values.length).toBeEqual(original.tokens.values.length);
|
|
225
|
+
(0, core_1.expect)(rebuilt.subscriptions.length).toBeEqual(original.subscriptions.length);
|
|
226
|
+
});
|
|
227
|
+
it('should round-trip through flatten and build with tokens', () => {
|
|
228
|
+
const tokens = new typescript_common_functionality_1.Dictionary(NotificationProperties_1.NotificationProperties.TokenId.builder);
|
|
229
|
+
const tokenId = NotificationProperties_1.NotificationProperties.TokenId.create('round-trip-token');
|
|
230
|
+
tokens.set(tokenId, 'round-trip-token');
|
|
231
|
+
const original = new NotificationProperties_1.NotificationProperties(tokens);
|
|
232
|
+
const rebuilt = NotificationProperties_1.NotificationProperties.builder.build(original.flatten);
|
|
233
|
+
(0, core_1.expect)(rebuilt.tokens.values.length).toBeEqual(1);
|
|
234
|
+
(0, core_1.expect)(rebuilt.tokens.get(tokenId)).toBeEqual('round-trip-token');
|
|
235
|
+
});
|
|
236
|
+
it('should round-trip through flatten and build with subscriptions', () => {
|
|
237
|
+
const subscriptions = ['new-fine', 'fine-reminder', 'fine-state-change'];
|
|
238
|
+
const original = new NotificationProperties_1.NotificationProperties(new typescript_common_functionality_1.Dictionary(NotificationProperties_1.NotificationProperties.TokenId.builder), subscriptions);
|
|
239
|
+
const rebuilt = NotificationProperties_1.NotificationProperties.builder.build(original.flatten);
|
|
240
|
+
(0, core_1.expect)(rebuilt.subscriptions.length).toBeEqual(3);
|
|
241
|
+
(0, core_1.expect)(rebuilt.subscriptions).toBeEqual(subscriptions);
|
|
242
|
+
});
|
|
243
|
+
it('should build with multiple tokens', () => {
|
|
244
|
+
const tokenId1 = NotificationProperties_1.NotificationProperties.TokenId.create('multi-token-1');
|
|
245
|
+
const tokenId2 = NotificationProperties_1.NotificationProperties.TokenId.create('multi-token-2');
|
|
246
|
+
const flattened = {
|
|
247
|
+
tokens: {
|
|
248
|
+
[tokenId1.flatten]: 'multi-token-1',
|
|
249
|
+
[tokenId2.flatten]: 'multi-token-2'
|
|
250
|
+
},
|
|
251
|
+
subscriptions: []
|
|
252
|
+
};
|
|
253
|
+
const props = NotificationProperties_1.NotificationProperties.builder.build(flattened);
|
|
254
|
+
(0, core_1.expect)(props.tokens.values.length).toBeEqual(2);
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@assertive-ts/core");
|
|
4
|
+
const PayedState_1 = require("../../src/types/PayedState");
|
|
5
|
+
describe('PayedState', () => {
|
|
6
|
+
describe('PayedState type', () => {
|
|
7
|
+
it('should be valid payed state types', () => {
|
|
8
|
+
const state1 = 'payed';
|
|
9
|
+
const state2 = 'notPayed';
|
|
10
|
+
(0, core_1.expect)(state1).toBeEqual('payed');
|
|
11
|
+
(0, core_1.expect)(state2).toBeEqual('notPayed');
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
describe('PayedState.all', () => {
|
|
15
|
+
it('should contain all payment states', () => {
|
|
16
|
+
(0, core_1.expect)(PayedState_1.PayedState.all.length).toBeEqual(2);
|
|
17
|
+
});
|
|
18
|
+
it('should contain payed', () => {
|
|
19
|
+
(0, core_1.expect)(PayedState_1.PayedState.all.includes('payed')).toBeTrue();
|
|
20
|
+
});
|
|
21
|
+
it('should contain notPayed', () => {
|
|
22
|
+
(0, core_1.expect)(PayedState_1.PayedState.all.includes('notPayed')).toBeTrue();
|
|
23
|
+
});
|
|
24
|
+
it('should contain only valid payment state strings', () => {
|
|
25
|
+
PayedState_1.PayedState.all.forEach(state => {
|
|
26
|
+
(0, core_1.expect)(typeof state).toBeEqual('string');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
it('should be readonly', () => {
|
|
30
|
+
(0, core_1.expect)(Array.isArray(PayedState_1.PayedState.all)).toBeTrue();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
describe('PayedState.formatted', () => {
|
|
34
|
+
describe('formatted with en locale', () => {
|
|
35
|
+
it('should format payed state', () => {
|
|
36
|
+
const formatted = PayedState_1.PayedState.formatted('payed', 'en');
|
|
37
|
+
(0, core_1.expect)(typeof formatted).toBeEqual('string');
|
|
38
|
+
(0, core_1.expect)(formatted.length).not.toBeEqual(0);
|
|
39
|
+
});
|
|
40
|
+
it('should format notPayed state', () => {
|
|
41
|
+
const formatted = PayedState_1.PayedState.formatted('notPayed', 'en');
|
|
42
|
+
(0, core_1.expect)(typeof formatted).toBeEqual('string');
|
|
43
|
+
(0, core_1.expect)(formatted.length).not.toBeEqual(0);
|
|
44
|
+
});
|
|
45
|
+
it('should return different values for different states', () => {
|
|
46
|
+
const payed = PayedState_1.PayedState.formatted('payed', 'en');
|
|
47
|
+
const notPayed = PayedState_1.PayedState.formatted('notPayed', 'en');
|
|
48
|
+
(0, core_1.expect)(payed).not.toBeEqual(notPayed);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe('formatted with de locale', () => {
|
|
52
|
+
it('should format payed state', () => {
|
|
53
|
+
const formatted = PayedState_1.PayedState.formatted('payed', 'de');
|
|
54
|
+
(0, core_1.expect)(typeof formatted).toBeEqual('string');
|
|
55
|
+
(0, core_1.expect)(formatted.length).not.toBeEqual(0);
|
|
56
|
+
});
|
|
57
|
+
it('should format notPayed state', () => {
|
|
58
|
+
const formatted = PayedState_1.PayedState.formatted('notPayed', 'de');
|
|
59
|
+
(0, core_1.expect)(typeof formatted).toBeEqual('string');
|
|
60
|
+
(0, core_1.expect)(formatted.length).not.toBeEqual(0);
|
|
61
|
+
});
|
|
62
|
+
it('should return different values for different states', () => {
|
|
63
|
+
const payed = PayedState_1.PayedState.formatted('payed', 'de');
|
|
64
|
+
const notPayed = PayedState_1.PayedState.formatted('notPayed', 'de');
|
|
65
|
+
(0, core_1.expect)(payed).not.toBeEqual(notPayed);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe('formatted for all states and locales', () => {
|
|
69
|
+
it('should format all states in all locales', () => {
|
|
70
|
+
PayedState_1.PayedState.all.forEach(state => {
|
|
71
|
+
const enFormatted = PayedState_1.PayedState.formatted(state, 'en');
|
|
72
|
+
const deFormatted = PayedState_1.PayedState.formatted(state, 'de');
|
|
73
|
+
(0, core_1.expect)(enFormatted.length).not.toBeEqual(0);
|
|
74
|
+
(0, core_1.expect)(deFormatted.length).not.toBeEqual(0);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
it('should return different values for different locales', () => {
|
|
78
|
+
const enPayed = PayedState_1.PayedState.formatted('payed', 'en');
|
|
79
|
+
const dePayed = PayedState_1.PayedState.formatted('payed', 'de');
|
|
80
|
+
const enNotPayed = PayedState_1.PayedState.formatted('notPayed', 'en');
|
|
81
|
+
const deNotPayed = PayedState_1.PayedState.formatted('notPayed', 'de');
|
|
82
|
+
// At least some should differ (assuming localization exists)
|
|
83
|
+
const allFormattings = [enPayed, dePayed, enNotPayed, deNotPayed];
|
|
84
|
+
const uniqueFormattings = new Set(allFormattings);
|
|
85
|
+
(0, core_1.expect)(uniqueFormattings.size).not.toBeEqual(1);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
describe('PayedState.builder', () => {
|
|
90
|
+
it('should build valid payment state from string', () => {
|
|
91
|
+
const state = PayedState_1.PayedState.builder.build('payed');
|
|
92
|
+
(0, core_1.expect)(state).toBeEqual('payed');
|
|
93
|
+
});
|
|
94
|
+
it('should preserve payment state value', () => {
|
|
95
|
+
const state = PayedState_1.PayedState.builder.build('notPayed');
|
|
96
|
+
(0, core_1.expect)(state).toBeEqual('notPayed');
|
|
97
|
+
});
|
|
98
|
+
it('should build all payment states', () => {
|
|
99
|
+
PayedState_1.PayedState.all.forEach(state => {
|
|
100
|
+
const built = PayedState_1.PayedState.builder.build(state);
|
|
101
|
+
(0, core_1.expect)(built).toBeEqual(state);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|