Use sorted username dropdown for character owner editing

This commit is contained in:
2026-02-26 14:19:58 +01:00
parent 76c83a5784
commit 83151d81fd
10 changed files with 91 additions and 4 deletions

View File

@@ -29,4 +29,22 @@ public sealed class AuthApiTests : ApiTestBase
var invalidLogin = await client.PostAsJsonAsync("/api/auth/login", new LoginRequest("alice", "wrong-password"));
Assert.Equal(HttpStatusCode.BadRequest, invalidLogin.StatusCode);
}
}
[Fact]
public async Task UsernamesEndpoint_RequiresAuthAndReturnsAlphabeticalList()
{
using var factory = CreateFactory();
using var client = factory.CreateClient(new() { AllowAutoRedirect = false });
await RegisterAsync(client, "zoe", "Password123", "Zoe");
await RegisterAsync(client, "amy", "Password123", "Amy");
await RegisterAsync(client, "bob", "Password123", "Bob");
var unauthorized = await client.GetAsync("/api/users/usernames");
Assert.Equal(HttpStatusCode.Unauthorized, unauthorized.StatusCode);
await LoginAsync(client, "bob", "Password123");
var usernames = await GetAsync<IReadOnlyList<string>>(client, "/api/users/usernames");
Assert.Equal(["amy", "bob", "zoe"], usernames);
}
}

View File

@@ -56,4 +56,22 @@ public sealed class ServiceAuthTests
Assert.True(login.Succeeded);
Assert.Equal(2, hasher.HashCalls);
}
}
[Fact]
public void GetUsernames_RequiresAuthAndReturnsSortedUsernames()
{
using var harness = ServiceTestSupport.CreateHarness();
var service = harness.Service;
service.Register("zoe", "Password123", "Zoe");
service.Register("amy", "Password123", "Amy");
service.Register("bob", "Password123", "Bob");
var unauthorized = service.GetUsernames(string.Empty);
Assert.False(unauthorized.Succeeded);
var session = ServiceTestSupport.GetValue(service.Login("bob", "Password123")).SessionToken;
var usernames = ServiceTestSupport.GetValue(service.GetUsernames(session));
Assert.Equal(["amy", "bob", "zoe"], usernames);
}
}