@happychef/algorithm 1.2.10 → 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 (46) hide show
  1. package/.github/workflows/ci-cd.yml +133 -2
  2. package/BRANCH_PROTECTION_SETUP.md +167 -0
  3. package/CHANGELOG.md +8 -8
  4. package/RESERVERINGEN_GIDS.md +986 -986
  5. package/assignTables.js +424 -398
  6. package/changes/2025/December/PR2___change.md +14 -14
  7. package/changes/2025/December/PR3_add__change.md +20 -20
  8. package/changes/2025/December/PR4___.md +16 -0
  9. package/changes/2025/December/PR5___.md +16 -0
  10. package/changes/2025/December/PR6__del_.md +18 -0
  11. package/changes/2025/December/PR7_add__change.md +22 -0
  12. package/changes/2026/January/PR8_add__change.md +39 -0
  13. package/changes/2026/January/PR9_add__change.md +20 -0
  14. package/filters/maxArrivalsFilter.js +114 -114
  15. package/filters/maxGroupsFilter.js +221 -221
  16. package/filters/timeFilter.js +89 -89
  17. package/getAvailableTimeblocks.js +158 -158
  18. package/grouping.js +162 -162
  19. package/index.js +42 -42
  20. package/isDateAvailable.js +80 -80
  21. package/isDateAvailableWithTableCheck.js +171 -171
  22. package/isTimeAvailable.js +25 -25
  23. package/package.json +27 -27
  24. package/processing/dailyGuestCounts.js +73 -73
  25. package/processing/mealTypeCount.js +133 -133
  26. package/processing/timeblocksAvailable.js +167 -167
  27. package/reservation_data/counter.js +64 -64
  28. package/restaurant_data/exceptions.js +149 -149
  29. package/restaurant_data/openinghours.js +123 -123
  30. package/simulateTableAssignment.js +709 -699
  31. package/tableHelpers.js +178 -178
  32. package/tables/time/parseTime.js +19 -19
  33. package/tables/time/shifts.js +7 -7
  34. package/tables/utils/calculateDistance.js +13 -13
  35. package/tables/utils/isTableFreeForAllSlots.js +14 -14
  36. package/tables/utils/isTemporaryTableValid.js +39 -39
  37. package/test/test_counter.js +194 -194
  38. package/test/test_dailyCount.js +81 -81
  39. package/test/test_datesAvailable.js +106 -106
  40. package/test/test_exceptions.js +172 -172
  41. package/test/test_isDateAvailable.js +330 -330
  42. package/test/test_mealTypeCount.js +54 -54
  43. package/test/test_timesAvailable.js +88 -88
  44. package/test-meal-stop-fix.js +147 -147
  45. package/test-meal-stop-simple.js +93 -93
  46. package/test.js +336 -336
@@ -7,6 +7,7 @@ on:
7
7
  pull_request:
8
8
  branches:
9
9
  - main
10
+ types: [opened, synchronize, reopened]
10
11
 
11
12
  jobs:
12
13
  test:
@@ -31,10 +32,122 @@ jobs:
31
32
  run: npm ci
32
33
 
33
34
  - name: Run tests
34
- run: npm test
35
+ id: test-run
36
+ run: npm test -- --verbose 2>&1 | tee test-output.txt
37
+ continue-on-error: true
35
38
 
36
39
  - name: Run tests with coverage
40
+ if: always()
37
41
  run: npm run test:coverage
42
+ continue-on-error: true
43
+
44
+ - name: Generate test summary
45
+ if: always()
46
+ run: |
47
+ echo "## Test Results for Node.js ${{ matrix.node-version }}" >> $GITHUB_STEP_SUMMARY
48
+ echo "" >> $GITHUB_STEP_SUMMARY
49
+
50
+ # Extract test results
51
+ TEST_OUTPUT=$(cat test-output.txt)
52
+
53
+ if echo "$TEST_OUTPUT" | grep -q "Tests:.*failed"; then
54
+ echo "❌ **Tests Failed**" >> $GITHUB_STEP_SUMMARY
55
+ echo "" >> $GITHUB_STEP_SUMMARY
56
+
57
+ # Extract summary line
58
+ SUMMARY=$(echo "$TEST_OUTPUT" | grep "Test Suites:" | tail -1)
59
+ echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
60
+ echo "$SUMMARY" >> $GITHUB_STEP_SUMMARY
61
+ echo "$TEST_OUTPUT" | grep "Tests:" | tail -1 >> $GITHUB_STEP_SUMMARY
62
+ echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
63
+ echo "" >> $GITHUB_STEP_SUMMARY
64
+
65
+ # Show failed tests
66
+ echo "### Failed Tests:" >> $GITHUB_STEP_SUMMARY
67
+ echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
68
+ echo "$TEST_OUTPUT" | grep -A 10 "FAIL" | head -30 >> $GITHUB_STEP_SUMMARY
69
+ echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
70
+ else
71
+ echo "✅ **All Tests Passed!**" >> $GITHUB_STEP_SUMMARY
72
+ echo "" >> $GITHUB_STEP_SUMMARY
73
+
74
+ # Extract summary line
75
+ SUMMARY=$(echo "$TEST_OUTPUT" | grep "Test Suites:" | tail -1)
76
+ echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
77
+ echo "$SUMMARY" >> $GITHUB_STEP_SUMMARY
78
+ echo "$TEST_OUTPUT" | grep "Tests:" | tail -1 >> $GITHUB_STEP_SUMMARY
79
+ echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
80
+ fi
81
+
82
+ - name: Comment PR with test results
83
+ if: always() && github.event_name == 'pull_request' && matrix.node-version == '20.x'
84
+ uses: actions/github-script@v7
85
+ with:
86
+ script: |
87
+ const fs = require('fs');
88
+ const testOutput = fs.readFileSync('test-output.txt', 'utf8');
89
+
90
+ // Check if tests failed
91
+ const hasFailed = testOutput.includes('FAIL');
92
+ const summaryLine = testOutput.match(/Test Suites:.*$/m)?.[0] || '';
93
+ const testsLine = testOutput.match(/Tests:.*$/m)?.[0] || '';
94
+
95
+ let comment = '';
96
+
97
+ if (hasFailed) {
98
+ comment = `## ❌ Tests Failed on Node.js ${{ matrix.node-version }}
99
+
100
+ **Summary:**
101
+ \`\`\`
102
+ ${summaryLine}
103
+ ${testsLine}
104
+ \`\`\`
105
+
106
+ ### 🔴 Failed Tests Details:
107
+
108
+ `;
109
+
110
+ // Extract failed test details
111
+ const failedTests = testOutput.match(/FAIL.*\n(.*\n){0,15}/g) || [];
112
+ failedTests.forEach(fail => {
113
+ const lines = fail.split('\n').slice(0, 10);
114
+ comment += '\`\`\`\n' + lines.join('\n') + '\n\`\`\`\n\n';
115
+ });
116
+
117
+ comment += `
118
+ ### 💡 What to do:
119
+ 1. Review the failed test(s) above
120
+ 2. Fix the issues in your code
121
+ 3. Push the changes to this PR
122
+ 4. Tests will run automatically again
123
+
124
+ **This PR cannot be merged until all tests pass.**
125
+ `;
126
+ } else {
127
+ comment = `## ✅ All Tests Passed on Node.js ${{ matrix.node-version }}
128
+
129
+ **Summary:**
130
+ \`\`\`
131
+ ${summaryLine}
132
+ ${testsLine}
133
+ \`\`\`
134
+
135
+ ### 🎉 Great work!
136
+ All tests are passing. This PR is ready to be reviewed and merged.
137
+
138
+ **Next steps:**
139
+ - Wait for code review (if required)
140
+ - Merge when ready
141
+ `;
142
+ }
143
+
144
+ // Post comment
145
+ github.rest.issues.createComment({
146
+ issue_number: context.issue.number,
147
+ owner: context.repo.owner,
148
+ repo: context.repo.repo,
149
+ body: comment
150
+ });
38
151
 
39
152
  - name: Upload coverage reports
40
153
  uses: codecov/codecov-action@v4
@@ -87,10 +200,25 @@ jobs:
87
200
 
88
201
  - name: Publish to NPM
89
202
  if: steps.version-check.outputs.version_changed == 'true'
90
- run: npm publish --access public
203
+ run: |
204
+ npm publish --access public
205
+ echo "## 📦 NPM Package Published" >> $GITHUB_STEP_SUMMARY
206
+ echo "" >> $GITHUB_STEP_SUMMARY
207
+ echo "✅ Successfully published @happychef/algorithm@$(node -p "require('./package.json').version")" >> $GITHUB_STEP_SUMMARY
208
+ echo "" >> $GITHUB_STEP_SUMMARY
209
+ echo "🔗 [View on NPM](https://www.npmjs.com/package/@happychef/algorithm)" >> $GITHUB_STEP_SUMMARY
91
210
  env:
92
211
  NODE_AUTH_TOKEN: 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
93
212
 
213
+ - name: Skip publishing (version unchanged)
214
+ if: steps.version-check.outputs.version_changed == 'false'
215
+ run: |
216
+ echo "## ⏭️ Publishing Skipped" >> $GITHUB_STEP_SUMMARY
217
+ echo "" >> $GITHUB_STEP_SUMMARY
218
+ echo "Version $(node -p "require('./package.json').version") is already published" >> $GITHUB_STEP_SUMMARY
219
+ echo "" >> $GITHUB_STEP_SUMMARY
220
+ echo "💡 Bump the version in package.json to trigger publishing" >> $GITHUB_STEP_SUMMARY
221
+
94
222
  - name: Create Git Tag
95
223
  if: steps.version-check.outputs.version_changed == 'true'
96
224
  run: |
@@ -99,5 +227,8 @@ jobs:
99
227
  git config user.email "github-actions[bot]@users.noreply.github.com"
100
228
  git tag -a "v$PACKAGE_VERSION" -m "Release v$PACKAGE_VERSION"
101
229
  git push origin "v$PACKAGE_VERSION"
230
+ echo "## 🏷️ Git Tag Created" >> $GITHUB_STEP_SUMMARY
231
+ echo "" >> $GITHUB_STEP_SUMMARY
232
+ echo "Created and pushed tag: v$PACKAGE_VERSION" >> $GITHUB_STEP_SUMMARY
102
233
  env:
103
234
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,167 @@
1
+ # Branch Protection Setup Guide
2
+
3
+ This guide explains how to configure GitHub branch protection rules to require all tests to pass before merging pull requests.
4
+
5
+ ## Why Branch Protection?
6
+
7
+ Branch protection ensures:
8
+ - ✅ All tests must pass before merging PRs
9
+ - ✅ No direct pushes to main without review (optional)
10
+ - ✅ Code quality is maintained
11
+ - ✅ Broken code never reaches production
12
+
13
+ ## Setup Instructions
14
+
15
+ ### Step 1: Go to Branch Protection Settings
16
+
17
+ 1. Navigate to your GitHub repository: `https://github.com/thibaultvandesompele2/15-happy-algorithm`
18
+ 2. Click on **Settings** (tab at the top)
19
+ 3. In the left sidebar, click **Branches** (under "Code and automation")
20
+ 4. Click **Add branch protection rule** (or **Add rule**)
21
+
22
+ ### Step 2: Configure the Rule
23
+
24
+ #### Basic Settings:
25
+ 1. **Branch name pattern**: Enter `main`
26
+
27
+ #### Required Settings:
28
+
29
+ ✅ **Check these boxes:**
30
+
31
+ 1. ☑️ **Require a pull request before merging**
32
+ - This prevents direct pushes to main
33
+ - Optional: Set "Required number of approvals" to 1 or more
34
+
35
+ 2. ☑️ **Require status checks to pass before merging**
36
+ - This is the CRITICAL setting for test enforcement
37
+ - Check: **Require branches to be up to date before merging**
38
+
39
+ 3. In the **Status checks** search box, you'll see:
40
+ - `Run Tests` (your test job)
41
+
42
+ ☑️ **Select both Node.js test jobs:**
43
+ - `Run Tests (18.x)`
44
+ - `Run Tests (20.x)`
45
+
46
+ *Note: These will appear after the first workflow run completes*
47
+
48
+ 4. ☑️ **Do not allow bypassing the above settings** (recommended)
49
+ - Even admins must follow these rules
50
+
51
+ #### Optional but Recommended:
52
+
53
+ 5. ☑️ **Require conversation resolution before merging**
54
+ - All PR comments must be resolved
55
+
56
+ 6. ☑️ **Require linear history**
57
+ - Prevents messy merge commits
58
+
59
+ ### Step 3: Save
60
+
61
+ 1. Scroll to the bottom
62
+ 2. Click **Create** or **Save changes**
63
+
64
+ ## What Happens After Setup
65
+
66
+ ### On Pull Requests:
67
+ - GitHub automatically runs the CI/CD tests
68
+ - You'll see status checks at the bottom of the PR
69
+ - **Merge button will be DISABLED** until all tests pass
70
+ - If tests fail, you must fix them before merging
71
+
72
+ ### Visual Indicators:
73
+
74
+ **Tests Running:**
75
+ ```
76
+ ⏳ Run Tests (18.x) — In progress
77
+ ⏳ Run Tests (20.x) — In progress
78
+ ```
79
+
80
+ **Tests Passed:**
81
+ ```
82
+ ✅ Run Tests (18.x) — Passed
83
+ ✅ Run Tests (20.x) — Passed
84
+ 🟢 Merge pull request button is ENABLED
85
+ ```
86
+
87
+ **Tests Failed:**
88
+ ```
89
+ ❌ Run Tests (18.x) — Failed
90
+ ❌ Run Tests (20.x) — Failed
91
+ 🔴 Merge pull request button is DISABLED
92
+ ```
93
+
94
+ ## Testing the Protection
95
+
96
+ ### Create a Test PR:
97
+
98
+ 1. Create a new branch:
99
+ ```bash
100
+ git checkout -b test-branch-protection
101
+ ```
102
+
103
+ 2. Make a small change:
104
+ ```bash
105
+ echo "# Test" >> test-file.txt
106
+ git add test-file.txt
107
+ git commit -m "Test branch protection"
108
+ git push origin test-branch-protection
109
+ ```
110
+
111
+ 3. Go to GitHub and create a pull request
112
+
113
+ 4. Observe:
114
+ - Tests run automatically
115
+ - Merge button is disabled until tests complete
116
+ - After tests pass, merge button becomes available
117
+
118
+ ## Workflow Behavior
119
+
120
+ ### For Pull Requests:
121
+ - ✅ Runs all 70 tests on Node.js 18.x and 20.x
122
+ - ✅ Must pass before merge is allowed
123
+ - ✅ Shows test summary in PR
124
+ - ❌ Does NOT publish to npm (only tests)
125
+
126
+ ### For Pushes to Main:
127
+ - ✅ Runs all tests
128
+ - ✅ If version changed AND tests pass → publishes to npm
129
+ - ✅ Creates git tag
130
+ - ✅ Shows summary of all actions
131
+
132
+ ## Troubleshooting
133
+
134
+ ### "Status checks not found"
135
+ - The status checks only appear after the first workflow run completes
136
+ - Push this branch protection setup, wait for workflow to run, then configure protection
137
+
138
+ ### "Can't find Run Tests in status checks"
139
+ - Make sure the workflow has run at least once
140
+ - Check the Actions tab to see workflow runs
141
+ - The job name must match exactly: `Run Tests`
142
+
143
+ ### "Tests are running but merge button isn't disabled"
144
+ - You need to enable "Require status checks to pass before merging"
145
+ - Make sure you selected the specific test jobs (18.x and 20.x)
146
+
147
+ ## Quick Setup Checklist
148
+
149
+ - [ ] Go to Settings → Branches
150
+ - [ ] Add branch protection rule for `main`
151
+ - [ ] Enable "Require status checks to pass before merging"
152
+ - [ ] Select `Run Tests (18.x)` and `Run Tests (20.x)`
153
+ - [ ] Enable "Do not allow bypassing"
154
+ - [ ] Save the rule
155
+ - [ ] Test with a PR
156
+
157
+ ## Additional Security (Optional)
158
+
159
+ For additional security, you can also enable:
160
+
161
+ - **Require deployments to succeed** - Wait for tests before deploying
162
+ - **Lock branch** - Temporarily prevent all changes
163
+ - **Restrict who can push** - Only specific users/teams can push
164
+
165
+ ---
166
+
167
+ **Result:** After setup, no code can be merged to `main` without passing all 70 tests! 🎉
package/CHANGELOG.md CHANGED
@@ -1,8 +1,8 @@
1
- PR 2:
2
- ADDED:
3
- - Modified the `getAvailableTimeblocks.js` file to change the default value of `uurOpVoorhand` from 4 hours to 0 hours, enabling immediate bookings when the field is not explicitly set in general settings.
4
-
5
- REMOVED:
6
- - No functions, features, or code were removed; only a configuration default value was updated.
7
-
8
- ---
1
+ PR 2:
2
+ ADDED:
3
+ - Modified the `getAvailableTimeblocks.js` file to change the default value of `uurOpVoorhand` from 4 hours to 0 hours, enabling immediate bookings when the field is not explicitly set in general settings.
4
+
5
+ REMOVED:
6
+ - No functions, features, or code were removed; only a configuration default value was updated.
7
+
8
+ ---