@darkpos/pricing 1.0.56 → 1.0.57

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.
@@ -74,6 +74,64 @@ describe('Modifier actions', () => {
74
74
  },
75
75
  });
76
76
 
77
+ expect(conditionsBag).toEqual([]);
78
+ expect(error).toEqual('');
79
+
80
+ expect(updatedOrder2.items[0].modifiers.length).toEqual(2);
81
+ });
82
+
83
+ test('CU-86dve27tq Should not allow adding a modifier more than once to an item if isQuantityMultiplier={true} QTY={2}', () => {
84
+ const order = {
85
+ id: 'ord-123',
86
+ items: [],
87
+ modifiers: [],
88
+ };
89
+ const modifier = {
90
+ _id: 1,
91
+ compute: {
92
+ amount: 10,
93
+ action: 'subtract',
94
+ type: 'fixed',
95
+ },
96
+ properties: {
97
+ isQuantityMultiplier: true,
98
+ },
99
+ };
100
+ order.items.push({
101
+ quantity: 2,
102
+ itemId: '123',
103
+ price: 100,
104
+ modifiers: [],
105
+ });
106
+
107
+ const conditionsBag = [];
108
+
109
+ const updatedOrder = pricingService.order.addItemModifier({
110
+ order,
111
+ modifier,
112
+ itemIndex: 0,
113
+ onConditionsNotMet: bag => {
114
+ bag.forEach(condition => {
115
+ conditionsBag.push(condition);
116
+ });
117
+ },
118
+ });
119
+
120
+ let error = '';
121
+ const updatedOrder2 = pricingService.order.addItemModifier({
122
+ order: { ...updatedOrder },
123
+ modifier,
124
+ itemIndex: 0,
125
+ onConditionsNotMet: bag => {
126
+ bag.forEach(condition => {
127
+ conditionsBag.push(condition);
128
+ });
129
+ },
130
+ onError: errorMessage => {
131
+ error = errorMessage;
132
+ },
133
+ });
134
+
77
135
  expect(conditionsBag).toEqual([]);
78
136
  expect(error).toEqual('modifier.has.reached.the.maximum.amount.of.applies');
79
137
  expect(updatedOrder2).toEqual(updatedOrder);
@@ -0,0 +1,32 @@
1
+ const usePricing = require('../../index');
2
+ const mockStores = require('../mocks/stores');
3
+ const orderNotPaid = require('../mocks/unpaid/order-not-paid.json');
4
+ const constants = require('../../lib/constants/Status');
5
+
6
+ const session = {
7
+ store: mockStores[0],
8
+ };
9
+
10
+ const pricingService = usePricing(session);
11
+
12
+ describe('Unvoid order', () => {
13
+ test('Should update status.order to OPEN if order has existing status', () => {
14
+ const updatedOrder = pricingService.order.unvoidOrder(orderNotPaid);
15
+ expect(updatedOrder.status.order).toBe(constants.Order.OPEN);
16
+ });
17
+
18
+ test('Should return null if order is null', () => {
19
+ const updatedOrder = pricingService.order.unvoidOrder(null);
20
+ expect(updatedOrder).toBeNull();
21
+ });
22
+ test('Should return undefined if order is undefined', () => {
23
+ const updatedOrder = pricingService.order.unvoidOrder(undefined);
24
+ expect(updatedOrder).toBeUndefined();
25
+ });
26
+ test('Should not mutate the original order object', () => {
27
+ const order = { ...orderNotPaid };
28
+ const orderClone = JSON.parse(JSON.stringify(orderNotPaid));
29
+ pricingService.order.unvoidOrder(order);
30
+ expect(order).toEqual(orderClone);
31
+ });
32
+ });
@@ -227,7 +227,7 @@ module.exports = ({ actions, itemActions, modifierActions, utils, _ }) => {
227
227
  if (
228
228
  contains &&
229
229
  modifierActions.isCompute(modifier) &&
230
- !modifierActions.isQuantityMultiplier(modifier)
230
+ modifierActions.isQuantityMultiplier(modifier)
231
231
  ) {
232
232
  if (onError)
233
233
  onError('modifier.has.reached.the.maximum.amount.of.applies');
@@ -38,6 +38,7 @@ const addDiscountModifier = require('./addDiscountModifier');
38
38
  const calculateDue = require('./calculateDue');
39
39
  const toggleModifier = require('./toggleModifier');
40
40
  const voidOrder = require('./void');
41
+ const unvoidOrder = require('./unvoid');
41
42
  const holdOrder = require('./hold');
42
43
  const openOrder = require('./open');
43
44
  const isDetailed = require('./isDetailed');
@@ -137,6 +138,7 @@ const orderActions = (deps = {}) => {
137
138
  calculateDue: calculateDue(innerDeps),
138
139
  toggleModifier: toggleModifier(innerDeps),
139
140
  voidOrder: voidOrder(innerDeps),
141
+ unvoidOrder: unvoidOrder(innerDeps),
140
142
  holdOrder: holdOrder(innerDeps),
141
143
  openOrder: openOrder(innerDeps),
142
144
  isDetailed: isDetailed(innerDeps),
@@ -0,0 +1,11 @@
1
+ module.exports = ({ constants }) =>
2
+ function unvoid(order) {
3
+ if (!order) return order;
4
+ return {
5
+ ...order,
6
+ status: {
7
+ ...(order.status || {}),
8
+ order: constants.Status.Order.OPEN,
9
+ },
10
+ };
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.56",
3
+ "version": "1.0.57",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -45,5 +45,5 @@
45
45
  "supertest": "^6.2.3",
46
46
  "supervisor": "^0.12.0"
47
47
  },
48
- "gitHead": "41b3ae5dcaec11195920c3b5f0a97b34b3982815"
48
+ "gitHead": "d7719dca121087e9f10644bcef8ccd76e1271104"
49
49
  }