Add comprehensive test suite infrastructure
- Create backend xUnit test project with Moq and FluentAssertions - Add test utilities: TestDataFactory, MockHttpContext, TestUserClaims - Create AuthControllerTests with comprehensive auth scenarios - Install Jest and React Testing Library for frontend - Configure jest.config.ts and jest.setup.ts with Next.js support - Add test scripts to package.json
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace backend.Tests.Utilities;
|
||||
|
||||
public static class MockHttpContext
|
||||
{
|
||||
public static HttpContext Create(
|
||||
string userId = "test-user-id",
|
||||
string email = "test@example.com",
|
||||
string role = "Participant",
|
||||
bool isAuthenticated = true)
|
||||
{
|
||||
var claims = new List<Claim>();
|
||||
|
||||
if (isAuthenticated)
|
||||
{
|
||||
claims.Add(new Claim(ClaimTypes.NameIdentifier, userId));
|
||||
claims.Add(new Claim(ClaimTypes.Email, email));
|
||||
claims.Add(new Claim(ClaimTypes.Role, role));
|
||||
}
|
||||
|
||||
var identity = new ClaimsIdentity(claims, isAuthenticated ? "TestAuthType" : null);
|
||||
var principal = new ClaimsPrincipal(identity);
|
||||
|
||||
var httpContext = new DefaultHttpContext
|
||||
{
|
||||
User = principal
|
||||
};
|
||||
|
||||
return httpContext;
|
||||
}
|
||||
|
||||
public static HttpContext CreateAnonymous()
|
||||
{
|
||||
return Create(isAuthenticated: false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user