@darkpos/pricing 1.0.173 → 1.0.174

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.
@@ -0,0 +1,51 @@
1
+ const usePricing = require('../../index');
2
+ const mockStores = require('../mocks/stores');
3
+ const mockStoreSettings = require('../mocks/storeSettings');
4
+
5
+ const pricingService = usePricing({
6
+ store: mockStores[0],
7
+ settings: mockStoreSettings,
8
+ });
9
+
10
+ const item = {
11
+ _id: 'item-1',
12
+ itemId: 'item-1',
13
+ name: 'Shirt',
14
+ price: 10,
15
+ quantity: 1,
16
+ modifiers: [],
17
+ };
18
+
19
+ describe('calculate order status', () => {
20
+ test('keeps a held order on hold', () => {
21
+ const order = pricingService.order.holdOrder({ status: {}, items: [item] });
22
+ const result = pricingService.order.calculate(order);
23
+ expect(result.status.order).toBe('hold');
24
+ });
25
+
26
+ test('closes a held order once it is paid and picked', () => {
27
+ const order = pricingService.order.holdOrder({
28
+ status: {},
29
+ totalPaid: 10,
30
+ items: [
31
+ {
32
+ ...item,
33
+ totalPaid: 10,
34
+ status: { picked: { value: true }, paid: { value: true } },
35
+ },
36
+ ],
37
+ });
38
+ const result = pricingService.order.calculate(order);
39
+ expect(result.status.paid).toBe(true);
40
+ expect(result.status.picked).toBe(true);
41
+ expect(result.status.order).toBe('closed');
42
+ });
43
+
44
+ test('reopens a closed order that is no longer paid and picked', () => {
45
+ const result = pricingService.order.calculate({
46
+ status: { order: 'closed' },
47
+ items: [item],
48
+ });
49
+ expect(result.status.order).toBe('open');
50
+ });
51
+ });
@@ -191,6 +191,9 @@ module.exports = ({
191
191
  totalPaid,
192
192
  });
193
193
 
194
+ let orderStatus = actions.isHold(order) ? 'hold' : 'open';
195
+ if (picked && paid) orderStatus = 'closed';
196
+
194
197
  return {
195
198
  ...order,
196
199
  subTotals,
@@ -201,7 +204,7 @@ module.exports = ({
201
204
  ...(order.status || {}),
202
205
  picked,
203
206
  paid,
204
- order: picked && paid ? 'closed' : 'open',
207
+ order: orderStatus,
205
208
  },
206
209
  properties: {
207
210
  ...(order.properties || {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.173",
3
+ "version": "1.0.174",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -54,5 +54,5 @@
54
54
  "supertest": "^6.2.3",
55
55
  "supervisor": "^0.12.0"
56
56
  },
57
- "gitHead": "1e2f77636a8b7470dbb07c4ec0c85c625c4827b5"
57
+ "gitHead": "0552fcb5d20916710172a621da480ce751503c5b"
58
58
  }