@darkpos/pricing 1.0.144 → 1.0.145
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__/order/hasSerial.test.js +86 -0
- package/lib/order/hasSerial.js +29 -0
- package/lib/order/index.js +2 -0
- package/package.json +3 -2
|
@@ -0,0 +1,86 @@
|
|
|
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('hasSerial function', () => {
|
|
11
|
+
test('returns true when another item has the same serial', () => {
|
|
12
|
+
const { hasSerial } = pricingService.order;
|
|
13
|
+
|
|
14
|
+
const order = {
|
|
15
|
+
items: [
|
|
16
|
+
{
|
|
17
|
+
_id: '1',
|
|
18
|
+
serial: 'ABC-123',
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const item = {
|
|
24
|
+
_id: '2',
|
|
25
|
+
serial: ' abc-123 ',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const result = hasSerial({ order, item });
|
|
29
|
+
|
|
30
|
+
expect(result).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('returns false when the matching serial belongs to the same item', () => {
|
|
34
|
+
const { hasSerial } = pricingService.order;
|
|
35
|
+
|
|
36
|
+
const order = {
|
|
37
|
+
items: [
|
|
38
|
+
{
|
|
39
|
+
_id: '1',
|
|
40
|
+
serial: 'ABC-123',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const item = {
|
|
46
|
+
_id: '1',
|
|
47
|
+
serial: 'ABC-123',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const result = hasSerial({ order, item });
|
|
51
|
+
|
|
52
|
+
expect(result).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('returns false for related items', () => {
|
|
56
|
+
const { hasSerial } = pricingService.order;
|
|
57
|
+
|
|
58
|
+
const order = {
|
|
59
|
+
items: [
|
|
60
|
+
{
|
|
61
|
+
_id: '1',
|
|
62
|
+
serial: 'ABC-123',
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const item = {
|
|
68
|
+
_id: '2',
|
|
69
|
+
serial: 'ABC-123',
|
|
70
|
+
properties: {
|
|
71
|
+
relatedItem: true,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const result = hasSerial({ order, item });
|
|
76
|
+
|
|
77
|
+
expect(result).toBe(false);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('returns false when order or item is missing', () => {
|
|
81
|
+
const { hasSerial } = pricingService.order;
|
|
82
|
+
|
|
83
|
+
expect(hasSerial({ order: null, item: { serial: 'ABC-123' } })).toBe(false);
|
|
84
|
+
expect(hasSerial({ order: { items: [] }, item: null })).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const normalizeSerial = serial => {
|
|
2
|
+
if (typeof serial !== 'string') return '';
|
|
3
|
+
return serial.trim().toUpperCase();
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
module.exports = ({ itemActions }) =>
|
|
7
|
+
function hasSerial({ order, item }) {
|
|
8
|
+
if (
|
|
9
|
+
!item ||
|
|
10
|
+
!item.serial ||
|
|
11
|
+
!order ||
|
|
12
|
+
!order.items ||
|
|
13
|
+
itemActions.isRelatedItem(item)
|
|
14
|
+
)
|
|
15
|
+
return false;
|
|
16
|
+
|
|
17
|
+
const normalizedSerial = normalizeSerial(item.serial);
|
|
18
|
+
|
|
19
|
+
if (!normalizedSerial) return false;
|
|
20
|
+
|
|
21
|
+
return order.items
|
|
22
|
+
.filter(
|
|
23
|
+
orderItem =>
|
|
24
|
+
orderItem._id !== item._id && !itemActions.isRelatedItem(orderItem)
|
|
25
|
+
)
|
|
26
|
+
.some(
|
|
27
|
+
orderItem => normalizeSerial(orderItem.serial) === normalizedSerial
|
|
28
|
+
);
|
|
29
|
+
};
|
package/lib/order/index.js
CHANGED
|
@@ -101,6 +101,7 @@ const getTaxes = require('./getTaxes');
|
|
|
101
101
|
const getPickedStatus = require('./getPickedStatus');
|
|
102
102
|
const calculateWithPayment = require('./calculateWithPayment');
|
|
103
103
|
const getOverpaidAmount = require('./getOverpaidAmount');
|
|
104
|
+
const hasSerial = require('./hasSerial');
|
|
104
105
|
|
|
105
106
|
const orderActions = (deps = {}) => {
|
|
106
107
|
const actions = {};
|
|
@@ -213,6 +214,7 @@ const orderActions = (deps = {}) => {
|
|
|
213
214
|
getPickedStatus: getPickedStatus(innerDeps),
|
|
214
215
|
calculateWithPayment: calculateWithPayment(innerDeps),
|
|
215
216
|
getOverpaidAmount: getOverpaidAmount(innerDeps),
|
|
217
|
+
hasSerial: hasSerial(innerDeps),
|
|
216
218
|
});
|
|
217
219
|
|
|
218
220
|
Object.keys(freezedActions).forEach(actionName => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.145",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"test:addItemModifier": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/modifier/addItemModifier.test.js",
|
|
33
33
|
"test:payment": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/payment.test.js",
|
|
34
34
|
"test:orderPaymentModifier": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/order-payment-modifier.test.js",
|
|
35
|
+
"test:hasSerial": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/hasSerial.test.js",
|
|
35
36
|
"lint": "eslint --quiet lib/"
|
|
36
37
|
},
|
|
37
38
|
"publishConfig": {
|
|
@@ -53,5 +54,5 @@
|
|
|
53
54
|
"supertest": "^6.2.3",
|
|
54
55
|
"supervisor": "^0.12.0"
|
|
55
56
|
},
|
|
56
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "eb6adf31020d7ca3b57f6e6b1bfa20c4e0289ca0"
|
|
57
58
|
}
|