571fe5bc7c
- 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
38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using System.Security.Claims;
|
|
|
|
namespace backend.Tests.Utilities;
|
|
|
|
public static class TestUserClaims
|
|
{
|
|
public static ClaimsPrincipal CreateOrganizer(Guid? userId = null, string email = "organizer@example.com")
|
|
{
|
|
var claims = new List<Claim>
|
|
{
|
|
new Claim(ClaimTypes.NameIdentifier, (userId ?? Guid.NewGuid()).ToString()),
|
|
new Claim(ClaimTypes.Email, email),
|
|
new Claim(ClaimTypes.Role, "Organizer")
|
|
};
|
|
|
|
var identity = new ClaimsIdentity(claims, "TestAuthType");
|
|
return new ClaimsPrincipal(identity);
|
|
}
|
|
|
|
public static ClaimsPrincipal CreateParticipant(Guid? userId = null, string email = "participant@example.com")
|
|
{
|
|
var claims = new List<Claim>
|
|
{
|
|
new Claim(ClaimTypes.NameIdentifier, (userId ?? Guid.NewGuid()).ToString()),
|
|
new Claim(ClaimTypes.Email, email),
|
|
new Claim(ClaimTypes.Role, "Participant")
|
|
};
|
|
|
|
var identity = new ClaimsIdentity(claims, "TestAuthType");
|
|
return new ClaimsPrincipal(identity);
|
|
}
|
|
|
|
public static ClaimsPrincipal CreateUnauthenticated()
|
|
{
|
|
return new ClaimsPrincipal(new ClaimsIdentity());
|
|
}
|
|
}
|