feat(account): add /account/update_name endpoint
Implements POST /account/update_name — writes Viewer.DisplayName and returns an empty array per the prod capture. Includes TDD test covering the persist side-effect. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
34
SVSim.UnitTests/Controllers/AccountControllerTests.cs
Normal file
34
SVSim.UnitTests/Controllers/AccountControllerTests.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using NUnit.Framework;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SVSim.Database;
|
||||
using SVSim.UnitTests.Infrastructure;
|
||||
|
||||
namespace SVSim.UnitTests.Controllers;
|
||||
|
||||
public class AccountControllerTests
|
||||
{
|
||||
[Test]
|
||||
public async Task UpdateName_writes_display_name()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
long viewerId = await factory.SeedViewerAsync(tutorialState: 0);
|
||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
|
||||
var requestJson = """{"name":"littlefootse","viewer_id":"0","steam_id":0,"steam_session_ticket":""}""";
|
||||
|
||||
var response = await client.PostAsync("/account/update_name",
|
||||
new StringContent(requestJson, Encoding.UTF8, "application/json"));
|
||||
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
|
||||
// Verify persisted name.
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
var viewer = await db.Viewers.FirstAsync(v => v.Id == viewerId);
|
||||
Assert.That(viewer.DisplayName, Is.EqualTo("littlefootse"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user