@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,175 +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
- );
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
- });
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
+ });
@@ -1,168 +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
- });
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
+ });