@darkpos/pricing 1.0.79 → 1.0.81
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__/modifier.test.js +584 -15
- package/__TEST__/order/conditionsNotMet.test.js +204 -0
- package/__TEST__/order/order.test.js +61 -8
- package/lib/item/adjustCreditModifiersDifference.js +34 -0
- package/lib/item/adjustFixedModifiersDifference.js +37 -0
- package/lib/item/getItemsTotals.js +2 -2
- package/lib/item/getModifierTags.js +1 -1
- package/lib/item/getSubtotal.js +5 -0
- package/lib/item/index.js +14 -0
- package/lib/item/removeModifiersByQuantity.js +5 -4
- package/lib/item/splitAndCalculate.js +18 -0
- package/lib/item/spreadModifiers.js +21 -0
- package/lib/item/validateCreditModifiersTotal.js +23 -0
- package/lib/item/validateFixedModifiersTotal.js +23 -0
- package/lib/modifier/areConditionsMet.js +13 -10
- package/lib/modifier/getCreditModifiersTotalEntities.js +12 -0
- package/lib/modifier/getFixedModifiersTotalEntities.js +12 -0
- package/lib/modifier/getMaxItemQuantity.js +5 -0
- package/lib/modifier/getMaxItemUse.js +5 -0
- package/lib/modifier/getMaxOrderUse.js +5 -0
- package/lib/modifier/getSplittedModifiers.js +15 -30
- package/lib/modifier/index.js +16 -8
- package/lib/modifier/isOrderUseValid.js +25 -0
- package/lib/modifier/isUnlimitedItemUse.js +4 -0
- package/lib/modifier/isUnlimitedOrderUse.js +4 -0
- package/lib/order/addItemModifier.js +27 -4
- package/lib/order/addModifier.js +8 -18
- package/lib/order/index.js +2 -4
- package/lib/order/splitItems.js +50 -0
- package/lib/order/validateCreditModifiersTotal.js +1 -1
- package/lib/order/validateFixedModifiersTotal.js +1 -1
- package/package.json +2 -2
- package/lib/modifier/getMaxAppliesItem.js +0 -5
- package/lib/modifier/getMaxAppliesOrder.js +0 -5
- package/lib/modifier/isUnlimitedAppliesItem.js +0 -6
- package/lib/modifier/isUnlimitedAppliesOrder.js +0 -6
- package/lib/order/getCreditModifiersTotal.js +0 -15
- package/lib/order/getFixedModifiersTotal.js +0 -15
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
const usePricing = require('../index');
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const mockStores = require('./mocks/stores');
|
|
4
|
+
|
|
5
|
+
const session = {
|
|
6
|
+
store: mockStores[0],
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const pricingService = usePricing(session);
|
|
4
10
|
|
|
5
11
|
describe('Modifier actions', () => {
|
|
6
12
|
test('CU-86dv8hzxg modifier.isGroup fn', () => {
|
|
@@ -874,7 +880,7 @@ describe('Modifier actions', () => {
|
|
|
874
880
|
});
|
|
875
881
|
});
|
|
876
882
|
|
|
877
|
-
test('CU-86dve295v Should throw error when adding a modifier more times than the ones specified in properties.limits.
|
|
883
|
+
test('CU-86dve295v Should throw error when adding a modifier more times than the ones specified in properties.limits.maxItemUse', () => {
|
|
878
884
|
const order = {
|
|
879
885
|
id: 'ord-123',
|
|
880
886
|
items: [],
|
|
@@ -889,7 +895,7 @@ describe('Modifier actions', () => {
|
|
|
889
895
|
},
|
|
890
896
|
properties: {
|
|
891
897
|
isQuantityMultiplier: true,
|
|
892
|
-
limits: {
|
|
898
|
+
limits: { maxItemUse: 1 },
|
|
893
899
|
},
|
|
894
900
|
};
|
|
895
901
|
order.items.push({
|
|
@@ -929,18 +935,26 @@ describe('Modifier actions', () => {
|
|
|
929
935
|
|
|
930
936
|
expect(conditionsBag).toEqual([]);
|
|
931
937
|
expect(error).toEqual('modifier.has.reached.the.maximum.amount.of.applies');
|
|
932
|
-
expect(updatedOrder2.items).
|
|
938
|
+
expect(updatedOrder2.items[0].modifiers.length).toBe(1);
|
|
939
|
+
expect(updatedOrder2.items[0].modifiers).toMatchObject([
|
|
933
940
|
{
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
941
|
+
compute: {
|
|
942
|
+
action: 'subtract',
|
|
943
|
+
amount: 10,
|
|
944
|
+
type: 'fixed',
|
|
945
|
+
},
|
|
946
|
+
modifierId: 1,
|
|
947
|
+
properties: {
|
|
948
|
+
isQuantityMultiplier: true,
|
|
949
|
+
limits: {
|
|
950
|
+
maxItemUse: 1,
|
|
951
|
+
},
|
|
952
|
+
},
|
|
939
953
|
},
|
|
940
954
|
]);
|
|
941
955
|
});
|
|
942
956
|
|
|
943
|
-
test('CU-86dve295v Should not throw error when adding a modifier less times than the ones specified in properties.limits.
|
|
957
|
+
test('CU-86dve295v Should not throw error when adding a modifier less times than the ones specified in properties.limits.maxItemUse=5 and isQuantityMultiplier=false', () => {
|
|
944
958
|
const order = {
|
|
945
959
|
id: 'ord-123',
|
|
946
960
|
items: [],
|
|
@@ -955,7 +969,7 @@ describe('Modifier actions', () => {
|
|
|
955
969
|
},
|
|
956
970
|
properties: {
|
|
957
971
|
isQuantityMultiplier: false,
|
|
958
|
-
limits: {
|
|
972
|
+
limits: { maxItemUse: 5 },
|
|
959
973
|
},
|
|
960
974
|
};
|
|
961
975
|
order.items.push({
|
|
@@ -993,7 +1007,116 @@ describe('Modifier actions', () => {
|
|
|
993
1007
|
expect(currentOrder.items[0].modifiers.length).toBe(5);
|
|
994
1008
|
});
|
|
995
1009
|
|
|
996
|
-
test('CU-86dve295v Should not throw error when adding a modifier
|
|
1010
|
+
test('CU-86dve295v Should not throw error when adding a modifier less times than the ones specified in properties.limits.maxItemUse=5 and isQuantityMultiplier=false. Considering also the quantity', () => {
|
|
1011
|
+
const order = {
|
|
1012
|
+
id: 'ord-123',
|
|
1013
|
+
items: [],
|
|
1014
|
+
modifiers: [],
|
|
1015
|
+
};
|
|
1016
|
+
const modifier = {
|
|
1017
|
+
_id: 1,
|
|
1018
|
+
compute: {
|
|
1019
|
+
amount: 10,
|
|
1020
|
+
action: 'subtract',
|
|
1021
|
+
type: 'fixed',
|
|
1022
|
+
},
|
|
1023
|
+
properties: {
|
|
1024
|
+
isQuantityMultiplier: false,
|
|
1025
|
+
limits: { maxItemUse: 5 },
|
|
1026
|
+
},
|
|
1027
|
+
direct: true,
|
|
1028
|
+
};
|
|
1029
|
+
order.items.push({
|
|
1030
|
+
quantity: 2,
|
|
1031
|
+
itemId: '123',
|
|
1032
|
+
price: 100,
|
|
1033
|
+
modifiers: [],
|
|
1034
|
+
});
|
|
1035
|
+
|
|
1036
|
+
const conditionsBag = [];
|
|
1037
|
+
|
|
1038
|
+
let error = '';
|
|
1039
|
+
let currentOrder = { ...order };
|
|
1040
|
+
|
|
1041
|
+
for (let i = 0; i < 10; i += 1) {
|
|
1042
|
+
currentOrder = pricingService.order.addItemModifier({
|
|
1043
|
+
order: currentOrder,
|
|
1044
|
+
modifier,
|
|
1045
|
+
itemIndex: 0,
|
|
1046
|
+
onConditionsNotMet: bag => {
|
|
1047
|
+
bag.forEach(condition => {
|
|
1048
|
+
conditionsBag.push(condition);
|
|
1049
|
+
});
|
|
1050
|
+
},
|
|
1051
|
+
// eslint-disable-next-line no-loop-func
|
|
1052
|
+
onError: errorMessage => {
|
|
1053
|
+
error = errorMessage;
|
|
1054
|
+
},
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
expect(conditionsBag).toEqual([]);
|
|
1059
|
+
expect(error).toEqual('');
|
|
1060
|
+
|
|
1061
|
+
const calculatedOrder = pricingService.order.calculate(currentOrder);
|
|
1062
|
+
|
|
1063
|
+
expect(calculatedOrder.items[0].modifiers.length).toBe(10);
|
|
1064
|
+
});
|
|
1065
|
+
|
|
1066
|
+
test('CU-86dve295v Should throw error when adding a modifier 11 times to an item with quantity=2 and modifier.properties.limits.maxItemUse=5', () => {
|
|
1067
|
+
const order = {
|
|
1068
|
+
id: 'ord-123',
|
|
1069
|
+
items: [],
|
|
1070
|
+
modifiers: [],
|
|
1071
|
+
};
|
|
1072
|
+
const modifier = {
|
|
1073
|
+
_id: 1,
|
|
1074
|
+
compute: {
|
|
1075
|
+
amount: 10,
|
|
1076
|
+
action: 'subtract',
|
|
1077
|
+
type: 'fixed',
|
|
1078
|
+
},
|
|
1079
|
+
properties: {
|
|
1080
|
+
isQuantityMultiplier: false,
|
|
1081
|
+
limits: { maxItemUse: 5 },
|
|
1082
|
+
},
|
|
1083
|
+
};
|
|
1084
|
+
order.items.push({
|
|
1085
|
+
quantity: 2,
|
|
1086
|
+
itemId: '123',
|
|
1087
|
+
price: 100,
|
|
1088
|
+
modifiers: [],
|
|
1089
|
+
});
|
|
1090
|
+
|
|
1091
|
+
const conditionsBag = [];
|
|
1092
|
+
|
|
1093
|
+
let error = '';
|
|
1094
|
+
let currentOrder = { ...order };
|
|
1095
|
+
|
|
1096
|
+
for (let i = 0; i < 11; i += 1) {
|
|
1097
|
+
currentOrder = pricingService.order.addItemModifier({
|
|
1098
|
+
order: currentOrder,
|
|
1099
|
+
modifier,
|
|
1100
|
+
itemIndex: 0,
|
|
1101
|
+
onConditionsNotMet: bag => {
|
|
1102
|
+
bag.forEach(condition => {
|
|
1103
|
+
conditionsBag.push(condition);
|
|
1104
|
+
});
|
|
1105
|
+
},
|
|
1106
|
+
// eslint-disable-next-line no-loop-func
|
|
1107
|
+
onError: errorMessage => {
|
|
1108
|
+
error = errorMessage;
|
|
1109
|
+
},
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
expect(conditionsBag).toEqual([]);
|
|
1114
|
+
expect(error).toEqual('modifier.has.reached.the.maximum.amount.of.applies');
|
|
1115
|
+
|
|
1116
|
+
expect(currentOrder.items[0].modifiers.length).toBe(10);
|
|
1117
|
+
});
|
|
1118
|
+
|
|
1119
|
+
test('CU-86dve295v Should not throw error when adding a modifier if properties.limits.maxItemUse=-1 and isQuantityMultiplier=false', () => {
|
|
997
1120
|
const order = {
|
|
998
1121
|
id: 'ord-123',
|
|
999
1122
|
items: [],
|
|
@@ -1008,7 +1131,7 @@ describe('Modifier actions', () => {
|
|
|
1008
1131
|
},
|
|
1009
1132
|
properties: {
|
|
1010
1133
|
isQuantityMultiplier: false,
|
|
1011
|
-
limits: {
|
|
1134
|
+
limits: { maxItemUse: -1 },
|
|
1012
1135
|
},
|
|
1013
1136
|
};
|
|
1014
1137
|
order.items.push({
|
|
@@ -1046,7 +1169,7 @@ describe('Modifier actions', () => {
|
|
|
1046
1169
|
expect(currentOrder.items[0].modifiers.length).toBe(5);
|
|
1047
1170
|
});
|
|
1048
1171
|
|
|
1049
|
-
test('CU-86dve295v Should not add the modifiers more times than item.quantity if
|
|
1172
|
+
test('CU-86dve295v Should not add the modifiers more times than item.quantity if modifier.properties.limits.maxItemUse is not set', () => {
|
|
1050
1173
|
const order = {
|
|
1051
1174
|
id: 'ord-123',
|
|
1052
1175
|
items: [],
|
|
@@ -1061,7 +1184,7 @@ describe('Modifier actions', () => {
|
|
|
1061
1184
|
},
|
|
1062
1185
|
properties: {
|
|
1063
1186
|
isQuantityMultiplier: false,
|
|
1064
|
-
limits: {
|
|
1187
|
+
limits: { maxItemUse: 0 },
|
|
1065
1188
|
},
|
|
1066
1189
|
};
|
|
1067
1190
|
order.items.push({
|
|
@@ -1098,4 +1221,450 @@ describe('Modifier actions', () => {
|
|
|
1098
1221
|
|
|
1099
1222
|
expect(currentOrder.items[0].modifiers.length).toBe(2);
|
|
1100
1223
|
});
|
|
1224
|
+
|
|
1225
|
+
test('CU-86dve295v Should add the modifier as many times as permitted by properties.limits.maxOrderUse', () => {
|
|
1226
|
+
const order = {
|
|
1227
|
+
id: 'ord-123',
|
|
1228
|
+
items: [],
|
|
1229
|
+
modifiers: [],
|
|
1230
|
+
};
|
|
1231
|
+
const modifier = {
|
|
1232
|
+
_id: 1,
|
|
1233
|
+
compute: {
|
|
1234
|
+
amount: 10,
|
|
1235
|
+
action: 'subtract',
|
|
1236
|
+
type: 'fixed',
|
|
1237
|
+
},
|
|
1238
|
+
properties: {
|
|
1239
|
+
isQuantityMultiplier: false,
|
|
1240
|
+
limits: { maxOrderUse: 3 },
|
|
1241
|
+
},
|
|
1242
|
+
};
|
|
1243
|
+
order.items.push({
|
|
1244
|
+
quantity: 1,
|
|
1245
|
+
itemId: '111',
|
|
1246
|
+
price: 100,
|
|
1247
|
+
modifiers: [],
|
|
1248
|
+
});
|
|
1249
|
+
order.items.push({
|
|
1250
|
+
quantity: 1,
|
|
1251
|
+
itemId: '222',
|
|
1252
|
+
price: 100,
|
|
1253
|
+
modifiers: [],
|
|
1254
|
+
});
|
|
1255
|
+
order.items.push({
|
|
1256
|
+
quantity: 1,
|
|
1257
|
+
itemId: '333',
|
|
1258
|
+
price: 100,
|
|
1259
|
+
modifiers: [],
|
|
1260
|
+
});
|
|
1261
|
+
|
|
1262
|
+
order.items.push({
|
|
1263
|
+
quantity: 1,
|
|
1264
|
+
itemId: '444',
|
|
1265
|
+
price: 100,
|
|
1266
|
+
modifiers: [],
|
|
1267
|
+
});
|
|
1268
|
+
|
|
1269
|
+
const conditionsBag = [];
|
|
1270
|
+
|
|
1271
|
+
let error = '';
|
|
1272
|
+
let currentOrder = { ...order };
|
|
1273
|
+
|
|
1274
|
+
currentOrder = pricingService.order.addItemModifier({
|
|
1275
|
+
order: currentOrder,
|
|
1276
|
+
modifier,
|
|
1277
|
+
itemIndex: 0,
|
|
1278
|
+
onConditionsNotMet: bag => {
|
|
1279
|
+
bag.forEach(condition => {
|
|
1280
|
+
conditionsBag.push(condition);
|
|
1281
|
+
});
|
|
1282
|
+
},
|
|
1283
|
+
onError: errorMessage => {
|
|
1284
|
+
error = errorMessage;
|
|
1285
|
+
},
|
|
1286
|
+
});
|
|
1287
|
+
|
|
1288
|
+
currentOrder = pricingService.order.addItemModifier({
|
|
1289
|
+
order: currentOrder,
|
|
1290
|
+
modifier,
|
|
1291
|
+
itemIndex: 1,
|
|
1292
|
+
onConditionsNotMet: bag => {
|
|
1293
|
+
bag.forEach(condition => {
|
|
1294
|
+
conditionsBag.push(condition);
|
|
1295
|
+
});
|
|
1296
|
+
},
|
|
1297
|
+
onError: errorMessage => {
|
|
1298
|
+
error = errorMessage;
|
|
1299
|
+
},
|
|
1300
|
+
});
|
|
1301
|
+
|
|
1302
|
+
currentOrder = pricingService.order.addItemModifier({
|
|
1303
|
+
order: currentOrder,
|
|
1304
|
+
modifier,
|
|
1305
|
+
itemIndex: 2,
|
|
1306
|
+
onConditionsNotMet: bag => {
|
|
1307
|
+
bag.forEach(condition => {
|
|
1308
|
+
conditionsBag.push(condition);
|
|
1309
|
+
});
|
|
1310
|
+
},
|
|
1311
|
+
onError: errorMessage => {
|
|
1312
|
+
error = errorMessage;
|
|
1313
|
+
},
|
|
1314
|
+
});
|
|
1315
|
+
|
|
1316
|
+
expect(conditionsBag).toEqual([]);
|
|
1317
|
+
expect(error).toEqual('');
|
|
1318
|
+
expect(currentOrder.items[0].modifiers.length).toBe(1);
|
|
1319
|
+
expect(currentOrder.items[1].modifiers.length).toBe(1);
|
|
1320
|
+
expect(currentOrder.items[2].modifiers.length).toBe(1);
|
|
1321
|
+
expect(currentOrder.items[3].modifiers.length).toBe(0);
|
|
1322
|
+
|
|
1323
|
+
expect(currentOrder.items.length).toBe(4);
|
|
1324
|
+
|
|
1325
|
+
currentOrder = pricingService.order.addItemModifier({
|
|
1326
|
+
order: currentOrder,
|
|
1327
|
+
modifier,
|
|
1328
|
+
itemIndex: 3,
|
|
1329
|
+
onConditionsNotMet: bag => {
|
|
1330
|
+
bag.forEach(condition => {
|
|
1331
|
+
conditionsBag.push(condition);
|
|
1332
|
+
});
|
|
1333
|
+
},
|
|
1334
|
+
onError: errorMessage => {
|
|
1335
|
+
error = errorMessage;
|
|
1336
|
+
},
|
|
1337
|
+
});
|
|
1338
|
+
|
|
1339
|
+
expect(conditionsBag).toEqual([]);
|
|
1340
|
+
expect(error).toEqual('modifier.has.reached.the.maximum.amount.of.applies');
|
|
1341
|
+
expect(currentOrder.items[3].modifiers.length).toBe(0);
|
|
1342
|
+
});
|
|
1343
|
+
test('CU-86dve295v should split item based on modifier.maxItemQuantity', () => {
|
|
1344
|
+
const order = {
|
|
1345
|
+
id: 'ord-123',
|
|
1346
|
+
items: [],
|
|
1347
|
+
modifiers: [],
|
|
1348
|
+
};
|
|
1349
|
+
const modifier = {
|
|
1350
|
+
_id: 1,
|
|
1351
|
+
compute: {
|
|
1352
|
+
amount: 10,
|
|
1353
|
+
action: 'subtract',
|
|
1354
|
+
type: 'fixed',
|
|
1355
|
+
},
|
|
1356
|
+
properties: {
|
|
1357
|
+
limits: { maxItemQuantity: 1 },
|
|
1358
|
+
},
|
|
1359
|
+
modifierId: 'aaa',
|
|
1360
|
+
};
|
|
1361
|
+
|
|
1362
|
+
order.items.push({
|
|
1363
|
+
quantity: 10,
|
|
1364
|
+
itemId: '111',
|
|
1365
|
+
price: 100,
|
|
1366
|
+
modifiers: [],
|
|
1367
|
+
});
|
|
1368
|
+
|
|
1369
|
+
let currentOrder = { ...order };
|
|
1370
|
+
|
|
1371
|
+
currentOrder = pricingService.order.addItemModifier({
|
|
1372
|
+
order: currentOrder,
|
|
1373
|
+
modifier,
|
|
1374
|
+
itemIndex: 0,
|
|
1375
|
+
});
|
|
1376
|
+
|
|
1377
|
+
expect(currentOrder.items.length).toEqual(1);
|
|
1378
|
+
|
|
1379
|
+
currentOrder = pricingService.order.splitItems({
|
|
1380
|
+
order: currentOrder,
|
|
1381
|
+
});
|
|
1382
|
+
|
|
1383
|
+
expect(currentOrder.items.length).toEqual(10);
|
|
1384
|
+
});
|
|
1385
|
+
|
|
1386
|
+
test('CU-86dve295v should split item based on modifier.maxItemQuantity, and spread modifiers accordingly 1', () => {
|
|
1387
|
+
const order = {
|
|
1388
|
+
id: 'ord-123',
|
|
1389
|
+
items: [],
|
|
1390
|
+
modifiers: [],
|
|
1391
|
+
};
|
|
1392
|
+
const modifier = {
|
|
1393
|
+
_id: 1,
|
|
1394
|
+
compute: {
|
|
1395
|
+
amount: 10,
|
|
1396
|
+
action: 'subtract',
|
|
1397
|
+
type: 'fixed',
|
|
1398
|
+
},
|
|
1399
|
+
properties: {
|
|
1400
|
+
limits: { maxItemQuantity: 1 },
|
|
1401
|
+
},
|
|
1402
|
+
modifierId: 'aaa',
|
|
1403
|
+
};
|
|
1404
|
+
|
|
1405
|
+
let currentOrder = { ...order };
|
|
1406
|
+
|
|
1407
|
+
currentOrder = pricingService.order.addItem({
|
|
1408
|
+
order,
|
|
1409
|
+
item: {
|
|
1410
|
+
quantity: 10,
|
|
1411
|
+
itemId: '111',
|
|
1412
|
+
price: 100,
|
|
1413
|
+
modifiers: [],
|
|
1414
|
+
subTotals: {},
|
|
1415
|
+
},
|
|
1416
|
+
}).updatedOrder;
|
|
1417
|
+
|
|
1418
|
+
currentOrder = pricingService.order.addItemModifier({
|
|
1419
|
+
order: currentOrder,
|
|
1420
|
+
modifier,
|
|
1421
|
+
itemIndex: 0,
|
|
1422
|
+
});
|
|
1423
|
+
|
|
1424
|
+
expect(currentOrder.items.length).toEqual(1);
|
|
1425
|
+
|
|
1426
|
+
currentOrder = pricingService.order.calculate(currentOrder);
|
|
1427
|
+
|
|
1428
|
+
currentOrder = pricingService.order.splitItems({
|
|
1429
|
+
order: currentOrder,
|
|
1430
|
+
});
|
|
1431
|
+
|
|
1432
|
+
expect(currentOrder.items.length).toEqual(10);
|
|
1433
|
+
expect(currentOrder.total).toEqual(990);
|
|
1434
|
+
|
|
1435
|
+
expect(currentOrder.items[0].total).toEqual(99);
|
|
1436
|
+
expect(currentOrder.items[0].modifiers[0]._computed.amount).toEqual(-1);
|
|
1437
|
+
expect(currentOrder.items[1].total).toEqual(99);
|
|
1438
|
+
expect(currentOrder.items[1].modifiers[0]._computed.amount).toEqual(-1);
|
|
1439
|
+
expect(currentOrder.items[2].total).toEqual(99);
|
|
1440
|
+
expect(currentOrder.items[2].modifiers[0]._computed.amount).toEqual(-1);
|
|
1441
|
+
expect(currentOrder.items[3].total).toEqual(99);
|
|
1442
|
+
expect(currentOrder.items[3].modifiers[0]._computed.amount).toEqual(-1);
|
|
1443
|
+
expect(currentOrder.items[4].total).toEqual(99);
|
|
1444
|
+
expect(currentOrder.items[4].modifiers[0]._computed.amount).toEqual(-1);
|
|
1445
|
+
expect(currentOrder.items[5].total).toEqual(99);
|
|
1446
|
+
expect(currentOrder.items[5].modifiers[0]._computed.amount).toEqual(-1);
|
|
1447
|
+
expect(currentOrder.items[6].total).toEqual(99);
|
|
1448
|
+
expect(currentOrder.items[6].modifiers[0]._computed.amount).toEqual(-1);
|
|
1449
|
+
expect(currentOrder.items[7].total).toEqual(99);
|
|
1450
|
+
expect(currentOrder.items[7].modifiers[0]._computed.amount).toEqual(-1);
|
|
1451
|
+
expect(currentOrder.items[8].total).toEqual(99);
|
|
1452
|
+
expect(currentOrder.items[8].modifiers[0]._computed.amount).toEqual(-1);
|
|
1453
|
+
expect(currentOrder.items[9].total).toEqual(99);
|
|
1454
|
+
expect(currentOrder.items[9].modifiers[0]._computed.amount).toEqual(-1);
|
|
1455
|
+
});
|
|
1456
|
+
|
|
1457
|
+
test('CU-86dve295v should split item based on modifier.maxItemQuantity=2, and spread modifiers accordingly 2', () => {
|
|
1458
|
+
const order = {
|
|
1459
|
+
id: 'ord-456',
|
|
1460
|
+
items: [],
|
|
1461
|
+
modifiers: [],
|
|
1462
|
+
};
|
|
1463
|
+
const modifier = {
|
|
1464
|
+
_id: 2,
|
|
1465
|
+
compute: {
|
|
1466
|
+
amount: 5,
|
|
1467
|
+
action: 'subtract',
|
|
1468
|
+
type: 'fixed',
|
|
1469
|
+
},
|
|
1470
|
+
properties: {
|
|
1471
|
+
limits: { maxItemQuantity: 2 },
|
|
1472
|
+
},
|
|
1473
|
+
modifierId: 'bbb',
|
|
1474
|
+
};
|
|
1475
|
+
|
|
1476
|
+
let currentOrder = { ...order };
|
|
1477
|
+
|
|
1478
|
+
currentOrder = pricingService.order.addItem({
|
|
1479
|
+
order,
|
|
1480
|
+
item: {
|
|
1481
|
+
quantity: 8,
|
|
1482
|
+
itemId: '222',
|
|
1483
|
+
price: 50,
|
|
1484
|
+
modifiers: [],
|
|
1485
|
+
subTotals: {},
|
|
1486
|
+
},
|
|
1487
|
+
}).updatedOrder;
|
|
1488
|
+
|
|
1489
|
+
currentOrder = pricingService.order.addItemModifier({
|
|
1490
|
+
order: currentOrder,
|
|
1491
|
+
modifier,
|
|
1492
|
+
itemIndex: 0,
|
|
1493
|
+
});
|
|
1494
|
+
|
|
1495
|
+
currentOrder = pricingService.order.calculate(currentOrder);
|
|
1496
|
+
|
|
1497
|
+
expect(currentOrder.items.length).toEqual(1);
|
|
1498
|
+
|
|
1499
|
+
expect(currentOrder.total).toEqual(395);
|
|
1500
|
+
|
|
1501
|
+
currentOrder = pricingService.order.splitItems({
|
|
1502
|
+
order: currentOrder,
|
|
1503
|
+
});
|
|
1504
|
+
|
|
1505
|
+
expect(currentOrder.items.length).toEqual(4);
|
|
1506
|
+
expect(currentOrder.total).toEqual(395);
|
|
1507
|
+
|
|
1508
|
+
currentOrder.items.forEach(item => {
|
|
1509
|
+
expect(item.quantity).toEqual(2);
|
|
1510
|
+
expect(item.total).toEqual(98.75);
|
|
1511
|
+
expect(item.modifiers[0]._computed.amount).toEqual(-1.25);
|
|
1512
|
+
});
|
|
1513
|
+
});
|
|
1514
|
+
|
|
1515
|
+
test('CU-86dve295v should split 1 item and left other untouched.', () => {
|
|
1516
|
+
const order = {
|
|
1517
|
+
id: 'ord-456',
|
|
1518
|
+
items: [],
|
|
1519
|
+
modifiers: [],
|
|
1520
|
+
};
|
|
1521
|
+
const modifier = {
|
|
1522
|
+
_id: 2,
|
|
1523
|
+
compute: {
|
|
1524
|
+
amount: 5,
|
|
1525
|
+
action: 'subtract',
|
|
1526
|
+
type: 'fixed',
|
|
1527
|
+
},
|
|
1528
|
+
properties: {
|
|
1529
|
+
limits: { maxItemQuantity: 2 },
|
|
1530
|
+
},
|
|
1531
|
+
modifierId: 'bbb',
|
|
1532
|
+
};
|
|
1533
|
+
|
|
1534
|
+
const redModifier = {
|
|
1535
|
+
_id: 3,
|
|
1536
|
+
modifierId: 'red-ccc',
|
|
1537
|
+
name: 'red',
|
|
1538
|
+
};
|
|
1539
|
+
|
|
1540
|
+
let currentOrder = { ...order };
|
|
1541
|
+
|
|
1542
|
+
currentOrder = pricingService.order.addItem({
|
|
1543
|
+
order,
|
|
1544
|
+
item: {
|
|
1545
|
+
quantity: 8,
|
|
1546
|
+
itemId: '222',
|
|
1547
|
+
price: 50,
|
|
1548
|
+
modifiers: [],
|
|
1549
|
+
subTotals: {},
|
|
1550
|
+
},
|
|
1551
|
+
}).updatedOrder;
|
|
1552
|
+
|
|
1553
|
+
currentOrder = pricingService.order.addItemModifier({
|
|
1554
|
+
order: currentOrder,
|
|
1555
|
+
modifier,
|
|
1556
|
+
itemIndex: 0,
|
|
1557
|
+
});
|
|
1558
|
+
|
|
1559
|
+
currentOrder = pricingService.order.addItemModifier({
|
|
1560
|
+
order: currentOrder,
|
|
1561
|
+
modifier: redModifier,
|
|
1562
|
+
itemIndex: 0,
|
|
1563
|
+
});
|
|
1564
|
+
|
|
1565
|
+
currentOrder = pricingService.order.addItem({
|
|
1566
|
+
order: currentOrder,
|
|
1567
|
+
item: {
|
|
1568
|
+
quantity: 1,
|
|
1569
|
+
itemId: '333',
|
|
1570
|
+
price: 100,
|
|
1571
|
+
modifiers: [],
|
|
1572
|
+
subTotals: {},
|
|
1573
|
+
},
|
|
1574
|
+
}).updatedOrder;
|
|
1575
|
+
|
|
1576
|
+
currentOrder = pricingService.order.calculate(currentOrder);
|
|
1577
|
+
|
|
1578
|
+
expect(currentOrder.items.length).toEqual(2);
|
|
1579
|
+
|
|
1580
|
+
expect(currentOrder.total).toEqual(495);
|
|
1581
|
+
|
|
1582
|
+
currentOrder = pricingService.order.splitItems({
|
|
1583
|
+
order: currentOrder,
|
|
1584
|
+
});
|
|
1585
|
+
|
|
1586
|
+
expect(currentOrder.items.length).toEqual(5);
|
|
1587
|
+
expect(currentOrder.total).toEqual(495);
|
|
1588
|
+
|
|
1589
|
+
expect(currentOrder.items[0].total).toEqual(100);
|
|
1590
|
+
expect(currentOrder.items[0].modifiers.length).toBe(0);
|
|
1591
|
+
|
|
1592
|
+
expect(currentOrder.items[1].total).toEqual(98.75);
|
|
1593
|
+
expect(currentOrder.items[1].modifiers[0].name).toBe('red');
|
|
1594
|
+
expect(currentOrder.items[1].modifiers[1]._computed.amount).toBe(-1.25);
|
|
1595
|
+
|
|
1596
|
+
expect(currentOrder.items[2].total).toEqual(98.75);
|
|
1597
|
+
expect(currentOrder.items[2].modifiers[0].name).toBe('red');
|
|
1598
|
+
expect(currentOrder.items[2].modifiers[1]._computed.amount).toBe(-1.25);
|
|
1599
|
+
|
|
1600
|
+
expect(currentOrder.items[3].total).toEqual(98.75);
|
|
1601
|
+
expect(currentOrder.items[3].modifiers[0].name).toBe('red');
|
|
1602
|
+
expect(currentOrder.items[3].modifiers[1]._computed.amount).toBe(-1.25);
|
|
1603
|
+
|
|
1604
|
+
expect(currentOrder.items[4].total).toEqual(98.75);
|
|
1605
|
+
expect(currentOrder.items[4].modifiers[0].name).toBe('red');
|
|
1606
|
+
expect(currentOrder.items[4].modifiers[1]._computed.amount).toBe(-1.25);
|
|
1607
|
+
});
|
|
1608
|
+
|
|
1609
|
+
test('CU-86dve295v should split item based on modifier.maxItemQuantity=4, and spread modifiers accordingly', () => {
|
|
1610
|
+
const order = {
|
|
1611
|
+
id: 'ord-456',
|
|
1612
|
+
items: [],
|
|
1613
|
+
modifiers: [],
|
|
1614
|
+
};
|
|
1615
|
+
const modifier = {
|
|
1616
|
+
_id: 2,
|
|
1617
|
+
compute: {
|
|
1618
|
+
amount: 5,
|
|
1619
|
+
action: 'subtract',
|
|
1620
|
+
type: 'fixed',
|
|
1621
|
+
},
|
|
1622
|
+
properties: {
|
|
1623
|
+
limits: { maxItemQuantity: 4 },
|
|
1624
|
+
},
|
|
1625
|
+
modifierId: 'bbb',
|
|
1626
|
+
};
|
|
1627
|
+
|
|
1628
|
+
let currentOrder = { ...order };
|
|
1629
|
+
|
|
1630
|
+
currentOrder = pricingService.order.addItem({
|
|
1631
|
+
order,
|
|
1632
|
+
item: {
|
|
1633
|
+
quantity: 10,
|
|
1634
|
+
itemId: '222',
|
|
1635
|
+
price: 50,
|
|
1636
|
+
modifiers: [],
|
|
1637
|
+
subTotals: {},
|
|
1638
|
+
},
|
|
1639
|
+
}).updatedOrder;
|
|
1640
|
+
|
|
1641
|
+
currentOrder = pricingService.order.addItemModifier({
|
|
1642
|
+
order: currentOrder,
|
|
1643
|
+
modifier,
|
|
1644
|
+
itemIndex: 0,
|
|
1645
|
+
});
|
|
1646
|
+
|
|
1647
|
+
currentOrder = pricingService.order.calculate(currentOrder);
|
|
1648
|
+
|
|
1649
|
+
expect(currentOrder.items.length).toEqual(1);
|
|
1650
|
+
|
|
1651
|
+
expect(currentOrder.total).toEqual(495);
|
|
1652
|
+
|
|
1653
|
+
currentOrder = pricingService.order.splitItems({
|
|
1654
|
+
order: currentOrder,
|
|
1655
|
+
});
|
|
1656
|
+
|
|
1657
|
+
expect(currentOrder.items.length).toEqual(3);
|
|
1658
|
+
|
|
1659
|
+
expect(currentOrder.items[0].quantity).toEqual(4);
|
|
1660
|
+
expect(currentOrder.items[0].modifiers[0]._computed.amount).toEqual(-2);
|
|
1661
|
+
|
|
1662
|
+
expect(currentOrder.items[1].quantity).toEqual(4);
|
|
1663
|
+
expect(currentOrder.items[1].modifiers[0]._computed.amount).toEqual(-2);
|
|
1664
|
+
|
|
1665
|
+
expect(currentOrder.items[2].quantity).toEqual(2);
|
|
1666
|
+
expect(currentOrder.items[2].modifiers[0]._computed.amount).toEqual(-1);
|
|
1667
|
+
|
|
1668
|
+
expect(currentOrder.total).toEqual(495);
|
|
1669
|
+
});
|
|
1101
1670
|
});
|