@darkpos/pricing 1.0.165 → 1.0.167
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/getGiftModifierSources.test.js +56 -40
- package/__TEST__/order/getPaidGiftModifiers.test.js +60 -18
- package/__TEST__/order/pickEndDate.test.js +34 -0
- package/__TEST__/payment/getPaymentItemIds.test.js +48 -0
- package/__TEST__/payment/getPaymentOrderIds.test.js +48 -0
- package/lib/order/getGiftModifierSources.js +2 -2
- package/lib/order/getPaidGiftModifiers.js +4 -3
- package/lib/payment/getPaymentItemIds.js +9 -0
- package/lib/payment/getPaymentOrderIds.js +9 -0
- package/lib/payment/index.js +4 -0
- package/lib/store/getSchedule.js +3 -5
- package/lib/store/index.js +2 -0
- package/lib/store/isDayMatch.js +6 -0
- package/lib/store/pickEndDate.js +9 -1
- package/package.json +2 -2
|
@@ -16,7 +16,8 @@ const makeGiftModifier = ({
|
|
|
16
16
|
compute: { amount },
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
const makePaidItem = (modifiers = []) => ({
|
|
19
|
+
const makePaidItem = (modifiers = [], _id = 'item1') => ({
|
|
20
|
+
_id,
|
|
20
21
|
status: { paid: { value: true } },
|
|
21
22
|
modifiers,
|
|
22
23
|
});
|
|
@@ -25,25 +26,30 @@ const makeOrder = (items = []) => ({ items, orders: [] });
|
|
|
25
26
|
|
|
26
27
|
describe('getGiftModifierSources', () => {
|
|
27
28
|
test('returns empty array for empty orders', () => {
|
|
28
|
-
expect(
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
expect(
|
|
30
|
+
pricingService.order.getGiftModifierSources({
|
|
31
|
+
orders: [],
|
|
32
|
+
purchasedDate: new Date(),
|
|
33
|
+
})
|
|
34
|
+
).toEqual([]);
|
|
31
35
|
});
|
|
32
36
|
|
|
33
37
|
test('maps paid gift modifier to source with correct fields', () => {
|
|
34
38
|
const purchasedDate = new Date('2026-05-01T00:00:00.000Z');
|
|
35
39
|
const orders = [
|
|
36
40
|
makeOrder([
|
|
37
|
-
makePaidItem(
|
|
38
|
-
makeGiftModifier({ number: '111222', pin: '9999', amount: 75 }),
|
|
39
|
-
|
|
41
|
+
makePaidItem(
|
|
42
|
+
[makeGiftModifier({ number: '111222', pin: '9999', amount: 75 })],
|
|
43
|
+
'item1'
|
|
44
|
+
),
|
|
40
45
|
]),
|
|
41
46
|
];
|
|
42
47
|
|
|
43
|
-
const result = pricingService.order.getGiftModifierSources(
|
|
48
|
+
const result = pricingService.order.getGiftModifierSources({
|
|
44
49
|
orders,
|
|
45
|
-
purchasedDate
|
|
46
|
-
|
|
50
|
+
purchasedDate,
|
|
51
|
+
itemIds: ['item1'],
|
|
52
|
+
});
|
|
47
53
|
|
|
48
54
|
expect(result).toHaveLength(1);
|
|
49
55
|
expect(result[0]).toEqual({
|
|
@@ -60,22 +66,26 @@ describe('getGiftModifierSources', () => {
|
|
|
60
66
|
const purchasedDate = new Date('2026-05-01T00:00:00.000Z');
|
|
61
67
|
const orders = [
|
|
62
68
|
makeOrder([
|
|
63
|
-
makePaidItem(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
makePaidItem(
|
|
70
|
+
[
|
|
71
|
+
makeGiftModifier({
|
|
72
|
+
number: '333444',
|
|
73
|
+
pin: '0000',
|
|
74
|
+
amount: 100,
|
|
75
|
+
expMonth: 12,
|
|
76
|
+
expYear: 2028,
|
|
77
|
+
}),
|
|
78
|
+
],
|
|
79
|
+
'item1'
|
|
80
|
+
),
|
|
72
81
|
]),
|
|
73
82
|
];
|
|
74
83
|
|
|
75
|
-
const result = pricingService.order.getGiftModifierSources(
|
|
84
|
+
const result = pricingService.order.getGiftModifierSources({
|
|
76
85
|
orders,
|
|
77
|
-
purchasedDate
|
|
78
|
-
|
|
86
|
+
purchasedDate,
|
|
87
|
+
itemIds: ['item1'],
|
|
88
|
+
});
|
|
79
89
|
|
|
80
90
|
expect(result[0].expMonth).toBe(12);
|
|
81
91
|
expect(result[0].expYear).toBe(2028);
|
|
@@ -84,16 +94,18 @@ describe('getGiftModifierSources', () => {
|
|
|
84
94
|
test('returns null for missing expMonth/expYear', () => {
|
|
85
95
|
const orders = [
|
|
86
96
|
makeOrder([
|
|
87
|
-
makePaidItem(
|
|
88
|
-
makeGiftModifier({ expMonth: undefined, expYear: undefined }),
|
|
89
|
-
|
|
97
|
+
makePaidItem(
|
|
98
|
+
[makeGiftModifier({ expMonth: undefined, expYear: undefined })],
|
|
99
|
+
'item1'
|
|
100
|
+
),
|
|
90
101
|
]),
|
|
91
102
|
];
|
|
92
103
|
|
|
93
|
-
const result = pricingService.order.getGiftModifierSources(
|
|
104
|
+
const result = pricingService.order.getGiftModifierSources({
|
|
94
105
|
orders,
|
|
95
|
-
new Date()
|
|
96
|
-
|
|
106
|
+
purchasedDate: new Date(),
|
|
107
|
+
itemIds: ['item1'],
|
|
108
|
+
});
|
|
97
109
|
|
|
98
110
|
expect(result[0].expMonth).toBeNull();
|
|
99
111
|
expect(result[0].expYear).toBeNull();
|
|
@@ -101,12 +113,13 @@ describe('getGiftModifierSources', () => {
|
|
|
101
113
|
|
|
102
114
|
test('sets purchasedDate from argument', () => {
|
|
103
115
|
const purchasedDate = new Date('2026-01-15T08:00:00.000Z');
|
|
104
|
-
const orders = [makeOrder([makePaidItem([makeGiftModifier()])])];
|
|
116
|
+
const orders = [makeOrder([makePaidItem([makeGiftModifier()], 'item1')])];
|
|
105
117
|
|
|
106
|
-
const result = pricingService.order.getGiftModifierSources(
|
|
118
|
+
const result = pricingService.order.getGiftModifierSources({
|
|
107
119
|
orders,
|
|
108
|
-
purchasedDate
|
|
109
|
-
|
|
120
|
+
purchasedDate,
|
|
121
|
+
itemIds: ['item1'],
|
|
122
|
+
});
|
|
110
123
|
|
|
111
124
|
expect(result[0].purchasedDate).toBe(purchasedDate);
|
|
112
125
|
});
|
|
@@ -114,15 +127,16 @@ describe('getGiftModifierSources', () => {
|
|
|
114
127
|
test('returns multiple sources for multiple gift modifiers', () => {
|
|
115
128
|
const orders = [
|
|
116
129
|
makeOrder([
|
|
117
|
-
makePaidItem([makeGiftModifier({ number: '111111', amount: 50 })]),
|
|
118
|
-
makePaidItem([makeGiftModifier({ number: '222222', amount: 25 })]),
|
|
130
|
+
makePaidItem([makeGiftModifier({ number: '111111', amount: 50 })], 'item1'),
|
|
131
|
+
makePaidItem([makeGiftModifier({ number: '222222', amount: 25 })], 'item2'),
|
|
119
132
|
]),
|
|
120
133
|
];
|
|
121
134
|
|
|
122
|
-
const result = pricingService.order.getGiftModifierSources(
|
|
135
|
+
const result = pricingService.order.getGiftModifierSources({
|
|
123
136
|
orders,
|
|
124
|
-
new Date()
|
|
125
|
-
|
|
137
|
+
purchasedDate: new Date(),
|
|
138
|
+
itemIds: ['item1', 'item2'],
|
|
139
|
+
});
|
|
126
140
|
|
|
127
141
|
expect(result).toHaveLength(2);
|
|
128
142
|
expect(result.map(s => s.number)).toEqual(['111111', '222222']);
|
|
@@ -130,15 +144,17 @@ describe('getGiftModifierSources', () => {
|
|
|
130
144
|
|
|
131
145
|
test('skips modifiers from unpaid items', () => {
|
|
132
146
|
const unpaidItem = {
|
|
147
|
+
_id: 'item1',
|
|
133
148
|
status: { paid: { value: false } },
|
|
134
149
|
modifiers: [makeGiftModifier()],
|
|
135
150
|
};
|
|
136
151
|
const orders = [makeOrder([unpaidItem])];
|
|
137
152
|
|
|
138
|
-
const result = pricingService.order.getGiftModifierSources(
|
|
153
|
+
const result = pricingService.order.getGiftModifierSources({
|
|
139
154
|
orders,
|
|
140
|
-
new Date()
|
|
141
|
-
|
|
155
|
+
purchasedDate: new Date(),
|
|
156
|
+
itemIds: ['item1'],
|
|
157
|
+
});
|
|
142
158
|
|
|
143
159
|
expect(result).toHaveLength(0);
|
|
144
160
|
});
|
|
@@ -16,31 +16,42 @@ const makeGiftModifier = ({
|
|
|
16
16
|
compute: { amount },
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
const makePaidItem = (modifiers = []) => ({
|
|
19
|
+
const makePaidItem = (modifiers = [], _id = 'item1') => ({
|
|
20
|
+
_id,
|
|
20
21
|
status: { paid: { value: true } },
|
|
21
22
|
modifiers,
|
|
22
23
|
});
|
|
23
24
|
|
|
24
|
-
const makeUnpaidItem = (modifiers = []) => ({
|
|
25
|
+
const makeUnpaidItem = (modifiers = [], _id = 'item1') => ({
|
|
26
|
+
_id,
|
|
25
27
|
status: { paid: { value: false } },
|
|
26
28
|
modifiers,
|
|
27
29
|
});
|
|
28
30
|
|
|
29
31
|
describe('getPaidGiftModifiers', () => {
|
|
30
32
|
test('returns empty array for empty orders', () => {
|
|
31
|
-
expect(pricingService.order.getPaidGiftModifiers([])).toEqual(
|
|
33
|
+
expect(pricingService.order.getPaidGiftModifiers({ orders: [] })).toEqual(
|
|
34
|
+
[]
|
|
35
|
+
);
|
|
32
36
|
});
|
|
33
37
|
|
|
34
38
|
test('returns empty array when orders is null or undefined', () => {
|
|
35
|
-
expect(
|
|
36
|
-
|
|
39
|
+
expect(
|
|
40
|
+
pricingService.order.getPaidGiftModifiers({ orders: null })
|
|
41
|
+
).toEqual([]);
|
|
42
|
+
expect(
|
|
43
|
+
pricingService.order.getPaidGiftModifiers({ orders: undefined })
|
|
44
|
+
).toEqual([]);
|
|
37
45
|
});
|
|
38
46
|
|
|
39
47
|
test('returns gift modifiers from paid items', () => {
|
|
40
48
|
const giftMod = makeGiftModifier({ number: '111222' });
|
|
41
|
-
const orders = [{ items: [makePaidItem([giftMod])], orders: [] }];
|
|
49
|
+
const orders = [{ items: [makePaidItem([giftMod], 'item1')], orders: [] }];
|
|
42
50
|
|
|
43
|
-
const result = pricingService.order.getPaidGiftModifiers(
|
|
51
|
+
const result = pricingService.order.getPaidGiftModifiers({
|
|
52
|
+
orders,
|
|
53
|
+
itemIds: ['item1'],
|
|
54
|
+
});
|
|
44
55
|
|
|
45
56
|
expect(result).toHaveLength(1);
|
|
46
57
|
expect(result[0]).toBe(giftMod);
|
|
@@ -48,9 +59,14 @@ describe('getPaidGiftModifiers', () => {
|
|
|
48
59
|
|
|
49
60
|
test('ignores gift modifiers from unpaid items', () => {
|
|
50
61
|
const giftMod = makeGiftModifier();
|
|
51
|
-
const orders = [
|
|
62
|
+
const orders = [
|
|
63
|
+
{ items: [makeUnpaidItem([giftMod], 'item1')], orders: [] },
|
|
64
|
+
];
|
|
52
65
|
|
|
53
|
-
const result = pricingService.order.getPaidGiftModifiers(
|
|
66
|
+
const result = pricingService.order.getPaidGiftModifiers({
|
|
67
|
+
orders,
|
|
68
|
+
itemIds: ['item1'],
|
|
69
|
+
});
|
|
54
70
|
|
|
55
71
|
expect(result).toHaveLength(0);
|
|
56
72
|
});
|
|
@@ -60,11 +76,14 @@ describe('getPaidGiftModifiers', () => {
|
|
|
60
76
|
const orders = [
|
|
61
77
|
{
|
|
62
78
|
items: [],
|
|
63
|
-
orders: [{ items: [makePaidItem([giftMod])] }],
|
|
79
|
+
orders: [{ items: [makePaidItem([giftMod], 'item1')] }],
|
|
64
80
|
},
|
|
65
81
|
];
|
|
66
82
|
|
|
67
|
-
const result = pricingService.order.getPaidGiftModifiers(
|
|
83
|
+
const result = pricingService.order.getPaidGiftModifiers({
|
|
84
|
+
orders,
|
|
85
|
+
itemIds: ['item1'],
|
|
86
|
+
});
|
|
68
87
|
|
|
69
88
|
expect(result).toHaveLength(1);
|
|
70
89
|
expect(result[0]).toBe(giftMod);
|
|
@@ -76,9 +95,12 @@ describe('getPaidGiftModifiers', () => {
|
|
|
76
95
|
properties: { gift: { number: '555444', pin: '1111' } },
|
|
77
96
|
compute: { amount: 30 },
|
|
78
97
|
};
|
|
79
|
-
const orders = [{ items: [makePaidItem([mod])], orders: [] }];
|
|
98
|
+
const orders = [{ items: [makePaidItem([mod], 'item1')], orders: [] }];
|
|
80
99
|
|
|
81
|
-
const result = pricingService.order.getPaidGiftModifiers(
|
|
100
|
+
const result = pricingService.order.getPaidGiftModifiers({
|
|
101
|
+
orders,
|
|
102
|
+
itemIds: ['item1'],
|
|
103
|
+
});
|
|
82
104
|
|
|
83
105
|
expect(result).toHaveLength(1);
|
|
84
106
|
});
|
|
@@ -89,9 +111,14 @@ describe('getPaidGiftModifiers', () => {
|
|
|
89
111
|
properties: {},
|
|
90
112
|
compute: { amount: 10 },
|
|
91
113
|
};
|
|
92
|
-
const orders = [
|
|
114
|
+
const orders = [
|
|
115
|
+
{ items: [makePaidItem([nonGiftMod], 'item1')], orders: [] },
|
|
116
|
+
];
|
|
93
117
|
|
|
94
|
-
const result = pricingService.order.getPaidGiftModifiers(
|
|
118
|
+
const result = pricingService.order.getPaidGiftModifiers({
|
|
119
|
+
orders,
|
|
120
|
+
itemIds: ['item1'],
|
|
121
|
+
});
|
|
95
122
|
|
|
96
123
|
expect(result).toHaveLength(0);
|
|
97
124
|
});
|
|
@@ -100,12 +127,27 @@ describe('getPaidGiftModifiers', () => {
|
|
|
100
127
|
const mod1 = makeGiftModifier({ number: '111111' });
|
|
101
128
|
const mod2 = makeGiftModifier({ number: '222222' });
|
|
102
129
|
const orders = [
|
|
103
|
-
{ items: [makePaidItem([mod1])], orders: [] },
|
|
104
|
-
{ items: [makePaidItem([mod2])], orders: [] },
|
|
130
|
+
{ items: [makePaidItem([mod1], 'item1')], orders: [] },
|
|
131
|
+
{ items: [makePaidItem([mod2], 'item2')], orders: [] },
|
|
105
132
|
];
|
|
106
133
|
|
|
107
|
-
const result = pricingService.order.getPaidGiftModifiers(
|
|
134
|
+
const result = pricingService.order.getPaidGiftModifiers({
|
|
135
|
+
orders,
|
|
136
|
+
itemIds: ['item1', 'item2'],
|
|
137
|
+
});
|
|
108
138
|
|
|
109
139
|
expect(result).toHaveLength(2);
|
|
110
140
|
});
|
|
141
|
+
|
|
142
|
+
test('excludes items not in itemIds', () => {
|
|
143
|
+
const giftMod = makeGiftModifier();
|
|
144
|
+
const orders = [{ items: [makePaidItem([giftMod], 'item1')], orders: [] }];
|
|
145
|
+
|
|
146
|
+
const result = pricingService.order.getPaidGiftModifiers({
|
|
147
|
+
orders,
|
|
148
|
+
itemIds: ['other-item'],
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
expect(result).toHaveLength(0);
|
|
152
|
+
});
|
|
111
153
|
});
|
|
@@ -517,6 +517,40 @@ describe('pickEndDate function', () => {
|
|
|
517
517
|
expect(result).toBe('2025-05-13T21:00:00Z');
|
|
518
518
|
});
|
|
519
519
|
|
|
520
|
+
test('pickEndDate - ignores schedules whose dayOfWeek does not match today', () => {
|
|
521
|
+
const schedules = [
|
|
522
|
+
{
|
|
523
|
+
_id: 'weekday-schedule',
|
|
524
|
+
dayOfWeek: [1, 2, 5, 4],
|
|
525
|
+
recommended: 'auto_recommended',
|
|
526
|
+
addDays: 3,
|
|
527
|
+
readyHour: { hour: 17, minute: 0 },
|
|
528
|
+
cutHour: { hour: 7, minute: 30 },
|
|
529
|
+
skipDays: [7],
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
_id: 'saturday-schedule',
|
|
533
|
+
dayOfWeek: [6],
|
|
534
|
+
recommended: 'auto_recommended',
|
|
535
|
+
addDays: 4,
|
|
536
|
+
readyHour: { hour: 17, minute: 0 },
|
|
537
|
+
cutHour: { hour: 7, minute: 30 },
|
|
538
|
+
skipDays: [7],
|
|
539
|
+
},
|
|
540
|
+
];
|
|
541
|
+
|
|
542
|
+
const pricingService = usePricing(getDefaultSettings(schedules));
|
|
543
|
+
|
|
544
|
+
// Monday
|
|
545
|
+
const now = moment('2025-05-12T15:00:00Z').tz('America/New_York');
|
|
546
|
+
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
547
|
+
|
|
548
|
+
const result = pricingService.store.pickEndDate();
|
|
549
|
+
|
|
550
|
+
// Monday + 3 days from the matching schedule, not +4 from the Saturday one
|
|
551
|
+
expect(result).toBe('2025-05-15T21:00:00Z');
|
|
552
|
+
});
|
|
553
|
+
|
|
520
554
|
test('pickEndDate - applies addDays when fromDate is provided', () => {
|
|
521
555
|
const schedule = {
|
|
522
556
|
addDays: 3,
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const usePricing = require('../../index');
|
|
2
|
+
|
|
3
|
+
const pricingService = usePricing();
|
|
4
|
+
|
|
5
|
+
const makePayment = (invoices) => ({ paymentInvoices: invoices });
|
|
6
|
+
|
|
7
|
+
const makeInvoice = (itemIds) => ({
|
|
8
|
+
paymentOrderItems: itemIds.map(orderItemId => ({ orderItemId })),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe('getPaymentItemIds', () => {
|
|
12
|
+
test('returns empty array when payment is null', () => {
|
|
13
|
+
expect(pricingService.payment.getPaymentItemIds(null)).toEqual([]);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('returns empty array when payment has no invoices', () => {
|
|
17
|
+
expect(pricingService.payment.getPaymentItemIds({})).toEqual([]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('returns empty array when paymentInvoices is empty', () => {
|
|
21
|
+
expect(pricingService.payment.getPaymentItemIds(makePayment([]))).toEqual([]);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('extracts itemIds from single invoice', () => {
|
|
25
|
+
const payment = makePayment([makeInvoice(['item1', 'item2'])]);
|
|
26
|
+
expect(pricingService.payment.getPaymentItemIds(payment)).toEqual(['item1', 'item2']);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('extracts itemIds from multiple invoices', () => {
|
|
30
|
+
const payment = makePayment([makeInvoice(['item1']), makeInvoice(['item2', 'item3'])]);
|
|
31
|
+
expect(pricingService.payment.getPaymentItemIds(payment)).toEqual(['item1', 'item2', 'item3']);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('filters out null/undefined itemIds', () => {
|
|
35
|
+
const payment = makePayment([{ paymentOrderItems: [{ orderItemId: 'item1' }, { orderItemId: null }, {}] }]);
|
|
36
|
+
expect(pricingService.payment.getPaymentItemIds(payment)).toEqual(['item1']);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('coerces itemIds to strings', () => {
|
|
40
|
+
const payment = makePayment([{ paymentOrderItems: [{ orderItemId: 123 }] }]);
|
|
41
|
+
expect(pricingService.payment.getPaymentItemIds(payment)).toEqual(['123']);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('handles invoice with no paymentOrderItems', () => {
|
|
45
|
+
const payment = makePayment([{}]);
|
|
46
|
+
expect(pricingService.payment.getPaymentItemIds(payment)).toEqual([]);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const usePricing = require('../../index');
|
|
2
|
+
|
|
3
|
+
const pricingService = usePricing();
|
|
4
|
+
|
|
5
|
+
const makePayment = (invoices) => ({ paymentInvoices: invoices });
|
|
6
|
+
|
|
7
|
+
const makeInvoice = (orderIds) => ({
|
|
8
|
+
paymentOrderItems: orderIds.map(orderId => ({ orderId })),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe('getPaymentOrderIds', () => {
|
|
12
|
+
test('returns empty array when payment is null', () => {
|
|
13
|
+
expect(pricingService.payment.getPaymentOrderIds(null)).toEqual([]);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('returns empty array when payment has no invoices', () => {
|
|
17
|
+
expect(pricingService.payment.getPaymentOrderIds({})).toEqual([]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('returns empty array when paymentInvoices is empty', () => {
|
|
21
|
+
expect(pricingService.payment.getPaymentOrderIds(makePayment([]))).toEqual([]);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('extracts orderIds from single invoice', () => {
|
|
25
|
+
const payment = makePayment([makeInvoice(['order1', 'order2'])]);
|
|
26
|
+
expect(pricingService.payment.getPaymentOrderIds(payment)).toEqual(['order1', 'order2']);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('extracts orderIds from multiple invoices', () => {
|
|
30
|
+
const payment = makePayment([makeInvoice(['order1']), makeInvoice(['order2', 'order3'])]);
|
|
31
|
+
expect(pricingService.payment.getPaymentOrderIds(payment)).toEqual(['order1', 'order2', 'order3']);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('filters out null/undefined orderIds', () => {
|
|
35
|
+
const payment = makePayment([{ paymentOrderItems: [{ orderId: 'order1' }, { orderId: null }, {}] }]);
|
|
36
|
+
expect(pricingService.payment.getPaymentOrderIds(payment)).toEqual(['order1']);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('coerces orderIds to strings', () => {
|
|
40
|
+
const payment = makePayment([{ paymentOrderItems: [{ orderId: 123 }] }]);
|
|
41
|
+
expect(pricingService.payment.getPaymentOrderIds(payment)).toEqual(['123']);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('handles invoice with no paymentOrderItems', () => {
|
|
45
|
+
const payment = makePayment([{}]);
|
|
46
|
+
expect(pricingService.payment.getPaymentOrderIds(payment)).toEqual([]);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module.exports = ({ actions, modifierActions }) =>
|
|
2
|
-
function getGiftModifierSources(orders, purchasedDate) {
|
|
3
|
-
const paidItemModifiers = actions.getPaidGiftModifiers(orders);
|
|
2
|
+
function getGiftModifierSources({ orders, purchasedDate, itemIds }) {
|
|
3
|
+
const paidItemModifiers = actions.getPaidGiftModifiers({ orders, itemIds });
|
|
4
4
|
return (paidItemModifiers || []).map(modifier =>
|
|
5
5
|
modifierActions.getGiftModifierSource(modifier, purchasedDate)
|
|
6
6
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
module.exports = () =>
|
|
2
|
-
function getPaidGiftModifiers(orders) {
|
|
1
|
+
module.exports = ({ itemActions }) =>
|
|
2
|
+
function getPaidGiftModifiers({ orders, itemIds }) {
|
|
3
3
|
if ((orders || []).length === 0) return [];
|
|
4
4
|
|
|
5
5
|
const allItems = orders
|
|
@@ -7,7 +7,8 @@ module.exports = () =>
|
|
|
7
7
|
...(order.items || []),
|
|
8
8
|
...(order.orders || []).flatMap(subOrder => subOrder.items || []),
|
|
9
9
|
])
|
|
10
|
-
.filter(item => item.
|
|
10
|
+
.filter(item => itemIds.includes(item._id))
|
|
11
|
+
.filter(item => itemActions.isPaid({ item }));
|
|
11
12
|
|
|
12
13
|
return allItems.flatMap(item =>
|
|
13
14
|
(item.modifiers || []).filter(
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module.exports = () =>
|
|
2
|
+
function getPaymentItemIds(payment) {
|
|
3
|
+
if (!payment || (payment.paymentInvoices || []).length === 0) return [];
|
|
4
|
+
|
|
5
|
+
return (payment.paymentInvoices || [])
|
|
6
|
+
.flatMap(pi => (pi.paymentOrderItems || []).map(poi => poi.orderItemId))
|
|
7
|
+
.filter(Boolean)
|
|
8
|
+
.map(String);
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module.exports = () =>
|
|
2
|
+
function getPaymentOrderIds(payment) {
|
|
3
|
+
if (!payment || (payment.paymentInvoices || []).length === 0) return [];
|
|
4
|
+
|
|
5
|
+
return (payment.paymentInvoices || [])
|
|
6
|
+
.flatMap(pi => (pi.paymentOrderItems || []).map(poi => poi.orderId))
|
|
7
|
+
.filter(Boolean)
|
|
8
|
+
.map(String);
|
|
9
|
+
};
|
package/lib/payment/index.js
CHANGED
|
@@ -4,6 +4,8 @@ const getMaxAmountToVoid = require('./getMaxAmountToVoid');
|
|
|
4
4
|
const getRefundableOrderAmount = require('./getRefundableOrderAmount');
|
|
5
5
|
const getMethodLabel = require('./getMethodLabel');
|
|
6
6
|
const getOverPaidOrders = require('./getOverPaidOrders');
|
|
7
|
+
const getPaymentItemIds = require('./getPaymentItemIds');
|
|
8
|
+
const getPaymentOrderIds = require('./getPaymentOrderIds');
|
|
7
9
|
|
|
8
10
|
const orderActions = (deps = {}) => {
|
|
9
11
|
const actions = {};
|
|
@@ -19,6 +21,8 @@ const orderActions = (deps = {}) => {
|
|
|
19
21
|
getRefundableOrderAmount: getRefundableOrderAmount(innerDeps),
|
|
20
22
|
getMethodLabel: getMethodLabel(innerDeps),
|
|
21
23
|
getOverPaidOrders: getOverPaidOrders(innerDeps),
|
|
24
|
+
getPaymentItemIds: getPaymentItemIds(innerDeps),
|
|
25
|
+
getPaymentOrderIds: getPaymentOrderIds(innerDeps),
|
|
22
26
|
});
|
|
23
27
|
|
|
24
28
|
Object.keys(freezedActions).forEach(actionName => {
|
package/lib/store/getSchedule.js
CHANGED
|
@@ -25,11 +25,9 @@ module.exports = ({ _, moment, settings, actions }) =>
|
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
const schedule = activeSchedules.find(item =>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return dayOfWeek.includes(day);
|
|
32
|
-
});
|
|
28
|
+
const schedule = activeSchedules.find(item =>
|
|
29
|
+
actions.isDayMatch({ schedule: item, day })
|
|
30
|
+
);
|
|
33
31
|
|
|
34
32
|
if (schedule) {
|
|
35
33
|
return {
|
package/lib/store/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const getStoreTimezone = require('./getStoreTimezone');
|
|
|
9
9
|
const hasReadyDateCapacitySettings = require('./hasReadyDateCapacitySettings');
|
|
10
10
|
const normalizeLimit = require('./normalizeLimit');
|
|
11
11
|
const pickBaseEndDate = require('./pickBaseEndDate');
|
|
12
|
+
const isDayMatch = require('./isDayMatch');
|
|
12
13
|
const pickEndDate = require('./pickEndDate');
|
|
13
14
|
const pickEndDateByCustomer = require('./pickEndDateByCustomer');
|
|
14
15
|
|
|
@@ -31,6 +32,7 @@ const storeActions = (deps = {}) => {
|
|
|
31
32
|
isNeareastMultiple: isNeareastMultiple(innerDeps),
|
|
32
33
|
normalizeLimit: normalizeLimit(innerDeps),
|
|
33
34
|
pickBaseEndDate: pickBaseEndDate(innerDeps),
|
|
35
|
+
isDayMatch: isDayMatch(innerDeps),
|
|
34
36
|
pickEndDate: pickEndDate(innerDeps),
|
|
35
37
|
pickEndDateByCustomer: pickEndDateByCustomer(innerDeps),
|
|
36
38
|
});
|
package/lib/store/pickEndDate.js
CHANGED
|
@@ -8,11 +8,19 @@ module.exports = ({ _, moment, settings, actions }) =>
|
|
|
8
8
|
readyDateCapacityCounts = []
|
|
9
9
|
) {
|
|
10
10
|
const timezone = actions.getStoreTimezone();
|
|
11
|
-
const
|
|
11
|
+
const todayTZ = moment().tz(timezone);
|
|
12
|
+
|
|
13
|
+
const today = isoWeekday || todayTZ.isoWeekday(); // monday 1 - sunday 7
|
|
14
|
+
|
|
15
|
+
let schedulesToEvaluate =
|
|
12
16
|
schedules && schedules.length
|
|
13
17
|
? schedules
|
|
14
18
|
: _.get(settings, 'order.schedules', []);
|
|
15
19
|
|
|
20
|
+
schedulesToEvaluate = schedulesToEvaluate.filter(each =>
|
|
21
|
+
actions.isDayMatch({ schedule: each, day: today })
|
|
22
|
+
);
|
|
23
|
+
|
|
16
24
|
const getCandidateDate = schedule => {
|
|
17
25
|
const candidateSchedules = schedule ? [schedule] : undefined;
|
|
18
26
|
let candidateDate = actions.pickBaseEndDate(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.167",
|
|
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": "
|
|
57
|
+
"gitHead": "62e86ff44452b3553488055bd6d92440e81bef9e"
|
|
58
58
|
}
|