@stevenkellner/team-conduct-api 2.0.3 → 2.0.4

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.
@@ -20,6 +20,13 @@ export declare namespace PayedState {
20
20
  * @returns Localized string representation of the payment state
21
21
  */
22
22
  function formatted(state: PayedState, locale: Locale): string;
23
+ /**
24
+ * Toggles the payment state between 'payed' and 'notPayed'.
25
+ *
26
+ * @param state - The current payment state
27
+ * @returns The toggled payment state
28
+ */
29
+ function toggled(state: PayedState): PayedState;
23
30
  /**
24
31
  * Type builder for PayedState serialization/deserialization.
25
32
  */
@@ -21,6 +21,21 @@ var PayedState;
21
21
  return Localization_1.Localization.shared(locale).payedState[state].value();
22
22
  }
23
23
  PayedState.formatted = formatted;
24
+ /**
25
+ * Toggles the payment state between 'payed' and 'notPayed'.
26
+ *
27
+ * @param state - The current payment state
28
+ * @returns The toggled payment state
29
+ */
30
+ function toggled(state) {
31
+ switch (state) {
32
+ case 'payed':
33
+ return 'notPayed';
34
+ case 'notPayed':
35
+ return 'payed';
36
+ }
37
+ }
38
+ PayedState.toggled = toggled;
24
39
  /**
25
40
  * Type builder for PayedState serialization/deserialization.
26
41
  */
@@ -86,6 +86,37 @@ describe('PayedState', () => {
86
86
  });
87
87
  });
88
88
  });
89
+ describe('PayedState.toggled', () => {
90
+ it('should toggle payed to notPayed', () => {
91
+ const result = PayedState_1.PayedState.toggled('payed');
92
+ (0, core_1.expect)(result).toBeEqual('notPayed');
93
+ });
94
+ it('should toggle notPayed to payed', () => {
95
+ const result = PayedState_1.PayedState.toggled('notPayed');
96
+ (0, core_1.expect)(result).toBeEqual('payed');
97
+ });
98
+ it('should toggle back and forth', () => {
99
+ const state1 = 'payed';
100
+ const state2 = PayedState_1.PayedState.toggled(state1);
101
+ const state3 = PayedState_1.PayedState.toggled(state2);
102
+ (0, core_1.expect)(state2).toBeEqual('notPayed');
103
+ (0, core_1.expect)(state3).toBeEqual('payed');
104
+ });
105
+ it('should toggle all payment states', () => {
106
+ PayedState_1.PayedState.all.forEach(state => {
107
+ const toggled = PayedState_1.PayedState.toggled(state);
108
+ (0, core_1.expect)(toggled).not.toBeEqual(state);
109
+ (0, core_1.expect)(PayedState_1.PayedState.all.includes(toggled)).toBeTrue();
110
+ });
111
+ });
112
+ it('should be reversible', () => {
113
+ PayedState_1.PayedState.all.forEach(state => {
114
+ const toggledOnce = PayedState_1.PayedState.toggled(state);
115
+ const toggledTwice = PayedState_1.PayedState.toggled(toggledOnce);
116
+ (0, core_1.expect)(toggledTwice).toBeEqual(state);
117
+ });
118
+ });
119
+ });
89
120
  describe('PayedState.builder', () => {
90
121
  it('should build valid payment state from string', () => {
91
122
  const state = PayedState_1.PayedState.builder.build('payed');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stevenkellner/team-conduct-api",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "Firebase API for Team Conduct",
5
5
  "license": "MIT",
6
6
  "author": "Steven Kellner",
@@ -29,6 +29,21 @@ export namespace PayedState {
29
29
  return Localization.shared(locale).payedState[state].value();
30
30
  }
31
31
 
32
+ /**
33
+ * Toggles the payment state between 'payed' and 'notPayed'.
34
+ *
35
+ * @param state - The current payment state
36
+ * @returns The toggled payment state
37
+ */
38
+ export function toggled(state: PayedState): PayedState {
39
+ switch (state) {
40
+ case 'payed':
41
+ return 'notPayed';
42
+ case 'notPayed':
43
+ return 'payed';
44
+ }
45
+ }
46
+
32
47
  /**
33
48
  * Type builder for PayedState serialization/deserialization.
34
49
  */