Stabilize test harness across full stack: Backend integration tests: - Fix Auth/Club/Migration/RLS/Member/Tenant/RLS Isolation/Shift/Task test suites - Add AssemblyInfo.cs for test configuration - Enhance CustomWebApplicationFactory + TestAuthHandler for stable test environment - Expand RlsIsolationTests with comprehensive multi-tenant RLS verification Frontend test harness: - Align vitest.config.ts with backend API changes - Add bunfig.toml for bun test environment stability - Enhance api.test.ts with proper test setup integration - Expand test/setup.ts with fixture initialization All tests now passing: backend 12/12 unit + 63/63 integration, frontend 45/45
57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
using System.Net;
|
|
using System.Text;
|
|
using WorkClub.Tests.Integration.Infrastructure;
|
|
using Xunit;
|
|
|
|
namespace WorkClub.Tests.Integration.Middleware;
|
|
|
|
public class TenantValidationTests : IntegrationTestBase
|
|
{
|
|
public TenantValidationTests(CustomWebApplicationFactory<Program> factory) : base(factory)
|
|
{
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Request_WithValidTenantId_Returns200()
|
|
{
|
|
AuthenticateAs("test@test.com", new Dictionary<string, string> { ["club-1"] = "admin" });
|
|
SetTenant("club-1");
|
|
|
|
var response = await Client.GetAsync("/api/test");
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Request_WithNonMemberTenantId_Returns403()
|
|
{
|
|
AuthenticateAs("test@test.com", new Dictionary<string, string> { ["club-1"] = "admin" });
|
|
SetTenant("club-2");
|
|
|
|
var response = await Client.GetAsync("/api/test");
|
|
|
|
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Request_WithoutTenantIdHeader_Returns400()
|
|
{
|
|
AuthenticateAs("test@test.com", new Dictionary<string, string> { ["club-1"] = "admin" });
|
|
|
|
var response = await Client.GetAsync("/api/test");
|
|
|
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Request_WithoutAuthentication_Returns401()
|
|
{
|
|
AuthenticateAsUnauthenticated();
|
|
SetTenant("club-1");
|
|
|
|
var response = await Client.GetAsync("/api/test");
|
|
|
|
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
|
}
|
|
}
|