@happychef/algorithm 1.2.9 → 1.2.11
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 +234 -0
- package/BRANCH_PROTECTION_SETUP.md +167 -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/assignTables.js +149 -123
- package/changes/2025/December/PR4___.md +16 -0
- package/changes/2025/December/PR5___.md +16 -0
- package/changes/2025/December/PR6__del_.md +18 -0
- package/changes/2025/December/PR7_add__change.md +22 -0
- package/jest.config.js +23 -0
- package/package.json +10 -1
- package/tableHelpers.js +2 -2
- package/test-detailed-filter.js +100 -100
- package/test-lunch-debug.js +110 -110
- package/test-max-arrivals-filter.js +79 -79
- package/test-timezone-debug.js +47 -47
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
const {
|
|
2
|
+
parseTime,
|
|
3
|
+
getMealTypeByTime,
|
|
4
|
+
getAllTables,
|
|
5
|
+
isTemporaryTableValid,
|
|
6
|
+
shifts
|
|
7
|
+
} = require('../tableHelpers');
|
|
8
|
+
|
|
9
|
+
describe('tableHelpers - parseTime', () => {
|
|
10
|
+
test('should parse valid time string correctly', () => {
|
|
11
|
+
expect(parseTime('12:30')).toBe(750); // 12*60 + 30 = 750
|
|
12
|
+
expect(parseTime('00:00')).toBe(0);
|
|
13
|
+
expect(parseTime('23:59')).toBe(1439);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('should return NaN for invalid time strings', () => {
|
|
17
|
+
expect(parseTime('')).toBeNaN();
|
|
18
|
+
expect(parseTime(null)).toBeNaN();
|
|
19
|
+
expect(parseTime(undefined)).toBeNaN();
|
|
20
|
+
expect(parseTime('25:00')).toBeNaN(); // Invalid hour
|
|
21
|
+
expect(parseTime('12:60')).toBeNaN(); // Invalid minute
|
|
22
|
+
expect(parseTime('12')).toBeNaN(); // Missing colon
|
|
23
|
+
expect(parseTime('ab:cd')).toBeNaN(); // Not numbers
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('should handle edge cases', () => {
|
|
27
|
+
expect(parseTime('0:0')).toBe(0);
|
|
28
|
+
expect(parseTime('1:1')).toBe(61);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('tableHelpers - getMealTypeByTime', () => {
|
|
33
|
+
test('should identify breakfast times correctly', () => {
|
|
34
|
+
expect(getMealTypeByTime('07:00')).toBe('breakfast');
|
|
35
|
+
expect(getMealTypeByTime('09:30')).toBe('breakfast');
|
|
36
|
+
expect(getMealTypeByTime('10:59')).toBe('breakfast');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('should identify lunch times correctly', () => {
|
|
40
|
+
expect(getMealTypeByTime('11:00')).toBe('lunch');
|
|
41
|
+
expect(getMealTypeByTime('12:30')).toBe('lunch');
|
|
42
|
+
expect(getMealTypeByTime('15:59')).toBe('lunch');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('should identify dinner times correctly', () => {
|
|
46
|
+
expect(getMealTypeByTime('16:00')).toBe('dinner');
|
|
47
|
+
expect(getMealTypeByTime('18:30')).toBe('dinner');
|
|
48
|
+
expect(getMealTypeByTime('22:59')).toBe('dinner');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('should return null for times outside defined shifts', () => {
|
|
52
|
+
expect(getMealTypeByTime('06:59')).toBeNull();
|
|
53
|
+
expect(getMealTypeByTime('23:00')).toBeNull();
|
|
54
|
+
expect(getMealTypeByTime('02:00')).toBeNull();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('should return null for invalid time strings', () => {
|
|
58
|
+
expect(getMealTypeByTime('invalid')).toBeNull();
|
|
59
|
+
expect(getMealTypeByTime('')).toBeNull();
|
|
60
|
+
expect(getMealTypeByTime(null)).toBeNull();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('tableHelpers - getAllTables', () => {
|
|
65
|
+
test('should extract tables correctly from restaurant data', () => {
|
|
66
|
+
const restaurantData = {
|
|
67
|
+
floors: [
|
|
68
|
+
{
|
|
69
|
+
tables: [
|
|
70
|
+
{
|
|
71
|
+
objectType: 'Tafel',
|
|
72
|
+
id: 'table1',
|
|
73
|
+
tableNumber: 1,
|
|
74
|
+
minCapacity: 2,
|
|
75
|
+
maxCapacity: 4,
|
|
76
|
+
priority: 1,
|
|
77
|
+
x: 10,
|
|
78
|
+
y: 20,
|
|
79
|
+
isTemporary: false
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
objectType: 'Tafel',
|
|
83
|
+
id: 'table2',
|
|
84
|
+
tableNumber: { $numberInt: '2' },
|
|
85
|
+
minCapacity: { $numberInt: '4' },
|
|
86
|
+
maxCapacity: { $numberInt: '6' },
|
|
87
|
+
priority: { $numberInt: '2' },
|
|
88
|
+
x: { $numberInt: '30' },
|
|
89
|
+
y: { $numberInt: '40' },
|
|
90
|
+
isTemporary: false
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const tables = getAllTables(restaurantData);
|
|
98
|
+
expect(tables).toHaveLength(2);
|
|
99
|
+
expect(tables[0].tableNumber).toBe(1);
|
|
100
|
+
expect(tables[0].maxCapacity).toBe(4);
|
|
101
|
+
expect(tables[1].tableNumber).toBe(2);
|
|
102
|
+
expect(tables[1].maxCapacity).toBe(6);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('should sort tables by maxCapacity, priority, and minCapacity', () => {
|
|
106
|
+
const restaurantData = {
|
|
107
|
+
floors: [
|
|
108
|
+
{
|
|
109
|
+
tables: [
|
|
110
|
+
{
|
|
111
|
+
objectType: 'Tafel',
|
|
112
|
+
id: 'table1',
|
|
113
|
+
tableNumber: 1,
|
|
114
|
+
minCapacity: 2,
|
|
115
|
+
maxCapacity: 6,
|
|
116
|
+
priority: 1,
|
|
117
|
+
x: 10,
|
|
118
|
+
y: 20
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
objectType: 'Tafel',
|
|
122
|
+
id: 'table2',
|
|
123
|
+
tableNumber: 2,
|
|
124
|
+
minCapacity: 2,
|
|
125
|
+
maxCapacity: 4,
|
|
126
|
+
priority: 1,
|
|
127
|
+
x: 30,
|
|
128
|
+
y: 40
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const tables = getAllTables(restaurantData);
|
|
136
|
+
expect(tables[0].tableNumber).toBe(2); // Smaller maxCapacity comes first
|
|
137
|
+
expect(tables[1].tableNumber).toBe(1);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('should handle empty or missing data gracefully', () => {
|
|
141
|
+
expect(getAllTables({})).toEqual([]);
|
|
142
|
+
expect(getAllTables({ floors: [] })).toEqual([]);
|
|
143
|
+
expect(getAllTables(null)).toEqual([]);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('should filter out non-Tafel objects', () => {
|
|
147
|
+
const restaurantData = {
|
|
148
|
+
floors: [
|
|
149
|
+
{
|
|
150
|
+
tables: [
|
|
151
|
+
{
|
|
152
|
+
objectType: 'Wall',
|
|
153
|
+
id: 'wall1',
|
|
154
|
+
tableNumber: 1
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
objectType: 'Tafel',
|
|
158
|
+
id: 'table1',
|
|
159
|
+
tableNumber: 2,
|
|
160
|
+
minCapacity: 2,
|
|
161
|
+
maxCapacity: 4,
|
|
162
|
+
priority: 1,
|
|
163
|
+
x: 10,
|
|
164
|
+
y: 20
|
|
165
|
+
}
|
|
166
|
+
]
|
|
167
|
+
}
|
|
168
|
+
]
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const tables = getAllTables(restaurantData);
|
|
172
|
+
expect(tables).toHaveLength(1);
|
|
173
|
+
expect(tables[0].tableNumber).toBe(2);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe('tableHelpers - isTemporaryTableValid', () => {
|
|
178
|
+
test('should return true for non-temporary tables', () => {
|
|
179
|
+
const table = {
|
|
180
|
+
tableNumber: 1,
|
|
181
|
+
isTemporary: false
|
|
182
|
+
};
|
|
183
|
+
expect(isTemporaryTableValid(table, '2025-06-15', '12:00')).toBe(true);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('should validate temporary table within date range and correct meal type', () => {
|
|
187
|
+
const table = {
|
|
188
|
+
tableNumber: 1,
|
|
189
|
+
isTemporary: true,
|
|
190
|
+
startDate: '2025-06-01',
|
|
191
|
+
endDate: '2025-06-30',
|
|
192
|
+
application: 'lunch'
|
|
193
|
+
};
|
|
194
|
+
expect(isTemporaryTableValid(table, '2025-06-15', '12:00')).toBe(true);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test('should reject temporary table outside date range', () => {
|
|
198
|
+
const table = {
|
|
199
|
+
tableNumber: 1,
|
|
200
|
+
isTemporary: true,
|
|
201
|
+
startDate: '2025-06-01',
|
|
202
|
+
endDate: '2025-06-30',
|
|
203
|
+
application: 'lunch'
|
|
204
|
+
};
|
|
205
|
+
expect(isTemporaryTableValid(table, '2025-07-01', '12:00')).toBe(false);
|
|
206
|
+
expect(isTemporaryTableValid(table, '2025-05-31', '12:00')).toBe(false);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test('should reject temporary table with wrong meal type', () => {
|
|
210
|
+
const table = {
|
|
211
|
+
tableNumber: 1,
|
|
212
|
+
isTemporary: true,
|
|
213
|
+
startDate: '2025-06-01',
|
|
214
|
+
endDate: '2025-06-30',
|
|
215
|
+
application: 'dinner'
|
|
216
|
+
};
|
|
217
|
+
expect(isTemporaryTableValid(table, '2025-06-15', '12:00')).toBe(false); // lunch time
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test('should reject temporary table with missing date range', () => {
|
|
221
|
+
const table = {
|
|
222
|
+
tableNumber: 1,
|
|
223
|
+
isTemporary: true,
|
|
224
|
+
application: 'lunch'
|
|
225
|
+
};
|
|
226
|
+
expect(isTemporaryTableValid(table, '2025-06-15', '12:00')).toBe(false);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test('should reject temporary table with invalid time', () => {
|
|
230
|
+
const table = {
|
|
231
|
+
tableNumber: 1,
|
|
232
|
+
isTemporary: true,
|
|
233
|
+
startDate: '2025-06-01',
|
|
234
|
+
endDate: '2025-06-30',
|
|
235
|
+
application: 'lunch'
|
|
236
|
+
};
|
|
237
|
+
expect(isTemporaryTableValid(table, '2025-06-15', 'invalid')).toBe(false);
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
describe('tableHelpers - shifts constant', () => {
|
|
242
|
+
test('should have correct shift definitions', () => {
|
|
243
|
+
expect(shifts.breakfast).toEqual({ start: '07:00', end: '11:00' });
|
|
244
|
+
expect(shifts.lunch).toEqual({ start: '11:00', end: '16:00' });
|
|
245
|
+
expect(shifts.dinner).toEqual({ start: '16:00', end: '23:00' });
|
|
246
|
+
});
|
|
247
|
+
});
|