@darkpos/pricing 1.0.166 → 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.
@@ -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,
@@ -25,11 +25,9 @@ module.exports = ({ _, moment, settings, actions }) =>
25
25
  };
26
26
  }
27
27
 
28
- const schedule = activeSchedules.find(item => {
29
- const { dayOfWeek } = item || {};
30
- if (!dayOfWeek || !dayOfWeek.length) return true;
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 {
@@ -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
  });
@@ -0,0 +1,6 @@
1
+ module.exports = () =>
2
+ function isDayMatch({ schedule, day }) {
3
+ const { dayOfWeek } = schedule || {};
4
+ if (!dayOfWeek || !dayOfWeek.length) return true;
5
+ return dayOfWeek.includes(day);
6
+ };
@@ -8,11 +8,19 @@ module.exports = ({ _, moment, settings, actions }) =>
8
8
  readyDateCapacityCounts = []
9
9
  ) {
10
10
  const timezone = actions.getStoreTimezone();
11
- const schedulesToEvaluate =
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.166",
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": "e51c44c8e3b47c531140a33cf4f9bea75055a8df"
57
+ "gitHead": "62e86ff44452b3553488055bd6d92440e81bef9e"
58
58
  }