test(user-mypage): explain Clear() + cover unparseable rotation entries
Add a comment above MyPageBgRotation.Clear() explaining the EF OwnsMany delete-on-clear semantics. Add a 7th test covering garbage/"" entries in mypage_id_list falling back to BgId=0 while adjacent valid entries are unaffected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -32,6 +32,8 @@ public sealed class UserMyPageController : SVSimController
|
||||
viewer.MyPageBgSelectType = request.SelectType;
|
||||
viewer.MyPageBgId = ParseIdOrZero(request.MyPageId);
|
||||
|
||||
// Clear() on a loaded OwnsMany marks every tracked entry as Deleted; SaveChangesAsync
|
||||
// issues DELETEs for all old slots before inserting the new ones.
|
||||
viewer.MyPageBgRotation.Clear();
|
||||
for (int slot = 0; slot < request.MyPageIdList.Count; slot++)
|
||||
{
|
||||
|
||||
@@ -146,4 +146,23 @@ public class UserMyPageControllerTests
|
||||
// controller's literal return value is what comes back. An empty class serializes to "{}".
|
||||
Assert.That(raw, Is.EqualTo("{}"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Update_with_unparseable_mypage_id_list_entries_falls_back_to_zero()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
long viewerId = await factory.SeedViewerAsync();
|
||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
|
||||
var body = JsonBody("""
|
||||
{"select_type":2,"mypage_id":"0","mypage_id_list":["1001","garbage","","1002"]}
|
||||
""");
|
||||
var response = await client.PostAsync("/user_mypage/update", body);
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
|
||||
var viewer = await LoadViewerWithRotation(factory, viewerId);
|
||||
var pool = viewer.MyPageBgRotation.OrderBy(r => r.Slot).Select(r => r.BgId).ToList();
|
||||
Assert.That(pool, Is.EqualTo(new[] { 1001, 0, 0, 1002 }),
|
||||
"garbage and empty entries are stored as 0; valid entries unaffected");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user