feat(backend): add PostgreSQL schema, RLS policies, and multi-tenant middleware
- Add EF Core migrations for initial schema (clubs, members, work_items, shifts, shift_signups)
- Implement RLS policies with SET LOCAL for tenant isolation
- Add Finbuckle multi-tenant middleware with ClaimStrategy + HeaderStrategy fallback
- Create TenantValidationMiddleware to enforce JWT claims match X-Tenant-Id header
- Add tenant-aware DB interceptors (SaveChangesTenantInterceptor, TenantDbConnectionInterceptor)
- Configure AppDbContext with tenant scoping and RLS support
- Add test infrastructure: CustomWebApplicationFactory, TestAuthHandler, DatabaseFixture
- Write TDD integration tests for multi-tenant isolation and RLS enforcement
- Add health check null safety for connection string
Tasks: 7 (PostgreSQL schema + migrations + RLS), 8 (Finbuckle multi-tenancy + validation), 12 (test infrastructure)
2026-03-03 14:32:21 +01:00
|
|
|
using System.Text.Json;
|
|
|
|
|
|
|
|
|
|
namespace WorkClub.Tests.Integration.Infrastructure;
|
|
|
|
|
|
|
|
|
|
public abstract class IntegrationTestBase : IClassFixture<CustomWebApplicationFactory<Program>>, IAsyncLifetime
|
|
|
|
|
{
|
|
|
|
|
protected readonly HttpClient Client;
|
|
|
|
|
protected readonly CustomWebApplicationFactory<Program> Factory;
|
|
|
|
|
|
|
|
|
|
protected IntegrationTestBase(CustomWebApplicationFactory<Program> factory)
|
|
|
|
|
{
|
|
|
|
|
Factory = factory;
|
|
|
|
|
Client = factory.CreateClient();
|
|
|
|
|
}
|
|
|
|
|
|
feat(shifts): add Shift CRUD API with sign-up/cancel and capacity management
- ShiftService with 7 methods: list, detail, create, update, delete, signup, cancel
- 5 DTOs: ShiftListDto, ShiftDetailDto, CreateShiftRequest, UpdateShiftRequest, ShiftSignupDto
- Minimal API endpoints: GET /api/shifts, GET /api/shifts/{id}, POST, PUT, DELETE, POST /signup, DELETE /signup
- Capacity validation: sign-up rejected when full → 409 Conflict
- Past shift blocking: cannot sign up for past shifts → 422 Unprocessable
- Duplicate signup prevention: check existing before create → 409 Conflict
- Concurrency: 2-attempt retry loop for last-slot race conditions
- Authorization: POST/PUT (Manager+), DELETE (Admin), signup/cancel (Member+)
- Test infrastructure: Added X-Test-UserId header support for member ID injection
- 13 TDD integration tests: CRUD, sign-up, capacity, past shift, concurrency
- Build: 0 errors (6 BouncyCastle warnings expected)
Task 15 complete. Wave 3: 3/5 tasks done.
2026-03-03 19:30:23 +01:00
|
|
|
protected void AuthenticateAs(string email, Dictionary<string, string> clubs, string? userId = null)
|
feat(backend): add PostgreSQL schema, RLS policies, and multi-tenant middleware
- Add EF Core migrations for initial schema (clubs, members, work_items, shifts, shift_signups)
- Implement RLS policies with SET LOCAL for tenant isolation
- Add Finbuckle multi-tenant middleware with ClaimStrategy + HeaderStrategy fallback
- Create TenantValidationMiddleware to enforce JWT claims match X-Tenant-Id header
- Add tenant-aware DB interceptors (SaveChangesTenantInterceptor, TenantDbConnectionInterceptor)
- Configure AppDbContext with tenant scoping and RLS support
- Add test infrastructure: CustomWebApplicationFactory, TestAuthHandler, DatabaseFixture
- Write TDD integration tests for multi-tenant isolation and RLS enforcement
- Add health check null safety for connection string
Tasks: 7 (PostgreSQL schema + migrations + RLS), 8 (Finbuckle multi-tenancy + validation), 12 (test infrastructure)
2026-03-03 14:32:21 +01:00
|
|
|
{
|
|
|
|
|
var clubsJson = JsonSerializer.Serialize(clubs);
|
|
|
|
|
Client.DefaultRequestHeaders.Remove("X-Test-Clubs");
|
|
|
|
|
Client.DefaultRequestHeaders.Add("X-Test-Clubs", clubsJson);
|
|
|
|
|
|
|
|
|
|
Client.DefaultRequestHeaders.Remove("X-Test-Email");
|
|
|
|
|
Client.DefaultRequestHeaders.Add("X-Test-Email", email);
|
feat(shifts): add Shift CRUD API with sign-up/cancel and capacity management
- ShiftService with 7 methods: list, detail, create, update, delete, signup, cancel
- 5 DTOs: ShiftListDto, ShiftDetailDto, CreateShiftRequest, UpdateShiftRequest, ShiftSignupDto
- Minimal API endpoints: GET /api/shifts, GET /api/shifts/{id}, POST, PUT, DELETE, POST /signup, DELETE /signup
- Capacity validation: sign-up rejected when full → 409 Conflict
- Past shift blocking: cannot sign up for past shifts → 422 Unprocessable
- Duplicate signup prevention: check existing before create → 409 Conflict
- Concurrency: 2-attempt retry loop for last-slot race conditions
- Authorization: POST/PUT (Manager+), DELETE (Admin), signup/cancel (Member+)
- Test infrastructure: Added X-Test-UserId header support for member ID injection
- 13 TDD integration tests: CRUD, sign-up, capacity, past shift, concurrency
- Build: 0 errors (6 BouncyCastle warnings expected)
Task 15 complete. Wave 3: 3/5 tasks done.
2026-03-03 19:30:23 +01:00
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(userId))
|
|
|
|
|
{
|
|
|
|
|
Client.DefaultRequestHeaders.Remove("X-Test-UserId");
|
|
|
|
|
Client.DefaultRequestHeaders.Add("X-Test-UserId", userId);
|
|
|
|
|
}
|
feat(backend): add PostgreSQL schema, RLS policies, and multi-tenant middleware
- Add EF Core migrations for initial schema (clubs, members, work_items, shifts, shift_signups)
- Implement RLS policies with SET LOCAL for tenant isolation
- Add Finbuckle multi-tenant middleware with ClaimStrategy + HeaderStrategy fallback
- Create TenantValidationMiddleware to enforce JWT claims match X-Tenant-Id header
- Add tenant-aware DB interceptors (SaveChangesTenantInterceptor, TenantDbConnectionInterceptor)
- Configure AppDbContext with tenant scoping and RLS support
- Add test infrastructure: CustomWebApplicationFactory, TestAuthHandler, DatabaseFixture
- Write TDD integration tests for multi-tenant isolation and RLS enforcement
- Add health check null safety for connection string
Tasks: 7 (PostgreSQL schema + migrations + RLS), 8 (Finbuckle multi-tenancy + validation), 12 (test infrastructure)
2026-03-03 14:32:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void SetTenant(string tenantId)
|
|
|
|
|
{
|
|
|
|
|
Client.DefaultRequestHeaders.Remove("X-Tenant-Id");
|
|
|
|
|
Client.DefaultRequestHeaders.Add("X-Tenant-Id", tenantId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual Task InitializeAsync() => Task.CompletedTask;
|
|
|
|
|
|
|
|
|
|
public virtual Task DisposeAsync() => Task.CompletedTask;
|
|
|
|
|
}
|