@darkpos/pricing 1.0.72 → 1.0.73
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/__TEST__/item.test.js +8 -9
- package/__TEST__/manualTest.test.js +91 -0
- package/__TEST__/modifier/getInvalidRequiredModifiers.test.js +9 -3605
- package/__TEST__/modifier/hasModifier.test.js +2 -12
- package/lib/item/getInvalidRequiredModifiers.js +1 -1
- package/lib/item/hasModifier.js +27 -27
- package/lib/item/removeModifier.js +0 -1
- package/lib/modifier/index.js +2 -0
- package/lib/modifier/removeGroupRelations.js +22 -0
- package/lib/order/addItemModifier.js +1 -1
- package/lib/order/removeItem.js +0 -1
- package/package.json +3 -2
package/__TEST__/item.test.js
CHANGED
|
@@ -1138,7 +1138,6 @@ describe('Item actions', () => {
|
|
|
1138
1138
|
test('Should add related item and its related addModifiers to the parent item, then removing that relateditem should also remove the mod from the parent item', () => {
|
|
1139
1139
|
const rawRelatedItem1 = {
|
|
1140
1140
|
name: 'the related item',
|
|
1141
|
-
|
|
1142
1141
|
_id: '67e2cadd8dcf08ebcc5ef888',
|
|
1143
1142
|
};
|
|
1144
1143
|
|
|
@@ -1154,7 +1153,7 @@ describe('Item actions', () => {
|
|
|
1154
1153
|
modifierId: 'mod1',
|
|
1155
1154
|
properties: {
|
|
1156
1155
|
group: {
|
|
1157
|
-
items: [
|
|
1156
|
+
items: [],
|
|
1158
1157
|
},
|
|
1159
1158
|
},
|
|
1160
1159
|
};
|
|
@@ -1176,7 +1175,7 @@ describe('Item actions', () => {
|
|
|
1176
1175
|
parentId: parentItem._id,
|
|
1177
1176
|
includeParent: true,
|
|
1178
1177
|
addModifiers: [groupMod],
|
|
1179
|
-
|
|
1178
|
+
groupPath: ',67e2cadd8dcf08ebcc5ef889',
|
|
1180
1179
|
},
|
|
1181
1180
|
__typename: 'OrderItem',
|
|
1182
1181
|
};
|
|
@@ -1188,7 +1187,7 @@ describe('Item actions', () => {
|
|
|
1188
1187
|
parentId: parentItem._id,
|
|
1189
1188
|
includeParent: true,
|
|
1190
1189
|
addModifiers: [groupMod],
|
|
1191
|
-
|
|
1190
|
+
groupPath: ',67e2cadd8dcf08ebcc5ef889',
|
|
1192
1191
|
},
|
|
1193
1192
|
__typename: 'OrderItem',
|
|
1194
1193
|
};
|
|
@@ -1237,7 +1236,7 @@ describe('Item actions', () => {
|
|
|
1237
1236
|
modifierId: 'mod1',
|
|
1238
1237
|
properties: {
|
|
1239
1238
|
group: {
|
|
1240
|
-
items: [
|
|
1239
|
+
items: [],
|
|
1241
1240
|
},
|
|
1242
1241
|
},
|
|
1243
1242
|
},
|
|
@@ -1251,8 +1250,8 @@ describe('Item actions', () => {
|
|
|
1251
1250
|
modifierId: 'mod1',
|
|
1252
1251
|
properties: {
|
|
1253
1252
|
group: {
|
|
1254
|
-
items: [
|
|
1255
|
-
modifiers: [
|
|
1253
|
+
items: [],
|
|
1254
|
+
modifiers: [],
|
|
1256
1255
|
},
|
|
1257
1256
|
},
|
|
1258
1257
|
};
|
|
@@ -1274,7 +1273,7 @@ describe('Item actions', () => {
|
|
|
1274
1273
|
parentId: parentItem._id,
|
|
1275
1274
|
includeParent: true,
|
|
1276
1275
|
addModifiers: [groupMod],
|
|
1277
|
-
|
|
1276
|
+
groupPath: ',67e2cadd8dcf08ebcc5ef889',
|
|
1278
1277
|
},
|
|
1279
1278
|
__typename: 'OrderItem',
|
|
1280
1279
|
};
|
|
@@ -1286,7 +1285,7 @@ describe('Item actions', () => {
|
|
|
1286
1285
|
parentId: parentItem._id,
|
|
1287
1286
|
includeParent: true,
|
|
1288
1287
|
addModifiers: [groupMod],
|
|
1289
|
-
|
|
1288
|
+
groupPath: ',67e2cadd8dcf08ebcc5ef889',
|
|
1290
1289
|
},
|
|
1291
1290
|
__typename: 'OrderItem',
|
|
1292
1291
|
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const usePricing = require('../index');
|
|
2
|
+
const mockStores = require('./mocks/stores');
|
|
3
|
+
|
|
4
|
+
const session = {
|
|
5
|
+
store: mockStores[0],
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const pricingService = usePricing(session);
|
|
9
|
+
|
|
10
|
+
describe('Manual actions', () => {
|
|
11
|
+
test('Should add related item and its related addModifiers to the parent item, then removing that relateditem should also remove the mod from the parent item', () => {
|
|
12
|
+
const rawRelatedItem1 = {
|
|
13
|
+
name: 'the related item',
|
|
14
|
+
_id: '67e2cadd8dcf08ebcc5ef888',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const rawRelatedItem2 = {
|
|
18
|
+
name: 'the 2nd related item',
|
|
19
|
+
_id: '67e2cadd8dcf08ebcc5ef88a',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const groupMod = {
|
|
23
|
+
_id: '67e2cadd8dcf08ebcc5ef889',
|
|
24
|
+
name: 'General Repair Department',
|
|
25
|
+
attributes: ['group'],
|
|
26
|
+
modifierId: 'mod1',
|
|
27
|
+
properties: {
|
|
28
|
+
group: {
|
|
29
|
+
items: [],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const parentItem = {
|
|
35
|
+
name: 'the parent item',
|
|
36
|
+
modifiers: [groupMod],
|
|
37
|
+
_id: '67e2cadd8dcf08ebcc5ef887',
|
|
38
|
+
__typename: 'OrderItem',
|
|
39
|
+
properties: {
|
|
40
|
+
basePrice: 100,
|
|
41
|
+
},
|
|
42
|
+
itemId: 'abcd123',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const relatedItem1 = {
|
|
46
|
+
...rawRelatedItem1,
|
|
47
|
+
properties: {
|
|
48
|
+
relatedItem: true,
|
|
49
|
+
parentId: parentItem._id,
|
|
50
|
+
parentItemId: parentItem.itemId,
|
|
51
|
+
includeParent: true,
|
|
52
|
+
addModifiers: [groupMod],
|
|
53
|
+
groupPath: ',67e2cadd8dcf08ebcc5ef889',
|
|
54
|
+
},
|
|
55
|
+
__typename: 'OrderItem',
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const relatedItem2 = {
|
|
59
|
+
...rawRelatedItem2,
|
|
60
|
+
properties: {
|
|
61
|
+
relatedItem: true,
|
|
62
|
+
parentId: parentItem._id,
|
|
63
|
+
parentItemId: parentItem.itemId,
|
|
64
|
+
includeParent: true,
|
|
65
|
+
addModifiers: [groupMod],
|
|
66
|
+
groupPath: ',67e2cadd8dcf08ebcc5ef889',
|
|
67
|
+
},
|
|
68
|
+
__typename: 'OrderItem',
|
|
69
|
+
};
|
|
70
|
+
const order = {
|
|
71
|
+
items: [parentItem, relatedItem1, relatedItem2],
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const result = pricingService.order.removeItem({
|
|
75
|
+
order,
|
|
76
|
+
item: relatedItem2,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
expect(result.items.length).toBe(2);
|
|
80
|
+
expect(result.items[0].modifiers.length).toBe(1);
|
|
81
|
+
expect(result.items[0].modifiers[0].modifierId).toBe('mod1');
|
|
82
|
+
|
|
83
|
+
// const result2 = pricingService.order.removeItem({
|
|
84
|
+
// order: result,
|
|
85
|
+
// item: relatedItem1,
|
|
86
|
+
// });
|
|
87
|
+
|
|
88
|
+
// expect(result2.items.length).toBe(1);
|
|
89
|
+
// expect(result2.items[0].modifiers.length).toBe(0);
|
|
90
|
+
});
|
|
91
|
+
});
|