feat(backend): Add ProjectManagement integration test infrastructure + fix API controller

Created comprehensive integration test infrastructure for ProjectManagement module:
- PMWebApplicationFactory with in-memory database support
- TestAuthHelper for JWT token generation
- Test project with all necessary dependencies

Fixed API Controller:
- Removed manual TenantId injection in ProjectsController
- TenantId now automatically extracted via ITenantContext in CommandHandler
- Maintained OwnerId extraction from JWT claims

Test Infrastructure:
- In-memory database for fast, isolated tests
- Support for multi-tenant scenarios
- JWT authentication helpers
- Cross-module database consistency

Next Steps:
- Write multi-tenant isolation tests (Phase 3.2)
- Write CRUD integration tests (Phase 3.3)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Yaojia Wang
2025-11-04 19:56:49 +01:00
parent 99bd92a3ca
commit 4359c9f08f
4 changed files with 210 additions and 13 deletions

View File

@@ -57,14 +57,13 @@ public class ProjectsController(IMediator mediator) : ControllerBase
[FromBody] CreateProjectCommand command,
CancellationToken cancellationToken = default)
{
// Extract TenantId and UserId from JWT claims
var tenantId = GetTenantIdFromClaims();
// Extract UserId from JWT claims
// Note: TenantId is now automatically extracted in the CommandHandler via ITenantContext
var userId = GetUserIdFromClaims();
// Override command with authenticated user's context
// Override command with authenticated user's ID
var commandWithContext = command with
{
TenantId = tenantId,
OwnerId = userId
};
@@ -104,15 +103,7 @@ public class ProjectsController(IMediator mediator) : ControllerBase
return NoContent();
}
// Helper methods to extract claims
private Guid GetTenantIdFromClaims()
{
var tenantIdClaim = User.FindFirst("tenant_id")?.Value
?? throw new UnauthorizedAccessException("Tenant ID not found in token");
return Guid.Parse(tenantIdClaim);
}
// Helper method to extract user ID from claims
private Guid GetUserIdFromClaims()
{
var userIdClaim = User.FindFirst(ClaimTypes.NameIdentifier)?.Value