@happychef/algorithm 1.2.9 → 1.2.10
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/.github/workflows/ci-cd.yml +103 -0
- package/README.md +144 -0
- package/__tests__/filters.test.js +276 -0
- package/__tests__/isDateAvailable.test.js +175 -0
- package/__tests__/isTimeAvailable.test.js +168 -0
- package/__tests__/restaurantData.test.js +422 -0
- package/__tests__/tableHelpers.test.js +247 -0
- package/jest.config.js +23 -0
- package/package.json +10 -1
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
const { isTimeAvailable } = require('../isTimeAvailable');
|
|
2
|
+
|
|
3
|
+
// Mock the timeblocksAvailable function
|
|
4
|
+
jest.mock('../processing/timeblocksAvailable', () => ({
|
|
5
|
+
timeblocksAvailable: jest.fn()
|
|
6
|
+
}));
|
|
7
|
+
|
|
8
|
+
const { timeblocksAvailable } = require('../processing/timeblocksAvailable');
|
|
9
|
+
|
|
10
|
+
describe('isTimeAvailable', () => {
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
jest.clearAllMocks();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('should return true when the specific time is available', () => {
|
|
16
|
+
timeblocksAvailable.mockReturnValue({
|
|
17
|
+
'12:00': { name: '12:00' },
|
|
18
|
+
'12:30': { name: '12:30' },
|
|
19
|
+
'13:00': { name: '13:00' }
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const data = { 'general-settings': {} };
|
|
23
|
+
const result = isTimeAvailable(data, '2025-06-15', '12:30', [], 4);
|
|
24
|
+
|
|
25
|
+
expect(result).toBe(true);
|
|
26
|
+
expect(timeblocksAvailable).toHaveBeenCalledWith(
|
|
27
|
+
data,
|
|
28
|
+
'2025-06-15',
|
|
29
|
+
[],
|
|
30
|
+
4,
|
|
31
|
+
[],
|
|
32
|
+
null,
|
|
33
|
+
false
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('should return false when the specific time is not available', () => {
|
|
38
|
+
timeblocksAvailable.mockReturnValue({
|
|
39
|
+
'12:00': { name: '12:00' },
|
|
40
|
+
'13:00': { name: '13:00' }
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const data = { 'general-settings': {} };
|
|
44
|
+
const result = isTimeAvailable(data, '2025-06-15', '12:30', [], 4);
|
|
45
|
+
|
|
46
|
+
expect(result).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('should return false when no timeblocks are available', () => {
|
|
50
|
+
timeblocksAvailable.mockReturnValue({});
|
|
51
|
+
|
|
52
|
+
const data = { 'general-settings': {} };
|
|
53
|
+
const result = isTimeAvailable(data, '2025-06-15', '12:00', [], 4);
|
|
54
|
+
|
|
55
|
+
expect(result).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('should handle reservations parameter', () => {
|
|
59
|
+
timeblocksAvailable.mockReturnValue({
|
|
60
|
+
'12:00': { name: '12:00' }
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const data = { 'general-settings': {} };
|
|
64
|
+
const reservations = [
|
|
65
|
+
{ date: '2025-06-15', time: '11:00', guests: 2 }
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
const result = isTimeAvailable(data, '2025-06-15', '12:00', reservations, 4);
|
|
69
|
+
|
|
70
|
+
expect(result).toBe(true);
|
|
71
|
+
expect(timeblocksAvailable).toHaveBeenCalledWith(
|
|
72
|
+
data,
|
|
73
|
+
'2025-06-15',
|
|
74
|
+
reservations,
|
|
75
|
+
4,
|
|
76
|
+
[],
|
|
77
|
+
null,
|
|
78
|
+
false
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('should handle blockedSlots parameter', () => {
|
|
83
|
+
timeblocksAvailable.mockReturnValue({
|
|
84
|
+
'12:00': { name: '12:00' }
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const data = { 'general-settings': {} };
|
|
88
|
+
const blockedSlots = [
|
|
89
|
+
{ date: '2025-06-15', time: '13:00' }
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
const result = isTimeAvailable(data, '2025-06-15', '12:00', [], 4, blockedSlots);
|
|
93
|
+
|
|
94
|
+
expect(result).toBe(true);
|
|
95
|
+
expect(timeblocksAvailable).toHaveBeenCalledWith(
|
|
96
|
+
data,
|
|
97
|
+
'2025-06-15',
|
|
98
|
+
[],
|
|
99
|
+
4,
|
|
100
|
+
blockedSlots,
|
|
101
|
+
null,
|
|
102
|
+
false
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('should handle giftcard parameter', () => {
|
|
107
|
+
timeblocksAvailable.mockReturnValue({
|
|
108
|
+
'12:00': { name: '12:00' }
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const data = { 'general-settings': {} };
|
|
112
|
+
|
|
113
|
+
const result = isTimeAvailable(data, '2025-06-15', '12:00', [], 4, [], 'LUNCH50');
|
|
114
|
+
|
|
115
|
+
expect(result).toBe(true);
|
|
116
|
+
expect(timeblocksAvailable).toHaveBeenCalledWith(
|
|
117
|
+
data,
|
|
118
|
+
'2025-06-15',
|
|
119
|
+
[],
|
|
120
|
+
4,
|
|
121
|
+
[],
|
|
122
|
+
'LUNCH50',
|
|
123
|
+
false
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('should handle isAdmin parameter', () => {
|
|
128
|
+
timeblocksAvailable.mockReturnValue({
|
|
129
|
+
'12:00': { name: '12:00' }
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const data = { 'general-settings': {} };
|
|
133
|
+
|
|
134
|
+
const result = isTimeAvailable(data, '2025-06-15', '12:00', [], 4, [], null, true);
|
|
135
|
+
|
|
136
|
+
expect(result).toBe(true);
|
|
137
|
+
expect(timeblocksAvailable).toHaveBeenCalledWith(
|
|
138
|
+
data,
|
|
139
|
+
'2025-06-15',
|
|
140
|
+
[],
|
|
141
|
+
4,
|
|
142
|
+
[],
|
|
143
|
+
null,
|
|
144
|
+
true
|
|
145
|
+
);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('should handle different guest counts', () => {
|
|
149
|
+
timeblocksAvailable.mockReturnValue({
|
|
150
|
+
'12:00': { name: '12:00' }
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const data = { 'general-settings': {} };
|
|
154
|
+
|
|
155
|
+
const result = isTimeAvailable(data, '2025-06-15', '12:00', [], 10);
|
|
156
|
+
|
|
157
|
+
expect(result).toBe(true);
|
|
158
|
+
expect(timeblocksAvailable).toHaveBeenCalledWith(
|
|
159
|
+
data,
|
|
160
|
+
'2025-06-15',
|
|
161
|
+
[],
|
|
162
|
+
10,
|
|
163
|
+
[],
|
|
164
|
+
null,
|
|
165
|
+
false
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
const {
|
|
2
|
+
getDataByDayAndMeal,
|
|
3
|
+
getDataByDateAndMeal,
|
|
4
|
+
getDataByDateAndTime,
|
|
5
|
+
daysOfWeekEnglish,
|
|
6
|
+
getMealTypeByTime,
|
|
7
|
+
parseTime
|
|
8
|
+
} = require('../restaurant_data/openinghours');
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
getDataByDateAndMealWithExceptions,
|
|
12
|
+
getDataByDateAndTimeWithExceptions
|
|
13
|
+
} = require('../restaurant_data/exceptions');
|
|
14
|
+
|
|
15
|
+
describe('openinghours - parseTime', () => {
|
|
16
|
+
test('should parse time correctly', () => {
|
|
17
|
+
expect(parseTime('12:30')).toBe(750);
|
|
18
|
+
expect(parseTime('00:00')).toBe(0);
|
|
19
|
+
expect(parseTime('23:59')).toBe(1439);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('openinghours - getMealTypeByTime', () => {
|
|
24
|
+
test('should identify meal types correctly', () => {
|
|
25
|
+
expect(getMealTypeByTime('08:00')).toBe('breakfast');
|
|
26
|
+
expect(getMealTypeByTime('12:00')).toBe('lunch');
|
|
27
|
+
expect(getMealTypeByTime('18:00')).toBe('dinner');
|
|
28
|
+
expect(getMealTypeByTime('06:00')).toBeNull();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('openinghours - getDataByDayAndMeal', () => {
|
|
33
|
+
test('should return meal data for a specific day and meal type', () => {
|
|
34
|
+
const data = {
|
|
35
|
+
'openinghours-lunch': {
|
|
36
|
+
schemeSettings: {
|
|
37
|
+
'Monday': {
|
|
38
|
+
enabled: true,
|
|
39
|
+
startTime: '11:00',
|
|
40
|
+
endTime: '15:00',
|
|
41
|
+
maxCapacity: 50
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const result = getDataByDayAndMeal(data, 'Monday', 'lunch');
|
|
48
|
+
expect(result).toBeDefined();
|
|
49
|
+
expect(result.enabled).toBe(true);
|
|
50
|
+
expect(result.startTime).toBe('11:00');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('should return null if meal key does not exist', () => {
|
|
54
|
+
const data = {};
|
|
55
|
+
const result = getDataByDayAndMeal(data, 'Monday', 'lunch');
|
|
56
|
+
expect(result).toBeNull();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('should return null if day data does not exist', () => {
|
|
60
|
+
const data = {
|
|
61
|
+
'openinghours-lunch': {
|
|
62
|
+
schemeSettings: {
|
|
63
|
+
'Tuesday': {
|
|
64
|
+
enabled: true,
|
|
65
|
+
startTime: '11:00',
|
|
66
|
+
endTime: '15:00'
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const result = getDataByDayAndMeal(data, 'Monday', 'lunch');
|
|
73
|
+
expect(result).toBeNull();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('openinghours - getDataByDateAndMeal', () => {
|
|
78
|
+
test('should return meal data for a specific date', () => {
|
|
79
|
+
const data = {
|
|
80
|
+
'openinghours-lunch': {
|
|
81
|
+
schemeSettings: {
|
|
82
|
+
'Monday': {
|
|
83
|
+
enabled: true,
|
|
84
|
+
startTime: '11:00',
|
|
85
|
+
endTime: '15:00',
|
|
86
|
+
maxCapacity: 50,
|
|
87
|
+
maxCapacityEnabled: true
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
'general-settings': {
|
|
92
|
+
duurReservatie: 120
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// 2025-06-16 is a Monday
|
|
97
|
+
const result = getDataByDateAndMeal(data, '2025-06-16', 'lunch');
|
|
98
|
+
expect(result).toBeDefined();
|
|
99
|
+
expect(result.enabled).toBe(true);
|
|
100
|
+
expect(result.startTime).toBe('11:00');
|
|
101
|
+
expect(result.endTime).toBe('17:00'); // 15:00 + 120 minutes
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('should return null if date is invalid', () => {
|
|
105
|
+
const data = {};
|
|
106
|
+
const result = getDataByDateAndMeal(data, 'invalid-date', 'lunch');
|
|
107
|
+
expect(result).toBeNull();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('should return null if meal is not enabled', () => {
|
|
111
|
+
const data = {
|
|
112
|
+
'openinghours-lunch': {
|
|
113
|
+
schemeSettings: {
|
|
114
|
+
'Monday': {
|
|
115
|
+
enabled: false,
|
|
116
|
+
startTime: '11:00',
|
|
117
|
+
endTime: '15:00'
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const result = getDataByDateAndMeal(data, '2025-06-16', 'lunch');
|
|
124
|
+
expect(result).toBeNull();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('should use general zitplaatsen when maxCapacityEnabled is false', () => {
|
|
128
|
+
const data = {
|
|
129
|
+
'openinghours-lunch': {
|
|
130
|
+
schemeSettings: {
|
|
131
|
+
'Monday': {
|
|
132
|
+
enabled: true,
|
|
133
|
+
startTime: '11:00',
|
|
134
|
+
endTime: '15:00',
|
|
135
|
+
maxCapacityEnabled: false
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
'general-settings': {
|
|
140
|
+
zitplaatsen: 100,
|
|
141
|
+
duurReservatie: 120
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const result = getDataByDateAndMeal(data, '2025-06-16', 'lunch');
|
|
146
|
+
expect(result.maxCapacity).toBe(100);
|
|
147
|
+
expect(result.maxCapacityEnabled).toBe(true);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe('openinghours - getDataByDateAndTime', () => {
|
|
152
|
+
test('should return meal data when time falls within meal period', () => {
|
|
153
|
+
const data = {
|
|
154
|
+
'openinghours-lunch': {
|
|
155
|
+
schemeSettings: {
|
|
156
|
+
'Monday': {
|
|
157
|
+
enabled: true,
|
|
158
|
+
startTime: '11:00',
|
|
159
|
+
endTime: '15:00',
|
|
160
|
+
maxCapacityEnabled: true,
|
|
161
|
+
maxCapacity: 50
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
'general-settings': {
|
|
166
|
+
duurReservatie: 120
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const result = getDataByDateAndTime(data, '2025-06-16', '12:00');
|
|
171
|
+
expect(result).toBeDefined();
|
|
172
|
+
expect(result.startTime).toBe('11:00');
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('should return null when time falls outside meal period', () => {
|
|
176
|
+
const data = {
|
|
177
|
+
'openinghours-lunch': {
|
|
178
|
+
schemeSettings: {
|
|
179
|
+
'Monday': {
|
|
180
|
+
enabled: true,
|
|
181
|
+
startTime: '11:00',
|
|
182
|
+
endTime: '15:00',
|
|
183
|
+
maxCapacityEnabled: true
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
'general-settings': {
|
|
188
|
+
duurReservatie: 120
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const result = getDataByDateAndTime(data, '2025-06-16', '18:00');
|
|
193
|
+
expect(result).toBeNull();
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe('exceptions - getDataByDateAndMealWithExceptions', () => {
|
|
198
|
+
test('should return regular meal data when no exceptions apply', () => {
|
|
199
|
+
const data = {
|
|
200
|
+
'openinghours-lunch': {
|
|
201
|
+
schemeSettings: {
|
|
202
|
+
'Monday': {
|
|
203
|
+
enabled: true,
|
|
204
|
+
startTime: '11:00',
|
|
205
|
+
endTime: '15:00',
|
|
206
|
+
maxCapacityEnabled: true,
|
|
207
|
+
maxCapacity: 50
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
'general-settings': {
|
|
212
|
+
duurReservatie: 120
|
|
213
|
+
},
|
|
214
|
+
exceptions: []
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const result = getDataByDateAndMealWithExceptions(data, '2025-06-16', 'lunch');
|
|
218
|
+
expect(result).toBeDefined();
|
|
219
|
+
expect(result.startTime).toBe('11:00');
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test('should return null when closure exception applies', () => {
|
|
223
|
+
const data = {
|
|
224
|
+
'openinghours-lunch': {
|
|
225
|
+
schemeSettings: {
|
|
226
|
+
'Monday': {
|
|
227
|
+
enabled: true,
|
|
228
|
+
startTime: '11:00',
|
|
229
|
+
endTime: '15:00'
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
'general-settings': {
|
|
234
|
+
duurReservatie: 120
|
|
235
|
+
},
|
|
236
|
+
exceptions: [
|
|
237
|
+
{
|
|
238
|
+
type: 'Sluiting',
|
|
239
|
+
timeframe: 'Volledige Dag',
|
|
240
|
+
startDate: '2025-06-16',
|
|
241
|
+
endDate: '2025-06-16',
|
|
242
|
+
daysOfWeek: []
|
|
243
|
+
}
|
|
244
|
+
]
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const result = getDataByDateAndMealWithExceptions(data, '2025-06-16', 'lunch');
|
|
248
|
+
expect(result).toBeNull();
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test('should return exception data when opening exception applies', () => {
|
|
252
|
+
const data = {
|
|
253
|
+
'openinghours-lunch': {
|
|
254
|
+
schemeSettings: {
|
|
255
|
+
'Monday': {
|
|
256
|
+
enabled: true,
|
|
257
|
+
startTime: '11:00',
|
|
258
|
+
endTime: '15:00'
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
'general-settings': {
|
|
263
|
+
duurReservatie: 120
|
|
264
|
+
},
|
|
265
|
+
exceptions: [
|
|
266
|
+
{
|
|
267
|
+
type: 'Opening',
|
|
268
|
+
timeframe: 'lunch',
|
|
269
|
+
startDate: '2025-06-16',
|
|
270
|
+
endDate: '2025-06-16',
|
|
271
|
+
daysOfWeek: [],
|
|
272
|
+
startHour: '12:00',
|
|
273
|
+
endHour: '16:00',
|
|
274
|
+
maxSeats: 60
|
|
275
|
+
}
|
|
276
|
+
]
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const result = getDataByDateAndMealWithExceptions(data, '2025-06-16', 'lunch');
|
|
280
|
+
expect(result).toBeDefined();
|
|
281
|
+
expect(result.startTime).toBe('12:00');
|
|
282
|
+
expect(result.endTime).toBe('18:00'); // 16:00 + 120 minutes
|
|
283
|
+
expect(result.maxCapacity).toBe(60);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test('should apply exception only on matching days of week', () => {
|
|
287
|
+
const data = {
|
|
288
|
+
'openinghours-lunch': {
|
|
289
|
+
schemeSettings: {
|
|
290
|
+
'Monday': {
|
|
291
|
+
enabled: true,
|
|
292
|
+
startTime: '11:00',
|
|
293
|
+
endTime: '15:00',
|
|
294
|
+
maxCapacityEnabled: true
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
'general-settings': {
|
|
299
|
+
duurReservatie: 120
|
|
300
|
+
},
|
|
301
|
+
exceptions: [
|
|
302
|
+
{
|
|
303
|
+
type: 'Sluiting',
|
|
304
|
+
timeframe: 'Volledige Dag',
|
|
305
|
+
startDate: '2025-06-01',
|
|
306
|
+
endDate: '2025-06-30',
|
|
307
|
+
daysOfWeek: ['dinsdag'] // Tuesday only
|
|
308
|
+
}
|
|
309
|
+
]
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// 2025-06-16 is Monday, so exception should not apply
|
|
313
|
+
const result = getDataByDateAndMealWithExceptions(data, '2025-06-16', 'lunch');
|
|
314
|
+
expect(result).toBeDefined();
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
test('should handle invalid date gracefully', () => {
|
|
318
|
+
const data = {
|
|
319
|
+
exceptions: []
|
|
320
|
+
};
|
|
321
|
+
const result = getDataByDateAndMealWithExceptions(data, 'invalid-date', 'lunch');
|
|
322
|
+
expect(result).toBeNull();
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
test('should prioritize exceptions in correct order: Opening > Sluiting > Uitzondering', () => {
|
|
326
|
+
const data = {
|
|
327
|
+
'openinghours-lunch': {
|
|
328
|
+
schemeSettings: {
|
|
329
|
+
'Monday': {
|
|
330
|
+
enabled: true,
|
|
331
|
+
startTime: '11:00',
|
|
332
|
+
endTime: '15:00'
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
'general-settings': {
|
|
337
|
+
duurReservatie: 120
|
|
338
|
+
},
|
|
339
|
+
exceptions: [
|
|
340
|
+
{
|
|
341
|
+
type: 'Uitzondering',
|
|
342
|
+
timeframe: 'lunch',
|
|
343
|
+
startDate: '2025-06-16',
|
|
344
|
+
endDate: '2025-06-16',
|
|
345
|
+
daysOfWeek: [],
|
|
346
|
+
startHour: '10:00',
|
|
347
|
+
endHour: '14:00',
|
|
348
|
+
maxSeats: 40
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
type: 'Opening',
|
|
352
|
+
timeframe: 'lunch',
|
|
353
|
+
startDate: '2025-06-16',
|
|
354
|
+
endDate: '2025-06-16',
|
|
355
|
+
daysOfWeek: [],
|
|
356
|
+
startHour: '12:00',
|
|
357
|
+
endHour: '16:00',
|
|
358
|
+
maxSeats: 60
|
|
359
|
+
}
|
|
360
|
+
]
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const result = getDataByDateAndMealWithExceptions(data, '2025-06-16', 'lunch');
|
|
364
|
+
expect(result.startTime).toBe('12:00'); // Opening exception takes priority
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
describe('exceptions - getDataByDateAndTimeWithExceptions', () => {
|
|
369
|
+
test('should return meal data when time falls within meal period with exceptions', () => {
|
|
370
|
+
const data = {
|
|
371
|
+
'openinghours-lunch': {
|
|
372
|
+
schemeSettings: {
|
|
373
|
+
'Monday': {
|
|
374
|
+
enabled: true,
|
|
375
|
+
startTime: '11:00',
|
|
376
|
+
endTime: '15:00',
|
|
377
|
+
maxCapacityEnabled: true
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
'general-settings': {
|
|
382
|
+
duurReservatie: 120
|
|
383
|
+
},
|
|
384
|
+
exceptions: []
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
const result = getDataByDateAndTimeWithExceptions(data, '2025-06-16', '12:00');
|
|
388
|
+
expect(result).toBeDefined();
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
test('should return null when time falls outside exception meal period', () => {
|
|
392
|
+
const data = {
|
|
393
|
+
'openinghours-lunch': {
|
|
394
|
+
schemeSettings: {
|
|
395
|
+
'Monday': {
|
|
396
|
+
enabled: true,
|
|
397
|
+
startTime: '11:00',
|
|
398
|
+
endTime: '15:00'
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
'general-settings': {
|
|
403
|
+
duurReservatie: 120
|
|
404
|
+
},
|
|
405
|
+
exceptions: [
|
|
406
|
+
{
|
|
407
|
+
type: 'Opening',
|
|
408
|
+
timeframe: 'lunch',
|
|
409
|
+
startDate: '2025-06-16',
|
|
410
|
+
endDate: '2025-06-16',
|
|
411
|
+
daysOfWeek: [],
|
|
412
|
+
startHour: '13:00',
|
|
413
|
+
endHour: '14:00',
|
|
414
|
+
maxSeats: 30
|
|
415
|
+
}
|
|
416
|
+
]
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
const result = getDataByDateAndTimeWithExceptions(data, '2025-06-16', '12:00');
|
|
420
|
+
expect(result).toBeNull(); // 12:00 is before exception start time 13:00
|
|
421
|
+
});
|
|
422
|
+
});
|