@stevenkellner/team-conduct-api 1.0.13 → 1.0.15

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.
Files changed (36) hide show
  1. package/lib/src/functions/fine/add.js +3 -37
  2. package/lib/src/functions/fine/delete.js +3 -37
  3. package/lib/src/functions/fine/update.js +4 -38
  4. package/lib/src/locales/de.json +69 -0
  5. package/lib/src/locales/en.json +69 -0
  6. package/lib/src/types/FineAmount.d.ts +3 -1
  7. package/lib/src/types/FineAmount.js +10 -42
  8. package/lib/src/types/FineTemplateRepetition.d.ts +2 -0
  9. package/lib/src/types/FineTemplateRepetition.js +8 -0
  10. package/lib/src/types/Localization.d.ts +71 -0
  11. package/lib/src/types/Localization.js +124 -0
  12. package/lib/src/types/PayedState.d.ts +1 -0
  13. package/lib/src/types/PayedState.js +5 -0
  14. package/lib/src/types/UserRole.d.ts +1 -0
  15. package/lib/src/types/UserRole.js +11 -0
  16. package/lib/src/types/index.d.ts +1 -0
  17. package/lib/src/types/index.js +1 -0
  18. package/lib/test/localization-utils.d.ts +12 -0
  19. package/lib/test/localization-utils.js +68 -0
  20. package/lib/test/localization.de.test.d.ts +1 -0
  21. package/lib/test/localization.de.test.js +166 -0
  22. package/lib/test/localization.en.test.d.ts +1 -0
  23. package/lib/test/localization.en.test.js +162 -0
  24. package/lib/tsconfig.tsbuildinfo +1 -1
  25. package/package.json +6 -1
  26. package/src/functions/fine/add.ts +5 -5
  27. package/src/functions/fine/delete.ts +4 -5
  28. package/src/functions/fine/update.ts +5 -6
  29. package/src/locales/de.json +67 -28
  30. package/src/locales/en.json +67 -28
  31. package/src/types/FineAmount.ts +11 -9
  32. package/src/types/FineTemplateRepetition.ts +9 -0
  33. package/src/types/Localization.ts +95 -0
  34. package/src/types/PayedState.ts +5 -0
  35. package/src/types/UserRole.ts +11 -0
  36. package/src/types/index.ts +1 -0
@@ -2,8 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PayedState = void 0;
4
4
  const typescript_common_functionality_1 = require("@stevenkellner/typescript-common-functionality");
5
+ const Localization_1 = require("./Localization");
5
6
  var PayedState;
6
7
  (function (PayedState) {
7
8
  PayedState.all = ['payed', 'notPayed'];
9
+ function formatted(state) {
10
+ return Localization_1.Localization.shared.get(key => key.payedState[state]);
11
+ }
12
+ PayedState.formatted = formatted;
8
13
  PayedState.builder = new typescript_common_functionality_1.ValueTypeBuilder();
9
14
  })(PayedState || (exports.PayedState = PayedState = {}));
@@ -2,5 +2,6 @@ import { ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality
2
2
  export type UserRole = 'person-manager' | 'fineTemplate-manager' | 'fine-manager' | 'team-manager';
3
3
  export declare namespace UserRole {
4
4
  const all: UserRole[];
5
+ function formatted(role: UserRole): string;
5
6
  const builder: ValueTypeBuilder<UserRole>;
6
7
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UserRole = void 0;
4
4
  const typescript_common_functionality_1 = require("@stevenkellner/typescript-common-functionality");
5
+ const Localization_1 = require("./Localization");
5
6
  var UserRole;
6
7
  (function (UserRole) {
7
8
  UserRole.all = [
@@ -10,5 +11,15 @@ var UserRole;
10
11
  'fine-manager',
11
12
  'team-manager'
12
13
  ];
14
+ function formatted(role) {
15
+ const localizationKeyMap = {
16
+ 'person-manager': 'personManager',
17
+ 'fineTemplate-manager': 'fineTemplateManager',
18
+ 'fine-manager': 'fineManager',
19
+ 'team-manager': 'teamManager'
20
+ };
21
+ return Localization_1.Localization.shared.get(key => key.userRole[localizationKeyMap[role]]);
22
+ }
23
+ UserRole.formatted = formatted;
13
24
  UserRole.builder = new typescript_common_functionality_1.ValueTypeBuilder();
14
25
  })(UserRole || (exports.UserRole = UserRole = {}));
@@ -4,6 +4,7 @@ export * from './FineAmount';
4
4
  export * from './FineTemplate';
5
5
  export * from './FineTemplateRepetition';
6
6
  export * from './Invitation';
7
+ export * from './Localization';
7
8
  export * from './MoneyAmount';
8
9
  export * from './NotificationProperties';
9
10
  export * from './PayedState';
@@ -20,6 +20,7 @@ __exportStar(require("./FineAmount"), exports);
20
20
  __exportStar(require("./FineTemplate"), exports);
21
21
  __exportStar(require("./FineTemplateRepetition"), exports);
22
22
  __exportStar(require("./Invitation"), exports);
23
+ __exportStar(require("./Localization"), exports);
23
24
  __exportStar(require("./MoneyAmount"), exports);
24
25
  __exportStar(require("./NotificationProperties"), exports);
25
26
  __exportStar(require("./PayedState"), exports);
@@ -0,0 +1,12 @@
1
+ import { localizationKey, localizationNKey } from '../src/types/Localization';
2
+ export declare function localizationWithoutDefault<T extends Record<string, unknown>>(record: T): Exclude<T, 'default'>;
3
+ export declare function hasSameKeys(record1: Record<string, unknown>, record2: Record<string, unknown>): void;
4
+ export declare class TestedKeys {
5
+ private tested;
6
+ constructor(localization: Record<string, unknown>);
7
+ private mapCheckTestedRecord;
8
+ checkAllTested(): void;
9
+ test(getKey: (key: typeof localizationKey) => string, expected: string): void;
10
+ testArgs(getKey: (key: typeof localizationKey) => string, args: string[], expected: string): void;
11
+ testN(getKey: (key: typeof localizationNKey) => string, count: number, expected: string): void;
12
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TestedKeys = void 0;
4
+ exports.localizationWithoutDefault = localizationWithoutDefault;
5
+ exports.hasSameKeys = hasSameKeys;
6
+ const core_1 = require("@assertive-ts/core");
7
+ const typescript_common_functionality_1 = require("@stevenkellner/typescript-common-functionality");
8
+ const Localization_1 = require("../src/types/Localization");
9
+ function localizationWithoutDefault(record) {
10
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
+ const { default: _, ...rest } = record;
12
+ return rest;
13
+ }
14
+ function hasSameKeys(record1, record2) {
15
+ (0, core_1.expect)((0, typescript_common_functionality_1.keys)(record1)).toHaveSameMembers((0, typescript_common_functionality_1.keys)(record2));
16
+ for (const key of (0, typescript_common_functionality_1.keys)(record1)) {
17
+ if (typeof record1[key] === 'object' && record1[key] !== null) {
18
+ (0, core_1.expect)(record2[key]).not.toBeUndefined();
19
+ (0, core_1.expect)(typeof record2[key]).toBeEqual('object');
20
+ (0, core_1.expect)(record1[key]).not.toBeNull();
21
+ hasSameKeys(record1[key], record2[key]);
22
+ }
23
+ else {
24
+ (0, core_1.expect)(typeof record1[key]).toBeEqual('string');
25
+ (0, core_1.expect)(typeof record2[key]).toBeEqual('string');
26
+ }
27
+ }
28
+ }
29
+ class TestedKeys {
30
+ tested;
31
+ constructor(localization) {
32
+ this.tested = this.mapCheckTestedRecord(localizationWithoutDefault(localization));
33
+ }
34
+ mapCheckTestedRecord(record) {
35
+ function getKeyList(record, key) {
36
+ return (0, typescript_common_functionality_1.keys)(record).flatMap(k => {
37
+ if (typeof record[k] === 'object' && record[k] !== null)
38
+ return getKeyList(record[k], `${key}${k}.`);
39
+ else
40
+ return `${key}${k}`;
41
+ });
42
+ }
43
+ const testedRecord = {};
44
+ for (const key of getKeyList(record, ''))
45
+ testedRecord[key] = false;
46
+ return testedRecord;
47
+ }
48
+ checkAllTested() {
49
+ for (const value of (0, typescript_common_functionality_1.values)(this.tested))
50
+ (0, core_1.expect)(value).toBeEqual(true);
51
+ }
52
+ test(getKey, expected) {
53
+ this.tested[getKey(Localization_1.localizationKey)] = true;
54
+ (0, core_1.expect)(Localization_1.Localization.shared.get(getKey)).toBeEqual(expected);
55
+ }
56
+ testArgs(getKey, args, expected) {
57
+ this.tested[getKey(Localization_1.localizationKey)] = true;
58
+ (0, core_1.expect)(Localization_1.Localization.shared.get(getKey, ...args)).toBeEqual(expected);
59
+ }
60
+ testN(getKey, count, expected) {
61
+ if (count === 1)
62
+ this.tested[`${getKey(Localization_1.localizationNKey)}.one`] = true;
63
+ else
64
+ this.tested[`${getKey(Localization_1.localizationNKey)}.other`] = true;
65
+ (0, core_1.expect)(Localization_1.Localization.shared.getN(getKey, count)).toBeEqual(expected);
66
+ }
67
+ }
68
+ exports.TestedKeys = TestedKeys;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const core_1 = require("@assertive-ts/core");
37
+ const localizationEN = __importStar(require("../src/locales/en.json"));
38
+ const localizationDE = __importStar(require("../src/locales/de.json"));
39
+ const types_1 = require("../src/types");
40
+ const localization_utils_1 = require("./localization-utils");
41
+ describe('Localization for de', () => {
42
+ const testedKeys = new localization_utils_1.TestedKeys((0, localization_utils_1.localizationWithoutDefault)(localizationDE));
43
+ before(() => {
44
+ types_1.Localization.shared.setLocale('de');
45
+ });
46
+ after('all values should be tested', () => {
47
+ testedKeys.checkAllTested();
48
+ });
49
+ it('should have the same keys as en', () => {
50
+ (0, localization_utils_1.hasSameKeys)((0, localization_utils_1.localizationWithoutDefault)(localizationDE), (0, localization_utils_1.localizationWithoutDefault)(localizationEN));
51
+ });
52
+ describe('notification.fine should be tested', () => {
53
+ it('notification.fine.new should be tested', () => {
54
+ testedKeys.testArgs(key => key.notification.fine.new.title, ['fine-reason'], 'fine-reason');
55
+ testedKeys.testArgs(key => key.notification.fine.new.body, ['10,50 €'], 'Du hast eine neue Strafe von 10,50 €. Bitte so schnell wie möglich zahlen.');
56
+ });
57
+ it('notification.fine.reminder should be tested', () => {
58
+ testedKeys.test(key => key.notification.fine.reminder.title, 'Du hast noch offene Strafen');
59
+ testedKeys.testArgs(key => key.notification.fine.reminder.body, ['10,50 €'], 'Bei dir sind noch 10,50 € offen. Bitte so schnell wie möglich zahlen.');
60
+ });
61
+ it('notification.fine.stateChange should be tested', () => {
62
+ testedKeys.test(key => key.notification.fine.stateChange.title, 'Eine deiner Strafen hat sich geändert');
63
+ testedKeys.testArgs(key => key.notification.fine.stateChange.bodyPayed, ['10,50 €', 'fine-reason'], 'Du hast eine Strafe von 10,50 € bezahlt (fine-reason).');
64
+ testedKeys.testArgs(key => key.notification.fine.stateChange.bodyUnpayed, ['10,50 €', 'fine-reason'], '10,50 €, fine-reason ist noch offen.');
65
+ testedKeys.testArgs(key => key.notification.fine.stateChange.bodyDeleted, ['10,50 €', 'fine-reason'], '10,50 €, fine-reason wurde gelöscht.');
66
+ });
67
+ });
68
+ describe('fineAmount should be tested', () => {
69
+ it('fineAmount.item.type.crateOfBeer should be tested', () => {
70
+ testedKeys.test(key => key.fineAmount.item.type.crateOfBeer, 'Kasten Bier');
71
+ testedKeys.testN(key => key.fineAmount.item.type.crateOfBeer, 1, 'Ein Kasten Bier');
72
+ testedKeys.testN(key => key.fineAmount.item.type.crateOfBeer, 4, '4 Kästen Bier');
73
+ testedKeys.testN(key => key.fineAmount.item.type.crateOfBeerWithoutCount, 1, 'Kasten Bier');
74
+ testedKeys.testN(key => key.fineAmount.item.type.crateOfBeerWithoutCount, 4, 'Kästen Bier');
75
+ });
76
+ it('fineAmount.item.type.crateOfBeer should be formatted correctly', () => {
77
+ (0, core_1.expect)(types_1.FineAmount.Item.Type.formatted('crateOfBeer')).toBeEqual('Kasten Bier');
78
+ (0, core_1.expect)(new types_1.FineAmount.Item('crateOfBeer', 1).formatted()).toBeEqual('Ein Kasten Bier');
79
+ (0, core_1.expect)(new types_1.FineAmount.Item('crateOfBeer', 4).formatted()).toBeEqual('4 Kästen Bier');
80
+ (0, core_1.expect)(new types_1.FineAmount.Item('crateOfBeer', 1).formattedWithoutCount()).toBeEqual('Kasten Bier');
81
+ (0, core_1.expect)(new types_1.FineAmount.Item('crateOfBeer', 4).formattedWithoutCount()).toBeEqual('Kästen Bier');
82
+ });
83
+ });
84
+ describe('fineTemplateRepetition should be tested', () => {
85
+ it('fineTemplateRepetition.item.minute should be tested', () => {
86
+ testedKeys.test(key => key.fineTemplateRepetition.item.minute, 'Minute');
87
+ testedKeys.testN(key => key.fineTemplateRepetition.item.minute, 1, '1 Minute');
88
+ testedKeys.testN(key => key.fineTemplateRepetition.item.minute, 4, '4 Minuten');
89
+ });
90
+ it('fineTemplateRepetition.item.minute should be formatted correctly', () => {
91
+ (0, core_1.expect)(types_1.FineTemplateRepetition.Item.formatted('minute')).toBeEqual('Minute');
92
+ (0, core_1.expect)(new types_1.FineTemplateRepetition('minute', null).formatted(1)).toBeEqual('1 Minute');
93
+ (0, core_1.expect)(new types_1.FineTemplateRepetition('minute', null).formatted(4)).toBeEqual('4 Minuten');
94
+ });
95
+ it('fineTemplateRepetition.item.day should be tested', () => {
96
+ testedKeys.test(key => key.fineTemplateRepetition.item.day, 'Tag');
97
+ testedKeys.testN(key => key.fineTemplateRepetition.item.day, 1, '1 Tag');
98
+ testedKeys.testN(key => key.fineTemplateRepetition.item.day, 4, '4 Tage');
99
+ });
100
+ it('fineTemplateRepetition.item.day should be formatted correctly', () => {
101
+ (0, core_1.expect)(types_1.FineTemplateRepetition.Item.formatted('day')).toBeEqual('Tag');
102
+ (0, core_1.expect)(new types_1.FineTemplateRepetition('day', null).formatted(1)).toBeEqual('1 Tag');
103
+ (0, core_1.expect)(new types_1.FineTemplateRepetition('day', null).formatted(4)).toBeEqual('4 Tage');
104
+ });
105
+ it('fineTemplateRepetition.item.item should be tested', () => {
106
+ testedKeys.test(key => key.fineTemplateRepetition.item.item, 'Teil');
107
+ testedKeys.testN(key => key.fineTemplateRepetition.item.item, 1, '1 Teil');
108
+ testedKeys.testN(key => key.fineTemplateRepetition.item.item, 4, '4 Teile');
109
+ });
110
+ it('fineTemplateRepetition.item.item should be formatted correctly', () => {
111
+ (0, core_1.expect)(types_1.FineTemplateRepetition.Item.formatted('item')).toBeEqual('Teil');
112
+ (0, core_1.expect)(new types_1.FineTemplateRepetition('item', null).formatted(1)).toBeEqual('1 Teil');
113
+ (0, core_1.expect)(new types_1.FineTemplateRepetition('item', null).formatted(4)).toBeEqual('4 Teile');
114
+ });
115
+ it('fineTemplateRepetition.item.count should be tested', () => {
116
+ testedKeys.test(key => key.fineTemplateRepetition.item.count, 'Anzahl');
117
+ testedKeys.testN(key => key.fineTemplateRepetition.item.count, 1, '1 mal');
118
+ testedKeys.testN(key => key.fineTemplateRepetition.item.count, 4, '4 mal');
119
+ });
120
+ it('fineTemplateRepetition.item.count should be formatted correctly', () => {
121
+ (0, core_1.expect)(types_1.FineTemplateRepetition.Item.formatted('count')).toBeEqual('Anzahl');
122
+ (0, core_1.expect)(new types_1.FineTemplateRepetition('count', null).formatted(1)).toBeEqual('1 mal');
123
+ (0, core_1.expect)(new types_1.FineTemplateRepetition('count', null).formatted(4)).toBeEqual('4 mal');
124
+ });
125
+ });
126
+ describe('payedState should be tested', () => {
127
+ it('payedState.payed should be tested', () => {
128
+ testedKeys.test(key => key.payedState.payed, 'Bezahlt');
129
+ });
130
+ it('payedState.payed should be formatted correctly', () => {
131
+ (0, core_1.expect)(types_1.PayedState.formatted('payed')).toBeEqual('Bezahlt');
132
+ });
133
+ it('payedState.notPayed should be tested', () => {
134
+ testedKeys.test(key => key.payedState.notPayed, 'Offen');
135
+ });
136
+ it('payedState.notPayed should be formatted correctly', () => {
137
+ (0, core_1.expect)(types_1.PayedState.formatted('notPayed')).toBeEqual('Offen');
138
+ });
139
+ });
140
+ describe('userRole should be tested', () => {
141
+ it('userRole.personManager should be tested', () => {
142
+ testedKeys.test(key => key.userRole.personManager, 'Personenmanager');
143
+ });
144
+ it('userRole.personManager should be formatted correctly', () => {
145
+ (0, core_1.expect)(types_1.UserRole.formatted('person-manager')).toBeEqual('Personenmanager');
146
+ });
147
+ it('userRole.fineTemplateManager should be tested', () => {
148
+ testedKeys.test(key => key.userRole.fineTemplateManager, 'Strafvorlagenmanager');
149
+ });
150
+ it('userRole.fineTemplateManager should be formatted correctly', () => {
151
+ (0, core_1.expect)(types_1.UserRole.formatted('fineTemplate-manager')).toBeEqual('Strafvorlagenmanager');
152
+ });
153
+ it('userRole.fineManager should be tested', () => {
154
+ testedKeys.test(key => key.userRole.fineManager, 'Strafenmanager');
155
+ });
156
+ it('userRole.fineManager should be formatted correctly', () => {
157
+ (0, core_1.expect)(types_1.UserRole.formatted('fine-manager')).toBeEqual('Strafenmanager');
158
+ });
159
+ it('userRole.teamManager should be tested', () => {
160
+ testedKeys.test(key => key.userRole.teamManager, 'Teammanager');
161
+ });
162
+ it('userRole.teamManager should be formatted correctly', () => {
163
+ (0, core_1.expect)(types_1.UserRole.formatted('team-manager')).toBeEqual('Teammanager');
164
+ });
165
+ });
166
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const core_1 = require("@assertive-ts/core");
37
+ const localizationEN = __importStar(require("../src/locales/en.json"));
38
+ const types_1 = require("../src/types");
39
+ const localization_utils_1 = require("./localization-utils");
40
+ describe('Localization for en', () => {
41
+ const testedKeys = new localization_utils_1.TestedKeys((0, localization_utils_1.localizationWithoutDefault)(localizationEN));
42
+ before(() => {
43
+ types_1.Localization.shared.setLocale('en');
44
+ });
45
+ after('all values should be tested', () => {
46
+ testedKeys.checkAllTested();
47
+ });
48
+ describe('notification.fine should be tested', () => {
49
+ it('notification.fine.new should be tested', () => {
50
+ testedKeys.testArgs(key => key.notification.fine.new.title, ['fine-reason'], 'fine-reason');
51
+ testedKeys.testArgs(key => key.notification.fine.new.body, ['10.50 €'], 'You have a new fine of 10.50 €. Please pay it as soon as possible.');
52
+ });
53
+ it('notification.fine.reminder should be tested', () => {
54
+ testedKeys.test(key => key.notification.fine.reminder.title, 'You still have outstanding fines');
55
+ testedKeys.testArgs(key => key.notification.fine.reminder.body, ['10.50 €'], 'You still have 10.50 € outstanding. Please pay as soon as possible.');
56
+ });
57
+ it('notification.fine.stateChange should be tested', () => {
58
+ testedKeys.test(key => key.notification.fine.stateChange.title, 'One of your fines has changed');
59
+ testedKeys.testArgs(key => key.notification.fine.stateChange.bodyPayed, ['10.50 €', 'fine-reason'], 'You have paid a fine of 10.50 € (fine-reason).');
60
+ testedKeys.testArgs(key => key.notification.fine.stateChange.bodyUnpayed, ['10.50 €', 'fine-reason'], '10.50 €, fine-reason is still outstanding.');
61
+ testedKeys.testArgs(key => key.notification.fine.stateChange.bodyDeleted, ['10.50 €', 'fine-reason'], '10.50 €, fine-reason has been deleted.');
62
+ });
63
+ });
64
+ describe('fineAmount should be tested', () => {
65
+ it('fineAmount.item.type.crateOfBeer should be tested', () => {
66
+ testedKeys.test(key => key.fineAmount.item.type.crateOfBeer, 'Crate of Beer');
67
+ testedKeys.testN(key => key.fineAmount.item.type.crateOfBeer, 1, 'a crate of beer');
68
+ testedKeys.testN(key => key.fineAmount.item.type.crateOfBeer, 4, '4 crates of beer');
69
+ testedKeys.testN(key => key.fineAmount.item.type.crateOfBeerWithoutCount, 1, 'Crate of Beer');
70
+ testedKeys.testN(key => key.fineAmount.item.type.crateOfBeerWithoutCount, 4, 'Crates of Beer');
71
+ });
72
+ it('fineAmount.item.type.crateOfBeer should be formatted correctly', () => {
73
+ (0, core_1.expect)(types_1.FineAmount.Item.Type.formatted('crateOfBeer')).toBeEqual('Crate of Beer');
74
+ (0, core_1.expect)(new types_1.FineAmount.Item('crateOfBeer', 1).formatted()).toBeEqual('a crate of beer');
75
+ (0, core_1.expect)(new types_1.FineAmount.Item('crateOfBeer', 4).formatted()).toBeEqual('4 crates of beer');
76
+ (0, core_1.expect)(new types_1.FineAmount.Item('crateOfBeer', 1).formattedWithoutCount()).toBeEqual('Crate of Beer');
77
+ (0, core_1.expect)(new types_1.FineAmount.Item('crateOfBeer', 4).formattedWithoutCount()).toBeEqual('Crates of Beer');
78
+ });
79
+ });
80
+ describe('fineTemplateRepetition should be tested', () => {
81
+ it('fineTemplateRepetition.item.minute should be tested', () => {
82
+ testedKeys.test(key => key.fineTemplateRepetition.item.minute, 'Minute');
83
+ testedKeys.testN(key => key.fineTemplateRepetition.item.minute, 1, '1 minute');
84
+ testedKeys.testN(key => key.fineTemplateRepetition.item.minute, 4, '4 minutes');
85
+ });
86
+ it('fineTemplateRepetition.item.minute should be formatted correctly', () => {
87
+ (0, core_1.expect)(types_1.FineTemplateRepetition.Item.formatted('minute')).toBeEqual('Minute');
88
+ (0, core_1.expect)(new types_1.FineTemplateRepetition('minute', null).formatted(1)).toBeEqual('1 minute');
89
+ (0, core_1.expect)(new types_1.FineTemplateRepetition('minute', null).formatted(4)).toBeEqual('4 minutes');
90
+ });
91
+ it('fineTemplateRepetition.item.day should be tested', () => {
92
+ testedKeys.test(key => key.fineTemplateRepetition.item.day, 'Day');
93
+ testedKeys.testN(key => key.fineTemplateRepetition.item.day, 1, '1 day');
94
+ testedKeys.testN(key => key.fineTemplateRepetition.item.day, 4, '4 days');
95
+ });
96
+ it('fineTemplateRepetition.item.day should be formatted correctly', () => {
97
+ (0, core_1.expect)(types_1.FineTemplateRepetition.Item.formatted('day')).toBeEqual('Day');
98
+ (0, core_1.expect)(new types_1.FineTemplateRepetition('day', null).formatted(1)).toBeEqual('1 day');
99
+ (0, core_1.expect)(new types_1.FineTemplateRepetition('day', null).formatted(4)).toBeEqual('4 days');
100
+ });
101
+ it('fineTemplateRepetition.item.item should be tested', () => {
102
+ testedKeys.test(key => key.fineTemplateRepetition.item.item, 'Item');
103
+ testedKeys.testN(key => key.fineTemplateRepetition.item.item, 1, '1 item');
104
+ testedKeys.testN(key => key.fineTemplateRepetition.item.item, 4, '4 items');
105
+ });
106
+ it('fineTemplateRepetition.item.item should be formatted correctly', () => {
107
+ (0, core_1.expect)(types_1.FineTemplateRepetition.Item.formatted('item')).toBeEqual('Item');
108
+ (0, core_1.expect)(new types_1.FineTemplateRepetition('item', null).formatted(1)).toBeEqual('1 item');
109
+ (0, core_1.expect)(new types_1.FineTemplateRepetition('item', null).formatted(4)).toBeEqual('4 items');
110
+ });
111
+ it('fineTemplateRepetition.item.count should be tested', () => {
112
+ testedKeys.test(key => key.fineTemplateRepetition.item.count, 'Count');
113
+ testedKeys.testN(key => key.fineTemplateRepetition.item.count, 1, '1 time');
114
+ testedKeys.testN(key => key.fineTemplateRepetition.item.count, 4, '4 times');
115
+ });
116
+ it('fineTemplateRepetition.item.count should be formatted correctly', () => {
117
+ (0, core_1.expect)(types_1.FineTemplateRepetition.Item.formatted('count')).toBeEqual('Count');
118
+ (0, core_1.expect)(new types_1.FineTemplateRepetition('count', null).formatted(1)).toBeEqual('1 time');
119
+ (0, core_1.expect)(new types_1.FineTemplateRepetition('count', null).formatted(4)).toBeEqual('4 times');
120
+ });
121
+ });
122
+ describe('payedState should be tested', () => {
123
+ it('payedState.payed should be tested', () => {
124
+ testedKeys.test(key => key.payedState.payed, 'Paid');
125
+ });
126
+ it('payedState.payed should be formatted correctly', () => {
127
+ (0, core_1.expect)(types_1.PayedState.formatted('payed')).toBeEqual('Paid');
128
+ });
129
+ it('payedState.notPayed should be tested', () => {
130
+ testedKeys.test(key => key.payedState.notPayed, 'Outstanding');
131
+ });
132
+ it('payedState.notPayed should be formatted correctly', () => {
133
+ (0, core_1.expect)(types_1.PayedState.formatted('notPayed')).toBeEqual('Outstanding');
134
+ });
135
+ });
136
+ describe('userRole should be tested', () => {
137
+ it('userRole.personManager should be tested', () => {
138
+ testedKeys.test(key => key.userRole.personManager, 'Person Manager');
139
+ });
140
+ it('userRole.personManager should be formatted correctly', () => {
141
+ (0, core_1.expect)(types_1.UserRole.formatted('person-manager')).toBeEqual('Person Manager');
142
+ });
143
+ it('userRole.fineTemplateManager should be tested', () => {
144
+ testedKeys.test(key => key.userRole.fineTemplateManager, 'Fine Template Manager');
145
+ });
146
+ it('userRole.fineTemplateManager should be formatted correctly', () => {
147
+ (0, core_1.expect)(types_1.UserRole.formatted('fineTemplate-manager')).toBeEqual('Fine Template Manager');
148
+ });
149
+ it('userRole.fineManager should be tested', () => {
150
+ testedKeys.test(key => key.userRole.fineManager, 'Fine Manager');
151
+ });
152
+ it('userRole.fineManager should be formatted correctly', () => {
153
+ (0, core_1.expect)(types_1.UserRole.formatted('fine-manager')).toBeEqual('Fine Manager');
154
+ });
155
+ it('userRole.teamManager should be tested', () => {
156
+ testedKeys.test(key => key.userRole.teamManager, 'Team Manager');
157
+ });
158
+ it('userRole.teamManager should be formatted correctly', () => {
159
+ (0, core_1.expect)(types_1.UserRole.formatted('team-manager')).toBeEqual('Team Manager');
160
+ });
161
+ });
162
+ });
@@ -1 +1 @@
1
- {"root":["../index.ts","../src/Firestore.ts","../src/FirestoreScheme.ts","../src/checkAuthentication.ts","../src/firebaseFunctionsContext.ts","../src/index.ts","../src/pushNotification.ts","../src/firebase/FirebaseConfiguration.ts","../src/firebase/Messaging.ts","../src/firebase/index.ts","../src/functions/index.ts","../src/functions/fine/add.ts","../src/functions/fine/delete.ts","../src/functions/fine/update.ts","../src/functions/fineTemplate/add.ts","../src/functions/fineTemplate/delete.ts","../src/functions/fineTemplate/update.ts","../src/functions/invitation/invite.ts","../src/functions/invitation/register.ts","../src/functions/invitation/withdraw.ts","../src/functions/notification/register.ts","../src/functions/notification/subscribe.ts","../src/functions/paypalMe/edit.ts","../src/functions/person/add.ts","../src/functions/person/delete.ts","../src/functions/person/update.ts","../src/functions/team/new.ts","../src/functions/user/login.ts","../src/functions/user/roleEdit.ts","../src/types/Configuration.ts","../src/types/Fine.ts","../src/types/FineAmount.ts","../src/types/FineTemplate.ts","../src/types/FineTemplateRepetition.ts","../src/types/Invitation.ts","../src/types/MoneyAmount.ts","../src/types/NotificationProperties.ts","../src/types/PayedState.ts","../src/types/Person.ts","../src/types/PersonPrivateProperties.ts","../src/types/PersonSignInProperties.ts","../src/types/Team.ts","../src/types/User.ts","../src/types/UserRole.ts","../src/types/index.ts"],"version":"5.8.3"}
1
+ {"root":["../index.ts","../src/Firestore.ts","../src/FirestoreScheme.ts","../src/checkAuthentication.ts","../src/firebaseFunctionsContext.ts","../src/index.ts","../src/pushNotification.ts","../src/firebase/FirebaseConfiguration.ts","../src/firebase/Messaging.ts","../src/firebase/index.ts","../src/functions/index.ts","../src/functions/fine/add.ts","../src/functions/fine/delete.ts","../src/functions/fine/update.ts","../src/functions/fineTemplate/add.ts","../src/functions/fineTemplate/delete.ts","../src/functions/fineTemplate/update.ts","../src/functions/invitation/invite.ts","../src/functions/invitation/register.ts","../src/functions/invitation/withdraw.ts","../src/functions/notification/register.ts","../src/functions/notification/subscribe.ts","../src/functions/paypalMe/edit.ts","../src/functions/person/add.ts","../src/functions/person/delete.ts","../src/functions/person/update.ts","../src/functions/team/new.ts","../src/functions/user/login.ts","../src/functions/user/roleEdit.ts","../src/types/Configuration.ts","../src/types/Fine.ts","../src/types/FineAmount.ts","../src/types/FineTemplate.ts","../src/types/FineTemplateRepetition.ts","../src/types/Invitation.ts","../src/types/Localization.ts","../src/types/MoneyAmount.ts","../src/types/NotificationProperties.ts","../src/types/PayedState.ts","../src/types/Person.ts","../src/types/PersonPrivateProperties.ts","../src/types/PersonSignInProperties.ts","../src/types/Team.ts","../src/types/User.ts","../src/types/UserRole.ts","../src/types/index.ts","../test/localization-utils.ts","../test/localization.de.test.ts","../test/localization.en.test.ts"],"version":"5.8.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stevenkellner/team-conduct-api",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "Firebase API for Team Conduct",
5
5
  "license": "MIT",
6
6
  "author": "Steven Kellner",
@@ -17,6 +17,7 @@
17
17
  "build:watch": "tsc --watch",
18
18
  "lint": "eslint --ext .js,.ts .",
19
19
  "lint:fix": "eslint --ext .js,.ts . --fix",
20
+ "test": "mocha",
20
21
  "upgrade": "ncu --upgrade --install always",
21
22
  "release": "npm run rebuild && npm run lint && npm version patch && git push --follow-tags"
22
23
  },
@@ -26,15 +27,19 @@
26
27
  "i18n": "^0.15.1"
27
28
  },
28
29
  "devDependencies": {
30
+ "@assertive-ts/core": "^2.1.0",
29
31
  "@eslint/compat": "^1.2.9",
30
32
  "@eslint/eslintrc": "^3.3.1",
31
33
  "@eslint/js": "^9.26.0",
32
34
  "@types/i18n": "^0.13.12",
35
+ "@types/mocha": "^10.0.10",
33
36
  "@typescript-eslint/eslint-plugin": "^8.32.0",
34
37
  "@typescript-eslint/parser": "^8.32.0",
35
38
  "eslint": "^9.26.0",
36
39
  "eslint-config-google": "^0.14.0",
37
40
  "eslint-plugin-import": "^2.31.0",
41
+ "mocha": "^11.3.0",
42
+ "ts-node": "^10.9.2",
38
43
  "typescript": "^5.8.3"
39
44
  }
40
45
  }
@@ -1,10 +1,10 @@
1
1
  import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
2
2
  import { Flattable, ObjectTypeBuilder, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
3
- import { Configuration, Fine, Person, Team } from '../../types';
3
+ import { Configuration, Fine, Localization, Person, Team } from '../../types';
4
4
  import { checkAuthentication } from '../../checkAuthentication';
5
5
  import { Firestore } from '../../Firestore';
6
6
  import { pushNotification } from '../../pushNotification';
7
- import * as i18n from 'i18n';
7
+
8
8
 
9
9
  export namespace FineAddFunction {
10
10
 
@@ -45,10 +45,10 @@ export class FineAddFunction extends FirebaseFunction<FineAddFunction.Parameters
45
45
  person.fineIds.push(parameters.fine.id);
46
46
  await Firestore.shared.person(parameters.teamId, parameters.personId).set(person);
47
47
 
48
- i18n.setLocale(parameters.configuration.locale);
48
+ Localization.shared.setLocale(parameters.configuration.locale);
49
49
  await pushNotification(parameters.teamId, parameters.personId, 'new-fine', {
50
- title: i18n.__('notification.fine.new.title', parameters.fine.reason),
51
- body: i18n.__('notification.fine.new.body', parameters.fine.amount.formatted(parameters.configuration))
50
+ title: Localization.shared.get(key => key.notification.fine.new.title, parameters.fine.reason),
51
+ body: Localization.shared.get(key => key.notification.fine.new.body, parameters.fine.amount.formatted(parameters.configuration))
52
52
  });
53
53
  }
54
54
  }
@@ -1,10 +1,9 @@
1
1
  import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
2
- import { Configuration, Fine, FineAmount, Person, Team } from '../../types';
2
+ import { Configuration, Fine, FineAmount, Localization, Person, Team } from '../../types';
3
3
  import { Flattable, ObjectTypeBuilder, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
4
4
  import { checkAuthentication } from '../../checkAuthentication';
5
5
  import { Firestore } from '../../Firestore';
6
6
  import { pushNotification } from '../../pushNotification';
7
- import * as i18n from 'i18n';
8
7
 
9
8
  export namespace FineDeleteFunction {
10
9
 
@@ -45,10 +44,10 @@ export class FineDeleteFunction extends FirebaseFunction<FineDeleteFunction.Para
45
44
  person.fineIds = person.fineIds.filter(id => id.guidString !== parameters.id.guidString);
46
45
  await Firestore.shared.person(parameters.teamId, parameters.personId).set(person);
47
46
 
48
- i18n.setLocale(parameters.configuration.locale);
47
+ Localization.shared.setLocale(parameters.configuration.locale);
49
48
  await pushNotification(parameters.teamId, parameters.personId, 'fine-state-change', {
50
- title: i18n.__('notification.fine.state-change.title'),
51
- body: i18n.__('notification.fine.state-change.body-deleted', fineSnapshot.data.reason, FineAmount.builder.build(fineSnapshot.data.amount).formatted(parameters.configuration))
49
+ title: Localization.shared.get(key => key.notification.fine.stateChange.title),
50
+ body: Localization.shared.get(key => key.notification.fine.stateChange.bodyDeleted, fineSnapshot.data.reason, FineAmount.builder.build(fineSnapshot.data.amount).formatted(parameters.configuration))
52
51
  });
53
52
  }
54
53
  }
@@ -1,11 +1,10 @@
1
1
  import { Configuration } from '../../types/Configuration';
2
2
  import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
3
3
  import { pushNotification } from '../../pushNotification';
4
- import { Fine, Person, Team } from '../../types';
4
+ import { Fine, Localization, Person, Team } from '../../types';
5
5
  import { Flattable, ObjectTypeBuilder, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
6
6
  import { checkAuthentication } from '../../checkAuthentication';
7
7
  import { Firestore } from '../../Firestore';
8
- import * as i18n from 'i18n';
9
8
 
10
9
  export namespace FineUpdateFunction {
11
10
 
@@ -38,15 +37,15 @@ export class FineUpdateFunction extends FirebaseFunction<FineUpdateFunction.Para
38
37
 
39
38
  await Firestore.shared.fine(parameters.teamId, parameters.fine.id).set(parameters.fine);
40
39
 
41
- i18n.setLocale(parameters.configuration.locale);
40
+ Localization.shared.setLocale(parameters.configuration.locale);
42
41
  if (parameters.fine.payedState !== fineSnapshot.data.payedState) {
43
42
  let body: string;
44
43
  if (parameters.fine.payedState === 'payed')
45
- body = i18n.__('notification.fine.state-change.body-payed', parameters.fine.amount.formatted(parameters.configuration), parameters.fine.reason);
44
+ body = Localization.shared.get(key => key.notification.fine.stateChange.bodyPayed, parameters.fine.amount.formatted(parameters.configuration), parameters.fine.reason);
46
45
  else
47
- body = i18n.__('notification.fine.state-change.body-unpayed', parameters.fine.reason, parameters.fine.amount.formatted(parameters.configuration));
46
+ body = Localization.shared.get(key => key.notification.fine.stateChange.bodyUnpayed, parameters.fine.reason, parameters.fine.amount.formatted(parameters.configuration));
48
47
  await pushNotification(parameters.teamId, parameters.personId, 'fine-state-change', {
49
- title: i18n.__('notification.fine.state-change.title'),
48
+ title: Localization.shared.get(key => key.notification.fine.stateChange.title),
50
49
  body: body
51
50
  });
52
51