@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,276 +1,276 @@
1
- const { filterTimeblocksByMaxArrivals } = require('../filters/maxArrivalsFilter');
2
- const { filterTimeblocksByMaxGroups } = require('../filters/maxGroupsFilter');
3
-
4
- describe('maxArrivalsFilter', () => {
5
- test('should keep timeblocks when no max arrivals config exists', () => {
6
- const restaurantData = {};
7
- const timeblocks = {
8
- '12:00': { name: '12:00' },
9
- '12:30': { name: '12:30' }
10
- };
11
- const result = filterTimeblocksByMaxArrivals(restaurantData, '2025-06-15', timeblocks, [], 4);
12
- expect(result).toEqual(timeblocks);
13
- });
14
-
15
- test('should filter out timeblocks that exceed max arrivals', () => {
16
- const restaurantData = {
17
- 'max-arrivals-lunch': {
18
- '12:00': 10,
19
- '12:30': 8
20
- }
21
- };
22
- const timeblocks = {
23
- '12:00': { name: '12:00' },
24
- '12:30': { name: '12:30' }
25
- };
26
- const reservations = [
27
- { date: '2025-06-15', time: '12:00', guests: 8 }
28
- ];
29
-
30
- // Adding 4 guests to 12:00 (8 + 4 = 12 > 10) should filter it out
31
- const result = filterTimeblocksByMaxArrivals(restaurantData, '2025-06-15', timeblocks, reservations, 4);
32
- expect(result['12:00']).toBeUndefined();
33
- expect(result['12:30']).toBeDefined();
34
- });
35
-
36
- test('should keep timeblocks when within max arrivals limit', () => {
37
- const restaurantData = {
38
- 'max-arrivals-lunch': {
39
- '12:00': 20
40
- }
41
- };
42
- const timeblocks = {
43
- '12:00': { name: '12:00' }
44
- };
45
- const reservations = [
46
- { date: '2025-06-15', time: '12:00', guests: 10 }
47
- ];
48
-
49
- const result = filterTimeblocksByMaxArrivals(restaurantData, '2025-06-15', timeblocks, reservations, 5);
50
- expect(result['12:00']).toBeDefined();
51
- });
52
-
53
- test('should handle MongoDB NumberInt format', () => {
54
- const restaurantData = {
55
- 'max-arrivals-lunch': {
56
- '12:00': { $numberInt: '20' }
57
- }
58
- };
59
- const timeblocks = {
60
- '12:00': { name: '12:00' }
61
- };
62
- const reservations = [
63
- { date: '2025-06-15', time: '12:00', guests: 15 }
64
- ];
65
-
66
- const result = filterTimeblocksByMaxArrivals(restaurantData, '2025-06-15', timeblocks, reservations, 5);
67
- expect(result['12:00']).toBeDefined();
68
- });
69
-
70
- test('should handle breakfast times correctly', () => {
71
- const restaurantData = {
72
- 'max-arrivals-breakfast': {
73
- '09:00': 15
74
- }
75
- };
76
- const timeblocks = {
77
- '09:00': { name: '09:00' }
78
- };
79
- const reservations = [
80
- { date: '2025-06-15', time: '09:00', guests: 12 }
81
- ];
82
-
83
- const result = filterTimeblocksByMaxArrivals(restaurantData, '2025-06-15', timeblocks, reservations, 2);
84
- expect(result['09:00']).toBeDefined();
85
- });
86
-
87
- test('should handle dinner times correctly', () => {
88
- const restaurantData = {
89
- 'max-arrivals-dinner': {
90
- '18:00': 30
91
- }
92
- };
93
- const timeblocks = {
94
- '18:00': { name: '18:00' }
95
- };
96
- const reservations = [
97
- { date: '2025-06-15', time: '18:00', guests: 20 }
98
- ];
99
-
100
- const result = filterTimeblocksByMaxArrivals(restaurantData, '2025-06-15', timeblocks, reservations, 5);
101
- expect(result['18:00']).toBeDefined();
102
- });
103
-
104
- test('should only count arrivals on the specific date', () => {
105
- const restaurantData = {
106
- 'max-arrivals-lunch': {
107
- '12:00': 10
108
- }
109
- };
110
- const timeblocks = {
111
- '12:00': { name: '12:00' }
112
- };
113
- const reservations = [
114
- { date: '2025-06-14', time: '12:00', guests: 8 }, // Different date
115
- { date: '2025-06-15', time: '12:00', guests: 2 }
116
- ];
117
-
118
- const result = filterTimeblocksByMaxArrivals(restaurantData, '2025-06-15', timeblocks, reservations, 5);
119
- expect(result['12:00']).toBeDefined(); // 2 + 5 = 7 <= 10
120
- });
121
- });
122
-
123
- describe('maxGroupsFilter', () => {
124
- test('should keep timeblocks when no max groups config exists', () => {
125
- const restaurantData = {};
126
- const timeblocks = {
127
- '12:00': { name: '12:00' },
128
- '12:30': { name: '12:30' }
129
- };
130
- const result = filterTimeblocksByMaxGroups(restaurantData, '2025-06-15', timeblocks, [], 4);
131
- expect(result).toEqual(timeblocks);
132
- });
133
-
134
- test('should filter out timeblocks that exceed max groups for a size threshold', () => {
135
- const restaurantData = {
136
- 'max-groups-lunch': {
137
- '6': 2 // Max 2 groups of 6+ people
138
- }
139
- };
140
- const timeblocks = {
141
- '12:00': { name: '12:00' },
142
- '13:00': { name: '13:00' }
143
- };
144
- const reservations = [
145
- { date: '2025-06-15', time: '12:00', guests: 7 },
146
- { date: '2025-06-15', time: '12:30', guests: 8 }
147
- ];
148
-
149
- // Already have 2 groups of 6+, so adding another should be blocked
150
- const result = filterTimeblocksByMaxGroups(restaurantData, '2025-06-15', timeblocks, reservations, 6);
151
- expect(Object.keys(result)).toHaveLength(0);
152
- });
153
-
154
- test('should keep timeblocks when within max groups limit', () => {
155
- const restaurantData = {
156
- 'max-groups-lunch': {
157
- '6': 3 // Max 3 groups of 6+ people
158
- }
159
- };
160
- const timeblocks = {
161
- '12:00': { name: '12:00' }
162
- };
163
- const reservations = [
164
- { date: '2025-06-15', time: '12:00', guests: 7 }
165
- ];
166
-
167
- const result = filterTimeblocksByMaxGroups(restaurantData, '2025-06-15', timeblocks, reservations, 6);
168
- expect(result['12:00']).toBeDefined(); // 1 + 1 = 2 <= 3
169
- });
170
-
171
- test('should not apply filter if new booking is smaller than threshold', () => {
172
- const restaurantData = {
173
- 'max-groups-lunch': {
174
- '6': 1 // Max 1 group of 6+ people
175
- }
176
- };
177
- const timeblocks = {
178
- '12:00': { name: '12:00' }
179
- };
180
- const reservations = [
181
- { date: '2025-06-15', time: '12:00', guests: 8 }
182
- ];
183
-
184
- // Booking for 4 people - doesn't meet the 6+ threshold
185
- const result = filterTimeblocksByMaxGroups(restaurantData, '2025-06-15', timeblocks, reservations, 4);
186
- expect(result['12:00']).toBeDefined();
187
- });
188
-
189
- test('should handle MongoDB NumberInt format', () => {
190
- const restaurantData = {
191
- 'max-groups-lunch': {
192
- '6': { $numberInt: '2' }
193
- }
194
- };
195
- const timeblocks = {
196
- '12:00': { name: '12:00' }
197
- };
198
- const reservations = [
199
- { date: '2025-06-15', time: '12:00', guests: 7 }
200
- ];
201
-
202
- const result = filterTimeblocksByMaxGroups(restaurantData, '2025-06-15', timeblocks, reservations, 6);
203
- expect(result['12:00']).toBeDefined();
204
- });
205
-
206
- test('should handle multiple thresholds correctly', () => {
207
- const restaurantData = {
208
- 'max-groups-lunch': {
209
- '6': 2,
210
- '10': 1
211
- }
212
- };
213
- const timeblocks = {
214
- '12:00': { name: '12:00' }
215
- };
216
- const reservations = [
217
- { date: '2025-06-15', time: '12:00', guests: 12 } // Already have 1 group of 10+
218
- ];
219
-
220
- // Trying to add another 10+ group should be blocked
221
- const result = filterTimeblocksByMaxGroups(restaurantData, '2025-06-15', timeblocks, reservations, 10);
222
- expect(Object.keys(result)).toHaveLength(0);
223
- });
224
-
225
- test('should only count reservations for the same meal type', () => {
226
- const restaurantData = {
227
- 'max-groups-lunch': {
228
- '6': 1
229
- },
230
- 'max-groups-dinner': {
231
- '6': 1
232
- }
233
- };
234
- const timeblocks = {
235
- '12:00': { name: '12:00' } // lunch
236
- };
237
- const reservations = [
238
- { date: '2025-06-15', time: '18:00', guests: 8 } // dinner - different meal type
239
- ];
240
-
241
- const result = filterTimeblocksByMaxGroups(restaurantData, '2025-06-15', timeblocks, reservations, 7);
242
- expect(result['12:00']).toBeDefined(); // Dinner reservation doesn't count for lunch
243
- });
244
-
245
- test('should handle breakfast times correctly', () => {
246
- const restaurantData = {
247
- 'max-groups-breakfast': {
248
- '4': 3
249
- }
250
- };
251
- const timeblocks = {
252
- '09:00': { name: '09:00' }
253
- };
254
- const reservations = [
255
- { date: '2025-06-15', time: '08:00', guests: 5 },
256
- { date: '2025-06-15', time: '09:30', guests: 4 }
257
- ];
258
-
259
- const result = filterTimeblocksByMaxGroups(restaurantData, '2025-06-15', timeblocks, reservations, 6);
260
- expect(result['09:00']).toBeDefined();
261
- });
262
-
263
- test('should handle invalid guest counts gracefully', () => {
264
- const restaurantData = {
265
- 'max-groups-lunch': {
266
- '6': 2
267
- }
268
- };
269
- const timeblocks = {
270
- '12:00': { name: '12:00' }
271
- };
272
-
273
- const result = filterTimeblocksByMaxGroups(restaurantData, '2025-06-15', timeblocks, [], 'invalid');
274
- expect(result).toEqual(timeblocks); // Should return unfiltered
275
- });
276
- });
1
+ const { filterTimeblocksByMaxArrivals } = require('../filters/maxArrivalsFilter');
2
+ const { filterTimeblocksByMaxGroups } = require('../filters/maxGroupsFilter');
3
+
4
+ describe('maxArrivalsFilter', () => {
5
+ test('should keep timeblocks when no max arrivals config exists', () => {
6
+ const restaurantData = {};
7
+ const timeblocks = {
8
+ '12:00': { name: '12:00' },
9
+ '12:30': { name: '12:30' }
10
+ };
11
+ const result = filterTimeblocksByMaxArrivals(restaurantData, '2025-06-15', timeblocks, [], 4);
12
+ expect(result).toEqual(timeblocks);
13
+ });
14
+
15
+ test('should filter out timeblocks that exceed max arrivals', () => {
16
+ const restaurantData = {
17
+ 'max-arrivals-lunch': {
18
+ '12:00': 10,
19
+ '12:30': 8
20
+ }
21
+ };
22
+ const timeblocks = {
23
+ '12:00': { name: '12:00' },
24
+ '12:30': { name: '12:30' }
25
+ };
26
+ const reservations = [
27
+ { date: '2025-06-15', time: '12:00', guests: 8 }
28
+ ];
29
+
30
+ // Adding 4 guests to 12:00 (8 + 4 = 12 > 10) should filter it out
31
+ const result = filterTimeblocksByMaxArrivals(restaurantData, '2025-06-15', timeblocks, reservations, 4);
32
+ expect(result['12:00']).toBeUndefined();
33
+ expect(result['12:30']).toBeDefined();
34
+ });
35
+
36
+ test('should keep timeblocks when within max arrivals limit', () => {
37
+ const restaurantData = {
38
+ 'max-arrivals-lunch': {
39
+ '12:00': 20
40
+ }
41
+ };
42
+ const timeblocks = {
43
+ '12:00': { name: '12:00' }
44
+ };
45
+ const reservations = [
46
+ { date: '2025-06-15', time: '12:00', guests: 10 }
47
+ ];
48
+
49
+ const result = filterTimeblocksByMaxArrivals(restaurantData, '2025-06-15', timeblocks, reservations, 5);
50
+ expect(result['12:00']).toBeDefined();
51
+ });
52
+
53
+ test('should handle MongoDB NumberInt format', () => {
54
+ const restaurantData = {
55
+ 'max-arrivals-lunch': {
56
+ '12:00': { $numberInt: '20' }
57
+ }
58
+ };
59
+ const timeblocks = {
60
+ '12:00': { name: '12:00' }
61
+ };
62
+ const reservations = [
63
+ { date: '2025-06-15', time: '12:00', guests: 15 }
64
+ ];
65
+
66
+ const result = filterTimeblocksByMaxArrivals(restaurantData, '2025-06-15', timeblocks, reservations, 5);
67
+ expect(result['12:00']).toBeDefined();
68
+ });
69
+
70
+ test('should handle breakfast times correctly', () => {
71
+ const restaurantData = {
72
+ 'max-arrivals-breakfast': {
73
+ '09:00': 15
74
+ }
75
+ };
76
+ const timeblocks = {
77
+ '09:00': { name: '09:00' }
78
+ };
79
+ const reservations = [
80
+ { date: '2025-06-15', time: '09:00', guests: 12 }
81
+ ];
82
+
83
+ const result = filterTimeblocksByMaxArrivals(restaurantData, '2025-06-15', timeblocks, reservations, 2);
84
+ expect(result['09:00']).toBeDefined();
85
+ });
86
+
87
+ test('should handle dinner times correctly', () => {
88
+ const restaurantData = {
89
+ 'max-arrivals-dinner': {
90
+ '18:00': 30
91
+ }
92
+ };
93
+ const timeblocks = {
94
+ '18:00': { name: '18:00' }
95
+ };
96
+ const reservations = [
97
+ { date: '2025-06-15', time: '18:00', guests: 20 }
98
+ ];
99
+
100
+ const result = filterTimeblocksByMaxArrivals(restaurantData, '2025-06-15', timeblocks, reservations, 5);
101
+ expect(result['18:00']).toBeDefined();
102
+ });
103
+
104
+ test('should only count arrivals on the specific date', () => {
105
+ const restaurantData = {
106
+ 'max-arrivals-lunch': {
107
+ '12:00': 10
108
+ }
109
+ };
110
+ const timeblocks = {
111
+ '12:00': { name: '12:00' }
112
+ };
113
+ const reservations = [
114
+ { date: '2025-06-14', time: '12:00', guests: 8 }, // Different date
115
+ { date: '2025-06-15', time: '12:00', guests: 2 }
116
+ ];
117
+
118
+ const result = filterTimeblocksByMaxArrivals(restaurantData, '2025-06-15', timeblocks, reservations, 5);
119
+ expect(result['12:00']).toBeDefined(); // 2 + 5 = 7 <= 10
120
+ });
121
+ });
122
+
123
+ describe('maxGroupsFilter', () => {
124
+ test('should keep timeblocks when no max groups config exists', () => {
125
+ const restaurantData = {};
126
+ const timeblocks = {
127
+ '12:00': { name: '12:00' },
128
+ '12:30': { name: '12:30' }
129
+ };
130
+ const result = filterTimeblocksByMaxGroups(restaurantData, '2025-06-15', timeblocks, [], 4);
131
+ expect(result).toEqual(timeblocks);
132
+ });
133
+
134
+ test('should filter out timeblocks that exceed max groups for a size threshold', () => {
135
+ const restaurantData = {
136
+ 'max-groups-lunch': {
137
+ '6': 2 // Max 2 groups of 6+ people
138
+ }
139
+ };
140
+ const timeblocks = {
141
+ '12:00': { name: '12:00' },
142
+ '13:00': { name: '13:00' }
143
+ };
144
+ const reservations = [
145
+ { date: '2025-06-15', time: '12:00', guests: 7 },
146
+ { date: '2025-06-15', time: '12:30', guests: 8 }
147
+ ];
148
+
149
+ // Already have 2 groups of 6+, so adding another should be blocked
150
+ const result = filterTimeblocksByMaxGroups(restaurantData, '2025-06-15', timeblocks, reservations, 6);
151
+ expect(Object.keys(result)).toHaveLength(0);
152
+ });
153
+
154
+ test('should keep timeblocks when within max groups limit', () => {
155
+ const restaurantData = {
156
+ 'max-groups-lunch': {
157
+ '6': 3 // Max 3 groups of 6+ people
158
+ }
159
+ };
160
+ const timeblocks = {
161
+ '12:00': { name: '12:00' }
162
+ };
163
+ const reservations = [
164
+ { date: '2025-06-15', time: '12:00', guests: 7 }
165
+ ];
166
+
167
+ const result = filterTimeblocksByMaxGroups(restaurantData, '2025-06-15', timeblocks, reservations, 6);
168
+ expect(result['12:00']).toBeDefined(); // 1 + 1 = 2 <= 3
169
+ });
170
+
171
+ test('should not apply filter if new booking is smaller than threshold', () => {
172
+ const restaurantData = {
173
+ 'max-groups-lunch': {
174
+ '6': 1 // Max 1 group of 6+ people
175
+ }
176
+ };
177
+ const timeblocks = {
178
+ '12:00': { name: '12:00' }
179
+ };
180
+ const reservations = [
181
+ { date: '2025-06-15', time: '12:00', guests: 8 }
182
+ ];
183
+
184
+ // Booking for 4 people - doesn't meet the 6+ threshold
185
+ const result = filterTimeblocksByMaxGroups(restaurantData, '2025-06-15', timeblocks, reservations, 4);
186
+ expect(result['12:00']).toBeDefined();
187
+ });
188
+
189
+ test('should handle MongoDB NumberInt format', () => {
190
+ const restaurantData = {
191
+ 'max-groups-lunch': {
192
+ '6': { $numberInt: '2' }
193
+ }
194
+ };
195
+ const timeblocks = {
196
+ '12:00': { name: '12:00' }
197
+ };
198
+ const reservations = [
199
+ { date: '2025-06-15', time: '12:00', guests: 7 }
200
+ ];
201
+
202
+ const result = filterTimeblocksByMaxGroups(restaurantData, '2025-06-15', timeblocks, reservations, 6);
203
+ expect(result['12:00']).toBeDefined();
204
+ });
205
+
206
+ test('should handle multiple thresholds correctly', () => {
207
+ const restaurantData = {
208
+ 'max-groups-lunch': {
209
+ '6': 2,
210
+ '10': 1
211
+ }
212
+ };
213
+ const timeblocks = {
214
+ '12:00': { name: '12:00' }
215
+ };
216
+ const reservations = [
217
+ { date: '2025-06-15', time: '12:00', guests: 12 } // Already have 1 group of 10+
218
+ ];
219
+
220
+ // Trying to add another 10+ group should be blocked
221
+ const result = filterTimeblocksByMaxGroups(restaurantData, '2025-06-15', timeblocks, reservations, 10);
222
+ expect(Object.keys(result)).toHaveLength(0);
223
+ });
224
+
225
+ test('should only count reservations for the same meal type', () => {
226
+ const restaurantData = {
227
+ 'max-groups-lunch': {
228
+ '6': 1
229
+ },
230
+ 'max-groups-dinner': {
231
+ '6': 1
232
+ }
233
+ };
234
+ const timeblocks = {
235
+ '12:00': { name: '12:00' } // lunch
236
+ };
237
+ const reservations = [
238
+ { date: '2025-06-15', time: '18:00', guests: 8 } // dinner - different meal type
239
+ ];
240
+
241
+ const result = filterTimeblocksByMaxGroups(restaurantData, '2025-06-15', timeblocks, reservations, 7);
242
+ expect(result['12:00']).toBeDefined(); // Dinner reservation doesn't count for lunch
243
+ });
244
+
245
+ test('should handle breakfast times correctly', () => {
246
+ const restaurantData = {
247
+ 'max-groups-breakfast': {
248
+ '4': 3
249
+ }
250
+ };
251
+ const timeblocks = {
252
+ '09:00': { name: '09:00' }
253
+ };
254
+ const reservations = [
255
+ { date: '2025-06-15', time: '08:00', guests: 5 },
256
+ { date: '2025-06-15', time: '09:30', guests: 4 }
257
+ ];
258
+
259
+ const result = filterTimeblocksByMaxGroups(restaurantData, '2025-06-15', timeblocks, reservations, 6);
260
+ expect(result['09:00']).toBeDefined();
261
+ });
262
+
263
+ test('should handle invalid guest counts gracefully', () => {
264
+ const restaurantData = {
265
+ 'max-groups-lunch': {
266
+ '6': 2
267
+ }
268
+ };
269
+ const timeblocks = {
270
+ '12:00': { name: '12:00' }
271
+ };
272
+
273
+ const result = filterTimeblocksByMaxGroups(restaurantData, '2025-06-15', timeblocks, [], 'invalid');
274
+ expect(result).toEqual(timeblocks); // Should return unfiltered
275
+ });
276
+ });