@darkpos/pricing 1.0.41 → 1.0.44

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 (51) hide show
  1. package/__TEST__/item/getItemsModifierDescription.test.js +148 -0
  2. package/__TEST__/mocks/addItemMock.js +18729 -19357
  3. package/__TEST__/mocks/partially-paid/order-modifiers.json +48 -51
  4. package/__TEST__/mocks/partially-paid/order-partially-paid.json +893 -860
  5. package/__TEST__/mocks/unpaid/order-modifiers.json +48 -52
  6. package/__TEST__/modifier/calculate.test.js +1 -0
  7. package/__TEST__/modifier/getGroupedModifierLabels.test.js +95 -0
  8. package/__TEST__/modifier/getGroupedModifiers.test.js +65 -0
  9. package/__TEST__/modifier/getMatchTagsModifiers.test.js +72 -18
  10. package/__TEST__/modifier/getModifierIndex.test.js +10 -7
  11. package/__TEST__/modifier/getNotesToModifierTags.test.js +78 -0
  12. package/__TEST__/modifier/getRecommendedModifiers.test.js +6 -4
  13. package/__TEST__/modifier/hasAttribute.test.js +11 -5
  14. package/__TEST__/modifier/hasMatchTags.test.js +33 -11
  15. package/__TEST__/modifier/isOptionsOverride.test.js +46 -0
  16. package/__TEST__/modifier/sort.test.js +1 -1
  17. package/__TEST__/order/conditionsNotMet.test.js +133 -0
  18. package/__TEST__/order/order.test.js +7 -5
  19. package/__TEST__/order/pickEndDate.test.js +4 -4
  20. package/__TEST__/order/validateConditionsCalculate.test.js +397 -0
  21. package/lib/constants/index.js +1 -1
  22. package/lib/index.js +11 -2
  23. package/lib/item/calculate.js +27 -10
  24. package/lib/item/getItemModifiersDescription.js +40 -7
  25. package/lib/item/markModifiersAsLocked.js +3 -1
  26. package/lib/modifier/areConditionsMet.js +71 -0
  27. package/lib/modifier/getGroupedModifierLabels.js +10 -0
  28. package/lib/modifier/getGroupedModifiers.js +21 -0
  29. package/lib/modifier/getNotesToModifierTags.js +21 -0
  30. package/lib/modifier/index.js +22 -5
  31. package/lib/modifier/isOptionsOverride.js +9 -0
  32. package/lib/modifier/isPaymentMethodModifier.js +1 -1
  33. package/lib/modifier/isPaymentTypeModifier.js +1 -1
  34. package/lib/modifier/isValid.js +12 -0
  35. package/lib/modifier/validate.js +14 -0
  36. package/lib/modifier/validateDateDaysDiff.js +30 -0
  37. package/lib/modifier/validateInArr.js +12 -0
  38. package/lib/modifier/validateNumberCondition.js +20 -0
  39. package/lib/modifier/validateRequiredModifiers.js +16 -0
  40. package/lib/order/addItemModifier.js +72 -28
  41. package/lib/order/calculate.js +12 -7
  42. package/lib/order/index.js +0 -2
  43. package/lib/order/removeModifiersWithPaymentMethods.js +1 -2
  44. package/lib/order/removeModifiersWithPaymentTypes.js +1 -2
  45. package/lib/store/getRecommendedEndDate.js +13 -0
  46. package/lib/store/index.js +25 -0
  47. package/lib/store/pickEndDate.js +62 -0
  48. package/package.json +3 -3
  49. package/lib/modifier/findByPaymentMethod.js +0 -10
  50. package/lib/modifier/findByPaymentType.js +0 -10
  51. package/lib/order/pickEndDate.js +0 -65
@@ -1,53 +1,49 @@
1
1
  [
2
- {
3
- "__typename": "Modifier",
4
- "addModifiers": [],
5
- "delModifiers": [],
6
- "conditions": {
7
- "__typename": "Conditions",
8
- "paymentTypes": [
9
- "cash"
10
- ],
11
- "paymentMethods": [],
12
- "modifiers": [],
13
- "minItemQuantity": 0,
14
- "minItemPieces": 0
15
- },
16
- "compute": {
17
- "__typename": "Compute",
18
- "type": "fixed",
19
- "action": "add",
20
- "amount": 2
21
- },
22
- "_createdAt": "2022-11-08T16:09:49.227Z",
23
- "_updatedAt": "2022-11-28T18:44:16.821Z",
24
- "_id": "636a7f3ec19c040636f3da9a",
25
- "modifierId": null,
26
- "_parentId": null,
27
- "locked": false,
28
- "name": "Cash fee",
29
- "sku": "",
30
- "description": "",
31
- "group": "",
32
- "type": "fee",
33
- "attributes": [],
34
- "color": "",
35
- "backgroundColor": "",
36
- "icon": "",
37
- "url": "",
38
- "tags": [
39
- "default"
40
- ],
41
- "order": 0,
42
- "included": false,
43
- "direct": true,
44
- "hidden": false,
45
- "print": true,
46
- "required": false,
47
- "recommended": false,
48
- "default": false,
49
- "code": "",
50
- "properties": null,
51
- "_computed": null
52
- }
53
- ]
2
+ {
3
+ "__typename": "Modifier",
4
+ "addModifiers": [],
5
+ "delModifiers": [],
6
+ "conditions": {
7
+ "rules": [ {
8
+ "key": "paymentTypes",
9
+ "operand": "$in",
10
+ "value": ["cash"]
11
+ }
12
+ ]
13
+ },
14
+ "compute": {
15
+ "__typename": "Compute",
16
+ "type": "fixed",
17
+ "action": "add",
18
+ "amount": 2
19
+ },
20
+ "_createdAt": "2022-11-08T16:09:49.227Z",
21
+ "_updatedAt": "2022-11-28T18:44:16.821Z",
22
+ "_id": "636a7f3ec19c040636f3da9a",
23
+ "modifierId": null,
24
+ "_parentId": null,
25
+ "locked": false,
26
+ "name": "Cash fee",
27
+ "sku": "",
28
+ "description": "",
29
+ "group": "",
30
+ "type": "fee",
31
+ "attributes": [],
32
+ "color": "",
33
+ "backgroundColor": "",
34
+ "icon": "",
35
+ "url": "",
36
+ "tags": ["default"],
37
+ "order": 0,
38
+ "included": false,
39
+ "direct": true,
40
+ "hidden": false,
41
+ "print": true,
42
+ "required": false,
43
+ "recommended": false,
44
+ "default": false,
45
+ "code": "",
46
+ "properties": null,
47
+ "_computed": null
48
+ }
49
+ ]
@@ -1,6 +1,7 @@
1
1
  const usePricing = require('../../index');
2
2
 
3
3
  const { getComputeModField } = require('../../lib/modifier/utils');
4
+
4
5
  const pricingService = usePricing();
5
6
 
6
7
  describe('Calculate Function', () => {
@@ -0,0 +1,95 @@
1
+ const getGroupedModifierLabelsFunction = require('../../lib/modifier/getGroupedModifierLabels');
2
+
3
+ describe('getGroupedModifierLabels Function', () => {
4
+ const actions = {
5
+ getGroupedModifiers: jest.fn(),
6
+ };
7
+
8
+ const getGroupedModifierLabels = getGroupedModifierLabelsFunction({
9
+ actions,
10
+ });
11
+
12
+ beforeEach(() => {
13
+ jest.clearAllMocks();
14
+ });
15
+
16
+ test('should return an empty array if no modifiers are provided', () => {
17
+ actions.getGroupedModifiers.mockReturnValueOnce([]);
18
+
19
+ const result = getGroupedModifierLabels([]);
20
+
21
+ expect(result).toEqual([]);
22
+ expect(actions.getGroupedModifiers).toHaveBeenCalledWith([]);
23
+ });
24
+
25
+ test('should map modifiers to labels and group them by modifierId', () => {
26
+ const modifiers = [
27
+ { name: 'Modifier 1', modifierId: 'mod1' },
28
+ { name: 'Modifier 2', modifierId: 'mod2' },
29
+ ];
30
+
31
+ const groupedModifiers = [
32
+ { label: '1 Modifier 1', value: 'mod1', data: modifiers[0], quantity: 1 },
33
+ { label: '1 Modifier 2', value: 'mod2', data: modifiers[1], quantity: 1 },
34
+ ];
35
+
36
+ actions.getGroupedModifiers.mockReturnValueOnce(groupedModifiers);
37
+
38
+ const result = getGroupedModifierLabels(modifiers);
39
+
40
+ expect(result).toEqual(['1 Modifier 1', '1 Modifier 2']);
41
+ expect(actions.getGroupedModifiers).toHaveBeenCalledWith([
42
+ { label: 'Modifier 1', value: 'mod1', data: modifiers[0], quantity: 1 },
43
+ { label: 'Modifier 2', value: 'mod2', data: modifiers[1], quantity: 1 },
44
+ ]);
45
+ });
46
+
47
+ test('should group modifiers with the same modifierId and increment quantity', () => {
48
+ const modifiers = [
49
+ { name: 'Modifier 1', modifierId: 'mod1' },
50
+ { name: 'Modifier 1', modifierId: 'mod1' }, // Same modifierId
51
+ ];
52
+
53
+ const groupedModifiers = [
54
+ { label: '2 Modifier 1', value: 'mod1', data: modifiers[0], quantity: 2 },
55
+ ];
56
+
57
+ actions.getGroupedModifiers.mockReturnValueOnce(groupedModifiers);
58
+
59
+ const result = getGroupedModifierLabels(modifiers);
60
+
61
+ expect(result).toEqual(['2 Modifier 1']);
62
+ expect(actions.getGroupedModifiers).toHaveBeenCalledWith([
63
+ { label: 'Modifier 1', value: 'mod1', data: modifiers[0], quantity: 1 },
64
+ { label: 'Modifier 1', value: 'mod1', data: modifiers[1], quantity: 1 },
65
+ ]);
66
+ });
67
+
68
+ test('should handle a single modifier correctly', () => {
69
+ const modifiers = [{ name: 'Modifier 1', modifierId: 'mod1' }];
70
+
71
+ const groupedModifiers = [
72
+ { label: '1 Modifier 1', value: 'mod1', data: modifiers[0], quantity: 1 },
73
+ ];
74
+
75
+ actions.getGroupedModifiers.mockReturnValueOnce(groupedModifiers);
76
+
77
+ const result = getGroupedModifierLabels(modifiers);
78
+
79
+ expect(result).toEqual(['1 Modifier 1']);
80
+ expect(actions.getGroupedModifiers).toHaveBeenCalledWith([
81
+ { label: 'Modifier 1', value: 'mod1', data: modifiers[0], quantity: 1 },
82
+ ]);
83
+ });
84
+
85
+ test('should correctly handle an empty modifiers array', () => {
86
+ const modifiers = [];
87
+
88
+ actions.getGroupedModifiers.mockReturnValueOnce([]);
89
+
90
+ const result = getGroupedModifierLabels(modifiers);
91
+
92
+ expect(result).toEqual([]);
93
+ expect(actions.getGroupedModifiers).toHaveBeenCalledWith([]);
94
+ });
95
+ });
@@ -0,0 +1,65 @@
1
+ const getGroupedModifiersFunction = require('../../lib/modifier/getGroupedModifiers');
2
+
3
+ describe('getGroupedModifiers Function', () => {
4
+ const getGroupedModifiers = getGroupedModifiersFunction();
5
+
6
+ test('should return an empty array if no tags are provided', () => {
7
+ const result = getGroupedModifiers([]);
8
+ expect(result).toEqual([]);
9
+ });
10
+
11
+ test('should group modifiers by modifierId and increment quantity', () => {
12
+ const tags = [
13
+ { label: 'Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
14
+ { label: 'Modifier 2', data: { modifierId: 'mod2' }, quantity: 1 },
15
+ { label: 'Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
16
+ ];
17
+
18
+ const result = getGroupedModifiers(tags);
19
+
20
+ expect(result).toEqual([
21
+ { label: '2 Modifier 1', data: { modifierId: 'mod1' }, quantity: 2 },
22
+ { label: '1 Modifier 2', data: { modifierId: 'mod2' }, quantity: 1 },
23
+ ]);
24
+ });
25
+
26
+ test('should correctly handle tags with different modifierIds', () => {
27
+ const tags = [
28
+ { label: 'Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
29
+ { label: 'Modifier 2', data: { modifierId: 'mod2' }, quantity: 1 },
30
+ ];
31
+
32
+ const result = getGroupedModifiers(tags);
33
+
34
+ expect(result).toEqual([
35
+ { label: '1 Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
36
+ { label: '1 Modifier 2', data: { modifierId: 'mod2' }, quantity: 1 },
37
+ ]);
38
+ });
39
+
40
+ test('should not modify original tags array', () => {
41
+ const tags = [
42
+ { label: 'Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
43
+ { label: 'Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
44
+ ];
45
+
46
+ const originalTagsCopy = [...tags];
47
+
48
+ getGroupedModifiers(tags);
49
+
50
+ expect(tags).toEqual(originalTagsCopy); // Ensure original array is not mutated
51
+ });
52
+
53
+ test('should format the label to include the quantity', () => {
54
+ const tags = [
55
+ { label: 'Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
56
+ { label: 'Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
57
+ ];
58
+
59
+ const result = getGroupedModifiers(tags);
60
+
61
+ expect(result).toEqual([
62
+ { label: '2 Modifier 1', data: { modifierId: 'mod1' }, quantity: 2 },
63
+ ]);
64
+ });
65
+ });
@@ -10,45 +10,75 @@ describe('GetMatchTagsModifiers Function', () => {
10
10
  const customer = {};
11
11
  let modifiers = [];
12
12
  expect(
13
- pricingService.modifier.getMatchTagsModifiers({ modifiers, entity: customer })
13
+ pricingService.modifier.getMatchTagsModifiers({
14
+ modifiers,
15
+ entity: customer,
16
+ })
14
17
  ).toHaveLength(0);
15
18
  customer.tags = [];
16
19
  modifiers = [{ tags: [] }];
17
20
  expect(
18
- pricingService.modifier.getMatchTagsModifiers({ modifiers, entity: customer })
21
+ pricingService.modifier.getMatchTagsModifiers({
22
+ modifiers,
23
+ entity: customer,
24
+ })
19
25
  ).toHaveLength(1);
20
26
  customer.tags = ['all'];
21
27
  expect(
22
- pricingService.modifier.getMatchTagsModifiers({ modifiers, entity: customer })
28
+ pricingService.modifier.getMatchTagsModifiers({
29
+ modifiers,
30
+ entity: customer,
31
+ })
23
32
  ).toHaveLength(1);
24
33
  modifiers = [{ tags: ['test'] }];
25
34
  expect(
26
- pricingService.modifier.getMatchTagsModifiers({ modifiers, entity: customer })
35
+ pricingService.modifier.getMatchTagsModifiers({
36
+ modifiers,
37
+ entity: customer,
38
+ })
27
39
  ).toHaveLength(0);
28
40
  modifiers = [{ tags: ['all'] }, { tags: ['test'] }];
29
41
  expect(
30
- pricingService.modifier.getMatchTagsModifiers({ modifiers, entity: customer })
42
+ pricingService.modifier.getMatchTagsModifiers({
43
+ modifiers,
44
+ entity: customer,
45
+ })
31
46
  ).toHaveLength(1);
32
47
  modifiers = [{ tags: ['all'] }, { tags: ['test'] }, { tags: [] }];
33
48
  expect(
34
- pricingService.modifier.getMatchTagsModifiers({ modifiers, entity: customer })
49
+ pricingService.modifier.getMatchTagsModifiers({
50
+ modifiers,
51
+ entity: customer,
52
+ })
35
53
  ).toHaveLength(2);
36
54
  customer.tags = ['test'];
37
55
  modifiers = [{ tags: [] }];
38
56
  expect(
39
- pricingService.modifier.getMatchTagsModifiers({ modifiers, entity: customer })
57
+ pricingService.modifier.getMatchTagsModifiers({
58
+ modifiers,
59
+ entity: customer,
60
+ })
40
61
  ).toHaveLength(0);
41
62
  modifiers = [{ tags: ['test'] }];
42
63
  expect(
43
- pricingService.modifier.getMatchTagsModifiers({ modifiers, entity: customer })
64
+ pricingService.modifier.getMatchTagsModifiers({
65
+ modifiers,
66
+ entity: customer,
67
+ })
44
68
  ).toHaveLength(1);
45
69
  modifiers = [{ tags: ['all'] }, { tags: ['test'] }];
46
70
  expect(
47
- pricingService.modifier.getMatchTagsModifiers({ modifiers, entity: customer })
71
+ pricingService.modifier.getMatchTagsModifiers({
72
+ modifiers,
73
+ entity: customer,
74
+ })
48
75
  ).toHaveLength(1);
49
76
  modifiers = [{ tags: ['all'] }, { tags: ['test'] }, { tags: [] }];
50
77
  expect(
51
- pricingService.modifier.getMatchTagsModifiers({ modifiers, entity: customer })
78
+ pricingService.modifier.getMatchTagsModifiers({
79
+ modifiers,
80
+ entity: customer,
81
+ })
52
82
  ).toHaveLength(1);
53
83
  modifiers = [
54
84
  { tags: ['all'] },
@@ -57,7 +87,10 @@ describe('GetMatchTagsModifiers Function', () => {
57
87
  { tags: ['Test'] },
58
88
  ];
59
89
  expect(
60
- pricingService.modifier.getMatchTagsModifiers({ modifiers, entity: customer })
90
+ pricingService.modifier.getMatchTagsModifiers({
91
+ modifiers,
92
+ entity: customer,
93
+ })
61
94
  ).toHaveLength(1);
62
95
  modifiers = [
63
96
  { tags: ['all'] },
@@ -67,15 +100,24 @@ describe('GetMatchTagsModifiers Function', () => {
67
100
  { tags: ['test', 'Test'] },
68
101
  ];
69
102
  expect(
70
- pricingService.modifier.getMatchTagsModifiers({ modifiers, entity: customer })
103
+ pricingService.modifier.getMatchTagsModifiers({
104
+ modifiers,
105
+ entity: customer,
106
+ })
71
107
  ).toHaveLength(2);
72
108
  modifiers = [{ tags: ['all'] }];
73
109
  expect(
74
- pricingService.modifier.getMatchTagsModifiers({ modifiers, entity: customer })
110
+ pricingService.modifier.getMatchTagsModifiers({
111
+ modifiers,
112
+ entity: customer,
113
+ })
75
114
  ).toHaveLength(0);
76
115
  modifiers = [{ tags: ['all'] }, { tags: ['test'] }];
77
116
  expect(
78
- pricingService.modifier.getMatchTagsModifiers({ modifiers, entity: customer })
117
+ pricingService.modifier.getMatchTagsModifiers({
118
+ modifiers,
119
+ entity: customer,
120
+ })
79
121
  ).toHaveLength(1);
80
122
  modifiers = [
81
123
  { tags: ['all'] },
@@ -84,11 +126,17 @@ describe('GetMatchTagsModifiers Function', () => {
84
126
  {},
85
127
  ];
86
128
  expect(
87
- pricingService.modifier.getMatchTagsModifiers({ modifiers, entity: customer })
129
+ pricingService.modifier.getMatchTagsModifiers({
130
+ modifiers,
131
+ entity: customer,
132
+ })
88
133
  ).toHaveLength(2);
89
134
  customer.tags = ['all'];
90
135
  expect(
91
- pricingService.modifier.getMatchTagsModifiers({ modifiers, entity: customer })
136
+ pricingService.modifier.getMatchTagsModifiers({
137
+ modifiers,
138
+ entity: customer,
139
+ })
92
140
  ).toHaveLength(2);
93
141
  modifiers = [
94
142
  { tags: ['all'] },
@@ -99,11 +147,17 @@ describe('GetMatchTagsModifiers Function', () => {
99
147
  {},
100
148
  ];
101
149
  expect(
102
- pricingService.modifier.getMatchTagsModifiers({ modifiers, entity: customer })
150
+ pricingService.modifier.getMatchTagsModifiers({
151
+ modifiers,
152
+ entity: customer,
153
+ })
103
154
  ).toHaveLength(5);
104
155
  customer.tags = undefined;
105
156
  expect(
106
- pricingService.modifier.getMatchTagsModifiers({ modifiers, entity: customer })
157
+ pricingService.modifier.getMatchTagsModifiers({
158
+ modifiers,
159
+ entity: customer,
160
+ })
107
161
  ).toHaveLength(5);
108
162
  });
109
163
  });
@@ -12,7 +12,10 @@ describe('GetModifierIndex Function', () => {
12
12
  ).toBe(-1);
13
13
  const order = { modifiers: [{ modifierId: '123' }] };
14
14
  expect(
15
- pricingService.modifier.getModifierIndex({ entity: order, modifier: undefined })
15
+ pricingService.modifier.getModifierIndex({
16
+ entity: order,
17
+ modifier: undefined,
18
+ })
16
19
  ).toBe(-1);
17
20
  const modifier = { _id: '123' };
18
21
  expect(
@@ -29,12 +32,12 @@ describe('GetModifierIndex Function', () => {
29
32
  })
30
33
  ).toBe(-1);
31
34
  order.modifiers = [{ modifierId: '123' }, { modifierId: '234' }];
32
- expect(pricingService.modifier.getModifierIndex({ entity: order, modifier })).toBe(
33
- 1
34
- );
35
+ expect(
36
+ pricingService.modifier.getModifierIndex({ entity: order, modifier })
37
+ ).toBe(1);
35
38
  modifier._id = '123';
36
- expect(pricingService.modifier.getModifierIndex({ entity: order, modifier })).toBe(
37
- 0
38
- );
39
+ expect(
40
+ pricingService.modifier.getModifierIndex({ entity: order, modifier })
41
+ ).toBe(0);
39
42
  });
40
43
  });
@@ -0,0 +1,78 @@
1
+ const getNotesToModifierTagsFunction = require('../../lib/modifier/getNotesToModifierTags');
2
+
3
+ describe('getNotesToModifierTags Function', () => {
4
+ const getNotesToModifierTags = getNotesToModifierTagsFunction();
5
+
6
+ test('should return modifierTags if no notes are provided', () => {
7
+ const modifierTags = [
8
+ { label: 'Modifier 1', value: 'mod1', data: {}, quantity: 1 },
9
+ ];
10
+
11
+ const result = getNotesToModifierTags({ notes: null, modifierTags });
12
+ expect(result).toEqual(modifierTags);
13
+ });
14
+
15
+ test('should return modifierTags if notes array is empty', () => {
16
+ const modifierTags = [
17
+ { label: 'Modifier 1', value: 'mod1', data: {}, quantity: 1 },
18
+ ];
19
+
20
+ const result = getNotesToModifierTags({ notes: [], modifierTags });
21
+ expect(result).toEqual(modifierTags);
22
+ });
23
+
24
+ test('should filter out notes that are null or have a url', () => {
25
+ const notes = [
26
+ { message: 'Note 1' },
27
+ { message: 'Note 2', url: 'http://example.com' }, // Should be filtered out
28
+ null, // Should be filtered out
29
+ ];
30
+
31
+ const modifierTags = [
32
+ { label: 'Modifier 1', value: 'mod1', data: {}, quantity: 1 },
33
+ ];
34
+
35
+ const result = getNotesToModifierTags({ notes, modifierTags });
36
+
37
+ expect(result).toEqual([
38
+ { label: 'Modifier 1', value: 'mod1', data: {}, quantity: 1 },
39
+ { label: 'Note 1', value: '0', data: { message: 'Note 1' }, quantity: 1 },
40
+ ]);
41
+ });
42
+
43
+ test('should map notes to noteTags and append to modifierTags', () => {
44
+ const notes = [{ message: 'Note 1' }, { message: 'Note 2' }];
45
+
46
+ const modifierTags = [
47
+ { label: 'Modifier 1', value: 'mod1', data: {}, quantity: 1 },
48
+ ];
49
+
50
+ const result = getNotesToModifierTags({ notes, modifierTags });
51
+
52
+ expect(result).toEqual([
53
+ { label: 'Modifier 1', value: 'mod1', data: {}, quantity: 1 },
54
+ { label: 'Note 1', value: '0', data: { message: 'Note 1' }, quantity: 1 },
55
+ { label: 'Note 2', value: '1', data: { message: 'Note 2' }, quantity: 1 },
56
+ ]);
57
+ });
58
+
59
+ test('should handle case where notes contain falsy values', () => {
60
+ const notes = [null, undefined, { message: 'Valid Note' }];
61
+
62
+ const modifierTags = [
63
+ { label: 'Modifier 1', value: 'mod1', data: {}, quantity: 1 },
64
+ ];
65
+
66
+ const result = getNotesToModifierTags({ notes, modifierTags });
67
+
68
+ expect(result).toEqual([
69
+ { label: 'Modifier 1', value: 'mod1', data: {}, quantity: 1 },
70
+ {
71
+ label: 'Valid Note',
72
+ value: '0',
73
+ data: { message: 'Valid Note' },
74
+ quantity: 1,
75
+ },
76
+ ]);
77
+ });
78
+ });
@@ -5,13 +5,15 @@ const pricingService = usePricing();
5
5
  describe('GetRecommendedModifiers Function', () => {
6
6
  test('usecases', () => {
7
7
  const modifier = { modifier: { recommended: true } };
8
- expect(pricingService.modifier.getRecommendedModifiers([modifier])).toHaveLength(1);
8
+ expect(
9
+ pricingService.modifier.getRecommendedModifiers([modifier])
10
+ ).toHaveLength(1);
9
11
 
10
12
  const modifier2 = {
11
13
  modifier: { modifier: { _id: 1 } },
12
14
  };
13
- expect(pricingService.modifier.getRecommendedModifiers([modifier2])).toHaveLength(
14
- 0
15
- );
15
+ expect(
16
+ pricingService.modifier.getRecommendedModifiers([modifier2])
17
+ ).toHaveLength(0);
16
18
  });
17
19
  });
@@ -7,17 +7,23 @@ describe('Has Modifiers Function', () => {
7
7
  expect(pricingService.modifier.hasAttribute()).toBe(false);
8
8
  expect(pricingService.modifier.hasAttribute(undefined, 'test')).toBe(false);
9
9
  expect(pricingService.modifier.hasAttribute({}, undefined)).toBe(false);
10
- expect(pricingService.modifier.hasAttribute({ attributes: [] }, undefined)).toBe(
11
- false
12
- );
13
10
  expect(
14
- pricingService.modifier.hasAttribute({ attributes: [undefined] }, undefined)
11
+ pricingService.modifier.hasAttribute({ attributes: [] }, undefined)
12
+ ).toBe(false);
13
+ expect(
14
+ pricingService.modifier.hasAttribute(
15
+ { attributes: [undefined] },
16
+ undefined
17
+ )
15
18
  ).toBe(false);
16
19
  expect(
17
20
  pricingService.modifier.hasAttribute({ attributes: ['test'] }, undefined)
18
21
  ).toBe(false);
19
22
  expect(
20
- pricingService.modifier.hasAttribute({ attributes: ['undefined'] }, undefined)
23
+ pricingService.modifier.hasAttribute(
24
+ { attributes: ['undefined'] },
25
+ undefined
26
+ )
21
27
  ).toBe(false);
22
28
  expect(
23
29
  pricingService.modifier.hasAttribute(