@happychef/algorithm 1.4.0 → 1.4.1

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.
@@ -1,179 +1,175 @@
1
- const { isDateAvailable } = require('../isDateAvailable');
2
-
3
- // Mock the getAvailableTimeblocks function
4
- jest.mock('../getAvailableTimeblocks', () => ({
5
- getAvailableTimeblocks: jest.fn()
6
- }));
7
-
8
- const { getAvailableTimeblocks } = require('../getAvailableTimeblocks');
9
-
10
- describe('isDateAvailable', () => {
11
- beforeEach(() => {
12
- jest.clearAllMocks();
13
- });
14
-
15
- test('should return true when timeblocks are available', () => {
16
- getAvailableTimeblocks.mockReturnValue({
17
- '12:00': { name: '12:00' },
18
- '12:30': { name: '12:30' }
19
- });
20
-
21
- const data = {
22
- 'general-settings': {
23
- dagenInToekomst: 90
24
- }
25
- };
26
-
27
- const result = isDateAvailable(data, '2025-06-15', [], 4, [], null, false);
28
- expect(result).toBe(true);
29
- expect(getAvailableTimeblocks).toHaveBeenCalledWith(
30
- data,
31
- '2025-06-15',
32
- [],
33
- 4,
34
- [],
35
- null,
36
- false,
37
- null
38
- );
39
- });
40
-
41
- test('should return false when no timeblocks are available', () => {
42
- getAvailableTimeblocks.mockReturnValue({});
43
-
44
- const data = {
45
- 'general-settings': {
46
- dagenInToekomst: 90
47
- }
48
- };
49
-
50
- const result = isDateAvailable(data, '2025-06-15', [], 4);
51
- expect(result).toBe(false);
52
- });
53
-
54
- test('should return false when date is outside allowed range (non-admin)', () => {
55
- getAvailableTimeblocks.mockReturnValue({});
56
-
57
- const data = {
58
- 'general-settings': {
59
- dagenInToekomst: 1 // Only 1 day in future
60
- }
61
- };
62
-
63
- // Use a date far in the future - the function will calculate if it's out of range
64
- const result = isDateAvailable(data, '2099-12-31', [], 4, [], null, false);
65
- expect(result).toBe(false);
66
- });
67
-
68
- test('should allow dates outside range when isAdmin is true', () => {
69
- getAvailableTimeblocks.mockReturnValue({
70
- '12:00': { name: '12:00' }
71
- });
72
-
73
- const data = {
74
- 'general-settings': {
75
- dagenInToekomst: 1
76
- }
77
- };
78
-
79
- const result = isDateAvailable(data, '2099-12-31', [], 4, [], null, true);
80
- expect(result).toBe(true);
81
- });
82
-
83
- test('should use default dagenInToekomst of 90 when not specified', () => {
84
- getAvailableTimeblocks.mockReturnValue({
85
- '12:00': { name: '12:00' }
86
- });
87
-
88
- const data = {
89
- 'general-settings': {}
90
- };
91
-
92
- // Use a reasonable date within 90 days
93
- const result = isDateAvailable(data, '2025-02-01', [], 4);
94
- expect(result).toBe(true);
95
- });
96
-
97
- test('should handle giftcard parameter', () => {
98
- getAvailableTimeblocks.mockReturnValue({
99
- '12:00': { name: '12:00' }
100
- });
101
-
102
- const data = {
103
- 'general-settings': {
104
- dagenInToekomst: 90
105
- }
106
- };
107
-
108
- const result = isDateAvailable(data, '2025-02-01', [], 4, [], 'LUNCH50');
109
- expect(result).toBe(true);
110
- expect(getAvailableTimeblocks).toHaveBeenCalledWith(
111
- data,
112
- '2025-02-01',
113
- [],
114
- 4,
115
- [],
116
- 'LUNCH50',
117
- false,
118
- null
119
- );
120
- });
121
-
122
- test('should handle blockedSlots parameter', () => {
123
- getAvailableTimeblocks.mockReturnValue({
124
- '12:00': { name: '12:00' }
125
- });
126
-
127
- const data = {
128
- 'general-settings': {
129
- dagenInToekomst: 90
130
- }
131
- };
132
-
133
- const blockedSlots = [
134
- { date: '2025-02-01', time: '13:00' }
135
- ];
136
-
137
- const result = isDateAvailable(data, '2025-02-01', [], 4, blockedSlots);
138
- expect(result).toBe(true);
139
- expect(getAvailableTimeblocks).toHaveBeenCalledWith(
140
- data,
141
- '2025-02-01',
142
- [],
143
- 4,
144
- blockedSlots,
145
- null,
146
- false,
147
- null
148
- );
149
- });
150
-
151
- test('should handle reservations array', () => {
152
- getAvailableTimeblocks.mockReturnValue({
153
- '12:00': { name: '12:00' }
154
- });
155
-
156
- const data = {
157
- 'general-settings': {
158
- dagenInToekomst: 90
159
- }
160
- };
161
-
162
- const reservations = [
163
- { date: '2025-02-01', time: '12:00', guests: 2 }
164
- ];
165
-
166
- const result = isDateAvailable(data, '2025-02-01', reservations, 4);
167
- expect(result).toBe(true);
168
- expect(getAvailableTimeblocks).toHaveBeenCalledWith(
169
- data,
170
- '2025-02-01',
171
- reservations,
172
- 4,
173
- [],
174
- null,
175
- false,
176
- null
177
- );
178
- });
179
- });
1
+ const { isDateAvailable } = require('../isDateAvailable');
2
+
3
+ // Mock the getAvailableTimeblocks function
4
+ jest.mock('../getAvailableTimeblocks', () => ({
5
+ getAvailableTimeblocks: jest.fn()
6
+ }));
7
+
8
+ const { getAvailableTimeblocks } = require('../getAvailableTimeblocks');
9
+
10
+ describe('isDateAvailable', () => {
11
+ beforeEach(() => {
12
+ jest.clearAllMocks();
13
+ });
14
+
15
+ test('should return true when timeblocks are available', () => {
16
+ getAvailableTimeblocks.mockReturnValue({
17
+ '12:00': { name: '12:00' },
18
+ '12:30': { name: '12:30' }
19
+ });
20
+
21
+ const data = {
22
+ 'general-settings': {
23
+ dagenInToekomst: 90
24
+ }
25
+ };
26
+
27
+ const result = isDateAvailable(data, '2025-06-15', [], 4, [], null, false);
28
+ expect(result).toBe(true);
29
+ expect(getAvailableTimeblocks).toHaveBeenCalledWith(
30
+ data,
31
+ '2025-06-15',
32
+ [],
33
+ 4,
34
+ [],
35
+ null,
36
+ false
37
+ );
38
+ });
39
+
40
+ test('should return false when no timeblocks are available', () => {
41
+ getAvailableTimeblocks.mockReturnValue({});
42
+
43
+ const data = {
44
+ 'general-settings': {
45
+ dagenInToekomst: 90
46
+ }
47
+ };
48
+
49
+ const result = isDateAvailable(data, '2025-06-15', [], 4);
50
+ expect(result).toBe(false);
51
+ });
52
+
53
+ test('should return false when date is outside allowed range (non-admin)', () => {
54
+ getAvailableTimeblocks.mockReturnValue({});
55
+
56
+ const data = {
57
+ 'general-settings': {
58
+ dagenInToekomst: 1 // Only 1 day in future
59
+ }
60
+ };
61
+
62
+ // Use a date far in the future - the function will calculate if it's out of range
63
+ const result = isDateAvailable(data, '2099-12-31', [], 4, [], null, false);
64
+ expect(result).toBe(false);
65
+ });
66
+
67
+ test('should allow dates outside range when isAdmin is true', () => {
68
+ getAvailableTimeblocks.mockReturnValue({
69
+ '12:00': { name: '12:00' }
70
+ });
71
+
72
+ const data = {
73
+ 'general-settings': {
74
+ dagenInToekomst: 1
75
+ }
76
+ };
77
+
78
+ const result = isDateAvailable(data, '2099-12-31', [], 4, [], null, true);
79
+ expect(result).toBe(true);
80
+ });
81
+
82
+ test('should use default dagenInToekomst of 90 when not specified', () => {
83
+ getAvailableTimeblocks.mockReturnValue({
84
+ '12:00': { name: '12:00' }
85
+ });
86
+
87
+ const data = {
88
+ 'general-settings': {}
89
+ };
90
+
91
+ // Use a reasonable date within 90 days
92
+ const result = isDateAvailable(data, '2025-02-01', [], 4);
93
+ expect(result).toBe(true);
94
+ });
95
+
96
+ test('should handle giftcard parameter', () => {
97
+ getAvailableTimeblocks.mockReturnValue({
98
+ '12:00': { name: '12:00' }
99
+ });
100
+
101
+ const data = {
102
+ 'general-settings': {
103
+ dagenInToekomst: 90
104
+ }
105
+ };
106
+
107
+ const result = isDateAvailable(data, '2025-02-01', [], 4, [], 'LUNCH50');
108
+ expect(result).toBe(true);
109
+ expect(getAvailableTimeblocks).toHaveBeenCalledWith(
110
+ data,
111
+ '2025-02-01',
112
+ [],
113
+ 4,
114
+ [],
115
+ 'LUNCH50',
116
+ false
117
+ );
118
+ });
119
+
120
+ test('should handle blockedSlots parameter', () => {
121
+ getAvailableTimeblocks.mockReturnValue({
122
+ '12:00': { name: '12:00' }
123
+ });
124
+
125
+ const data = {
126
+ 'general-settings': {
127
+ dagenInToekomst: 90
128
+ }
129
+ };
130
+
131
+ const blockedSlots = [
132
+ { date: '2025-02-01', time: '13:00' }
133
+ ];
134
+
135
+ const result = isDateAvailable(data, '2025-02-01', [], 4, blockedSlots);
136
+ expect(result).toBe(true);
137
+ expect(getAvailableTimeblocks).toHaveBeenCalledWith(
138
+ data,
139
+ '2025-02-01',
140
+ [],
141
+ 4,
142
+ blockedSlots,
143
+ null,
144
+ false
145
+ );
146
+ });
147
+
148
+ test('should handle reservations array', () => {
149
+ getAvailableTimeblocks.mockReturnValue({
150
+ '12:00': { name: '12:00' }
151
+ });
152
+
153
+ const data = {
154
+ 'general-settings': {
155
+ dagenInToekomst: 90
156
+ }
157
+ };
158
+
159
+ const reservations = [
160
+ { date: '2025-02-01', time: '12:00', guests: 2 }
161
+ ];
162
+
163
+ const result = isDateAvailable(data, '2025-02-01', reservations, 4);
164
+ expect(result).toBe(true);
165
+ expect(getAvailableTimeblocks).toHaveBeenCalledWith(
166
+ data,
167
+ '2025-02-01',
168
+ reservations,
169
+ 4,
170
+ [],
171
+ null,
172
+ false
173
+ );
174
+ });
175
+ });