@darkpos/pricing 1.0.90 → 1.0.91

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,96 @@
1
+ const moment = require('moment-timezone');
2
+ const usePricing = require('../../lib/index');
3
+
4
+ const defaults = {
5
+ store: {
6
+ _settings: {
7
+ order: {
8
+ endDate: {
9
+ readySchedule: [
10
+ {
11
+ _id: '682373ef8256034ae1f2c195',
12
+ dayOfWeek: [2],
13
+ recommended: 'auto_recommended',
14
+ addDays: 1,
15
+ cutDay: 1,
16
+ skipDays: undefined,
17
+ readyHour: null,
18
+ cutHour: null,
19
+ },
20
+ ],
21
+ },
22
+ },
23
+ },
24
+ },
25
+ };
26
+ describe('getRecommendedEndDate function', () => {
27
+ test('getRecommendedEndDate, skipDays undefined', () => {
28
+ const pricingService = usePricing(defaults);
29
+ const now = moment('2025-05-13T15:00:00Z').tz('America/New_York');
30
+ jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
31
+
32
+ const result = pricingService.store.getRecommendedEndDate();
33
+ expect(result).toBe('2025-05-14T15:00:00Z'); // 2025-05-14T15:00:00Z
34
+ });
35
+
36
+ test('getRecommendedEndDate, skipDays with dayOfWeek undefined', () => {
37
+ const pricingService = usePricing({
38
+ store: {
39
+ _settings: {
40
+ order: {
41
+ endDate: {
42
+ readySchedule: [
43
+ {
44
+ _id: '682373ef8256034ae1f2c195',
45
+ dayOfWeek: null,
46
+ recommended: 'auto_recommended',
47
+ addDays: 1,
48
+ cutDay: 1,
49
+ skipDays: [1],
50
+ readyHour: null,
51
+ cutHour: null,
52
+ },
53
+ ],
54
+ },
55
+ },
56
+ },
57
+ },
58
+ });
59
+ const now = moment('2025-05-13T15:00:00Z').tz('America/New_York');
60
+ jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
61
+
62
+ const result = pricingService.store.getRecommendedEndDate();
63
+
64
+ expect(result).toBe(null); // null
65
+ });
66
+ test('getRecommendedEndDate, skipDays with one day', () => {
67
+ const pricingService = usePricing({
68
+ store: {
69
+ _settings: {
70
+ order: {
71
+ endDate: {
72
+ readySchedule: [
73
+ {
74
+ _id: '682373ef8256034ae1f2c195',
75
+ dayOfWeek: [2],
76
+ recommended: 'auto_recommended',
77
+ addDays: 1,
78
+ cutDay: 1,
79
+ skipDays: [1],
80
+ readyHour: null,
81
+ cutHour: null,
82
+ },
83
+ ],
84
+ },
85
+ },
86
+ },
87
+ },
88
+ });
89
+ const now = moment('2025-05-13T15:00:00Z').tz('America/New_York');
90
+ jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
91
+
92
+ const result = pricingService.store.getRecommendedEndDate();
93
+
94
+ expect(result).toBe('2025-05-14T15:00:00Z'); // 2025-05-14T15:00:00Z
95
+ });
96
+ });
@@ -138,4 +138,19 @@ describe('pickEndDate function', () => {
138
138
 
139
139
  expect(result).toBe('2024-09-05T00:00:00Z'); // 2024-09-04 20:00:00 EDT
140
140
  });
141
+ test('Get EndDate, undefined skipdays', () => {
142
+ const schedule = {
143
+ addDays: 1,
144
+ readyHour: { hour: 20, minute: 0 },
145
+ cutHour: { hour: 16, minute: 0 },
146
+ cutDay: 1,
147
+ };
148
+
149
+ const now = moment('2025-05-13T15:00:00Z').tz('America/New_York');
150
+ jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
151
+
152
+ const result = pricingService.store.pickEndDate(schedule);
153
+
154
+ expect(result).toBe('2025-05-15T00:00:00Z'); // 2024-09-04 20:00:00 EDT
155
+ });
141
156
  });
@@ -1,22 +1,25 @@
1
- module.exports = ({ actions, settings }) =>
2
- function getRecommendedEndDate() {
3
- const readySchedule =
4
- settings.order &&
1
+ module.exports = ({ actions, settings }) => {
2
+ const getReadyScheduleSetting = () =>
3
+ (settings.order &&
5
4
  settings.order.endDate &&
6
- settings.order.endDate.readySchedule;
5
+ settings.order.endDate.readySchedule) ||
6
+ [];
7
+ return function getRecommendedEndDate() {
8
+ const readySchedule = getReadyScheduleSetting();
7
9
 
8
- if (readySchedule) {
9
- const dayOfWeek = new Date().getDay();
10
- const day = dayOfWeek || 7;
11
- const schedule = settings.order.endDate.readySchedule.find(item =>
12
- item.dayOfWeek.includes(day)
13
- );
14
- return schedule
15
- ? actions.pickEndDate({
16
- ...schedule,
17
- })
18
- : null;
19
- }
10
+ const dayOfWeek = new Date().getDay();
11
+ const day = dayOfWeek || 7;
12
+ const schedule = readySchedule.find(item => {
13
+ if (item && item.dayOfWeek) {
14
+ return item.dayOfWeek.includes(day);
15
+ }
16
+ return false;
17
+ });
20
18
 
21
- return null;
19
+ return schedule
20
+ ? actions.pickEndDate({
21
+ ...schedule,
22
+ })
23
+ : null;
22
24
  };
25
+ };
@@ -11,13 +11,8 @@ module.exports = ({ settings, _, moment }) => {
11
11
  const MAX_ADD_DAYS = 365;
12
12
 
13
13
  return function pickEndDate(schedule = {}) {
14
- const {
15
- addDays: addDaysParam,
16
- readyHour,
17
- skipDays = [],
18
- cutHour,
19
- cutDay = 0,
20
- } = schedule;
14
+ const { addDays: addDaysParam, readyHour, cutHour, cutDay = 0 } = schedule;
15
+ const skipDays = schedule.skipDays || [];
21
16
 
22
17
  const todayTZ = moment().tz(timezone);
23
18
  let endDateTZ = todayTZ.clone();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.90",
3
+ "version": "1.0.91",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -51,5 +51,5 @@
51
51
  "supertest": "^6.2.3",
52
52
  "supervisor": "^0.12.0"
53
53
  },
54
- "gitHead": "9c351c72bca0563fb454c0cb51d50dcaf49ba37d"
54
+ "gitHead": "5526c9bdbba87270466443c92066c06c9fa87d52"
55
55
  }