Fix Task 5 review issues: per-test ApiFactory, drop dead RoleManager param + EF Core using

This commit is contained in:
2026-06-11 18:38:37 +00:00
parent 2a208e81b2
commit a1aa5023a2
2 changed files with 10 additions and 11 deletions
+9 -8
View File
@@ -5,14 +5,13 @@ using Xunit;
namespace backend.tests;
public class AuthTests(ApiFactory factory) : IClassFixture<ApiFactory>
public class AuthTests
{
private readonly ApiFactory _factory = factory;
[Fact]
public async Task Register_then_login_then_me_returns_user()
{
var client = _factory.CreateClient();
using var factory = new ApiFactory();
var client = factory.CreateClient();
var reg = await client.PostAsJsonAsync("/api/auth/register",
new { email = "first@example.com", password = "Passw0rd!" });
@@ -30,7 +29,8 @@ public class AuthTests(ApiFactory factory) : IClassFixture<ApiFactory>
[Fact]
public async Task Me_without_login_returns_401()
{
var client = _factory.CreateClient();
using var factory = new ApiFactory();
var client = factory.CreateClient();
var res = await client.GetAsync("/api/auth/me");
res.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
}
@@ -38,11 +38,12 @@ public class AuthTests(ApiFactory factory) : IClassFixture<ApiFactory>
[Fact]
public async Task First_user_is_admin()
{
var client = _factory.CreateClient();
using var factory = new ApiFactory();
var client = factory.CreateClient();
await client.PostAsJsonAsync("/api/auth/register",
new { email = "first@example.com", password = "Passw0rd!" });
new { email = "admin@example.com", password = "Passw0rd!" });
await client.PostAsJsonAsync("/api/auth/login",
new { email = "first@example.com", password = "Passw0rd!" });
new { email = "admin@example.com", password = "Passw0rd!" });
var me = await client.GetAsync("/api/auth/me");
(await me.Content.ReadAsStringAsync()).Should().Contain("\"isAdmin\":true");