feat(account): /account/update_birth persists viewer birth date
Strict yyyy-MM-dd parse (matches /load/index round-trip format) — rejects malformed input. data_headers.servertime is emitted by the standard envelope, which is what the client reads into BirthDayUpdateServerTime. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -106,4 +106,48 @@ public class AccountControllerTests
|
||||
var viewer = await db.Viewers.FirstAsync(v => v.Id == viewerId);
|
||||
Assert.That(viewer.DisplayName, Is.EqualTo(name));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateBirth_persists_and_round_trips_through_load_index()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
long viewerId = await factory.SeedViewerAsync(tutorialState: 0);
|
||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
|
||||
var setJson = """{"birth":"1995-07-04","viewer_id":"0","steam_id":0,"steam_session_ticket":""}""";
|
||||
var setResp = await client.PostAsync("/account/update_birth",
|
||||
new StringContent(setJson, Encoding.UTF8, "application/json"));
|
||||
var setBody = await setResp.Content.ReadAsStringAsync();
|
||||
Assert.That(setResp.StatusCode, Is.EqualTo(HttpStatusCode.OK), setBody);
|
||||
|
||||
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.Info.BirthDate.ToString("yyyy-MM-dd"), Is.EqualTo("1995-07-04"));
|
||||
|
||||
var loadJson = """{"viewer_id":"0","steam_id":0,"steam_session_ticket":"","carrier":"none","card_master_hash":""}""";
|
||||
var loadResp = await client.PostAsync("/load/index",
|
||||
new StringContent(loadJson, Encoding.UTF8, "application/json"));
|
||||
var body = await loadResp.Content.ReadAsStringAsync();
|
||||
using var doc = JsonDocument.Parse(body);
|
||||
Assert.That(doc.RootElement.GetProperty("user_info").GetProperty("birth").GetString(),
|
||||
Is.EqualTo("1995-07-04"), body);
|
||||
}
|
||||
|
||||
[TestCase("not-a-date")]
|
||||
[TestCase("1995/07/04")]
|
||||
[TestCase("1995-7-4")]
|
||||
[TestCase("")]
|
||||
public async Task UpdateBirth_rejects_malformed_input(string birth)
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
long viewerId = await factory.SeedViewerAsync(tutorialState: 0);
|
||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
|
||||
var json = $$"""{"birth":{{JsonSerializer.Serialize(birth)}},"viewer_id":"0","steam_id":0,"steam_session_ticket":""}""";
|
||||
var resp = await client.PostAsync("/account/update_birth",
|
||||
new StringContent(json, Encoding.UTF8, "application/json"));
|
||||
|
||||
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user