@happychef/algorithm 1.2.11 → 1.2.12

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.
Files changed (57) hide show
  1. package/.github/workflows/ci-cd.yml +234 -234
  2. package/BRANCH_PROTECTION_SETUP.md +167 -167
  3. package/CHANGELOG.md +8 -8
  4. package/README.md +144 -144
  5. package/RESERVERINGEN_GIDS.md +986 -986
  6. package/__tests__/filters.test.js +276 -276
  7. package/__tests__/isDateAvailable.test.js +175 -175
  8. package/__tests__/isTimeAvailable.test.js +168 -168
  9. package/__tests__/restaurantData.test.js +422 -422
  10. package/__tests__/tableHelpers.test.js +247 -247
  11. package/assignTables.js +424 -424
  12. package/changes/2025/December/PR2___change.md +14 -14
  13. package/changes/2025/December/PR3_add__change.md +20 -20
  14. package/changes/2025/December/PR4___.md +15 -15
  15. package/changes/2025/December/PR5___.md +15 -15
  16. package/changes/2025/December/PR6__del_.md +17 -17
  17. package/changes/2025/December/PR7_add__change.md +21 -21
  18. package/changes/2026/January/PR8_add__change.md +39 -0
  19. package/changes/2026/January/PR9_add__change.md +20 -0
  20. package/filters/maxArrivalsFilter.js +114 -114
  21. package/filters/maxGroupsFilter.js +221 -221
  22. package/filters/timeFilter.js +89 -89
  23. package/getAvailableTimeblocks.js +158 -158
  24. package/grouping.js +162 -162
  25. package/index.js +42 -42
  26. package/isDateAvailable.js +80 -80
  27. package/isDateAvailableWithTableCheck.js +171 -171
  28. package/isTimeAvailable.js +25 -25
  29. package/jest.config.js +23 -23
  30. package/package.json +27 -27
  31. package/processing/dailyGuestCounts.js +73 -73
  32. package/processing/mealTypeCount.js +133 -133
  33. package/processing/timeblocksAvailable.js +167 -167
  34. package/reservation_data/counter.js +64 -64
  35. package/restaurant_data/exceptions.js +149 -149
  36. package/restaurant_data/openinghours.js +123 -123
  37. package/simulateTableAssignment.js +709 -699
  38. package/tableHelpers.js +178 -178
  39. package/tables/time/parseTime.js +19 -19
  40. package/tables/time/shifts.js +7 -7
  41. package/tables/utils/calculateDistance.js +13 -13
  42. package/tables/utils/isTableFreeForAllSlots.js +14 -14
  43. package/tables/utils/isTemporaryTableValid.js +39 -39
  44. package/test/test_counter.js +194 -194
  45. package/test/test_dailyCount.js +81 -81
  46. package/test/test_datesAvailable.js +106 -106
  47. package/test/test_exceptions.js +172 -172
  48. package/test/test_isDateAvailable.js +330 -330
  49. package/test/test_mealTypeCount.js +54 -54
  50. package/test/test_timesAvailable.js +88 -88
  51. package/test-detailed-filter.js +100 -100
  52. package/test-lunch-debug.js +110 -110
  53. package/test-max-arrivals-filter.js +79 -79
  54. package/test-meal-stop-fix.js +147 -147
  55. package/test-meal-stop-simple.js +93 -93
  56. package/test-timezone-debug.js +47 -47
  57. package/test.js +336 -336
@@ -1,422 +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
- });
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
+ });