Repository navigation
Add API integration tests, return 400 for client errors and fix vulnerable dependencies - #3
Merged
Merged
Conversation
- EF Core 9.0.7 -> 9.0.21: SQLitePCLRaw.lib.e_sqlite3 2.1.10 -> 2.1.13 (GHSA-2m69-gcr7-jv3q, high) - Swashbuckle.AspNetCore 10.1.7 -> 10.2.3: Microsoft.OpenApi 2.4.1 -> 2.7.5 (GHSA-v5pm-xwqc-g5wc, high) - Microsoft.AspNetCore.OpenApi 9.0.15 -> 9.0.21 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Read the SQLite connection string from ConnectionStrings:ShiftPlanner
(default unchanged) so tests can use an isolated database
- Expose Program to WebApplicationFactory
- POST /api/load-analysis returned 500 when an employee lacked the
skill for an assigned shift; return 400 with an error message
- Use { error } bodies for scheduling validation errors, matching the
employee and shift endpoints
- Add 20 WebApplicationFactory tests on in-memory SQLite covering
demo data, generation, simulation, analysis and validation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
POST /api/load-analysiswithassignEmployee: truefor a shift whose skill the employee lacks threwInvalidOperationExceptioninShift.AssignEmployee. The global middleware turned that into500 "An unexpected error occurred."I reproduced this against the running API.400 { "error": "..." }, while/api/schedule/generateand/api/schedule/simulatereturned a bare JSON string.Data Source=shiftplanner.db) inAddInfrastructure, so the API could not be pointed at a test database (or any other database) without a code change.SQLitePCLRaw.lib.e_sqlite3 2.1.10(GHSA-2m69-gcr7-jv3q) via EF Core 9.0.7, andMicrosoft.OpenApi 2.4.1(GHSA-v5pm-xwqc-g5wc) via Swashbuckle 10.1.7.Solution
dotnet list package --vulnerable --include-transitiveis now clean for all projects.ConnectionStrings:ShiftPlanner(added toappsettings.json), with the old value as fallback. Default behaviour is unchanged.public partial class Program, soWebApplicationFactory<Program>can host the API.shift.CanAssign(employee)and returns400 { error }with the skill and date. The domain rule is unchanged.{ error }. The frontend only checksresponse.okfor these calls, so nothing in the UI changes.tests/ShiftPlanner.Api.IntegrationTestswith 20 tests. Each test gets its own API instance on an isolated in-memory SQLite database, and EF Core migrations run exactly as in production. No files are written. The tests cover:/api/shiftsLocation) and validationThe scheduling logic is unchanged.
Test results
Manual smoke test of the Release build:
/swagger/v1/swagger.json→ 200 with the new Swashbuckle,POST /api/demo/reset→ 10 employees / 14 shifts, load analysis with missing skill → 400 with message (previously 500).Limitations / findings not changed here
RequiredStaffis not persisted.ShiftEntityhas no column for it, andShiftRepositoryalways reads it back as1.POST /api/shiftswithrequiredStaff: 3responds with 3 but stores 1. The scheduling model assigns one employee per shift, so fixing this properly is a domain/migration decision. I left it unchanged and flagged it for review.SaveChangesper assignment). That is fine for the demo, but worth knowing.🤖 Generated with Claude Code