feat(mvp): complete Blazor UI + User Management + integration tests
This commit is contained in:
1 parent
b217c932e8
commit
38816aec8a
26 files changed
+1893
-45
No files matched your search
@@ -0,0 +1,91 @@
|
||||
using System.Net.Http.Json;
|
||||
using Heimdall.IntegrationTests.Factories;
|
||||
using Shouldly;
|
||||
|
||||
namespace Heimdall.IntegrationTests.Controllers;
|
||||
|
||||
public class AuthControllerTests : IClassFixture<HeimdallWebApplicationFactory>
|
||||
{
|
||||
private readonly HttpClient _client;
|
||||
|
||||
public AuthControllerTests(HeimdallWebApplicationFactory factory)
|
||||
{
|
||||
_client = factory.CreateClient();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Register_ValidRequest_ReturnsOk()
|
||||
{
|
||||
var response = await _client.PostAsJsonAsync("api/auth/register", new
|
||||
{
|
||||
email = $"test-{Guid.NewGuid()}@heimdall.test",
|
||||
password = "TestPassword123!",
|
||||
displayName = "Test User"
|
||||
});
|
||||
|
||||
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Register_DuplicateEmail_ReturnsConflict()
|
||||
{
|
||||
var email = $"dup-{Guid.NewGuid()}@heimdall.test";
|
||||
|
||||
var first = await _client.PostAsJsonAsync("api/auth/register", new
|
||||
{
|
||||
email,
|
||||
password = "TestPassword123!",
|
||||
displayName = "User 1"
|
||||
});
|
||||
first.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
|
||||
|
||||
var second = await _client.PostAsJsonAsync("api/auth/register", new
|
||||
{
|
||||
email,
|
||||
password = "TestPassword123!",
|
||||
displayName = "User 2"
|
||||
});
|
||||
|
||||
second.StatusCode.ShouldBe(System.Net.HttpStatusCode.Conflict);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Login_ValidCredentials_ReturnsOk()
|
||||
{
|
||||
var email = $"login-{Guid.NewGuid()}@heimdall.test";
|
||||
await _client.PostAsJsonAsync("api/auth/register", new
|
||||
{
|
||||
email,
|
||||
password = "TestPassword123!",
|
||||
displayName = "Login User"
|
||||
});
|
||||
|
||||
var response = await _client.PostAsJsonAsync("api/auth/login", new
|
||||
{
|
||||
email,
|
||||
password = "TestPassword123!"
|
||||
});
|
||||
|
||||
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Login_InvalidPassword_ReturnsUnauthorized()
|
||||
{
|
||||
var email = $"badpwd-{Guid.NewGuid()}@heimdall.test";
|
||||
await _client.PostAsJsonAsync("api/auth/register", new
|
||||
{
|
||||
email,
|
||||
password = "TestPassword123!",
|
||||
displayName = "Bad Pwd User"
|
||||
});
|
||||
|
||||
var response = await _client.PostAsJsonAsync("api/auth/login", new
|
||||
{
|
||||
email,
|
||||
password = "WrongPassword!"
|
||||
});
|
||||
|
||||
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.Unauthorized);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user