fix(mypage): populate unread_present_count from ViewerPresents

The home-screen crate button reads this count via MyPageTask (parsed
into Data.MyPage.data.unread_mail_count) and MyPageItemHome.cs:148
routes it into SetUnreadGiftCount to render the "N" bubble on the
gift button. It was hardcoded 0, so tutorial gifts (5 presents sitting
in the viewer's inbox after signup) showed no badge until the crate
was opened.

Add IViewerRepository.CountUnclaimedPresentsAsync and call it from
MyPageController.Index. Regression test seeds a viewer with tutorial
presents and asserts unread_present_count > 0.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-07-04 14:44:52 -04:00
parent c087f9b08f
commit 05d143d2e8
4 changed files with 39 additions and 1 deletions

View File

@@ -54,4 +54,27 @@ public class MyPageControllerTests
var root = JsonDocument.Parse(await resp.Content.ReadAsStringAsync()).RootElement;
Assert.That(root.GetProperty("can_give_daily_login_bonus").GetBoolean(), Is.False);
}
[Test]
public async Task MyPage_unread_present_count_reflects_unclaimed_viewer_presents()
{
// Drives the home-screen crate badge — MyPageTask parses `unread_present_count` into
// Data.MyPage.data.unread_mail_count, which MyPageItemHome.SetUnreadGiftCount reads to
// show the "N" bubble on the gift button. Stubbed to 0 would hide it even when the
// tutorial gift has 5 rewards sitting unclaimed.
using var factory = new SVSimTestFactory();
await factory.SeedGlobalsAsync();
long viewerId = await factory.SeedViewerAsync();
await factory.SeedTutorialPresentsAsync(viewerId);
using var client = factory.CreateAuthenticatedClient(viewerId);
var resp = await client.PostAsync("/mypage/index",
new StringContent(MyPageRequestJson, Encoding.UTF8, "application/json"));
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.OK), await resp.Content.ReadAsStringAsync());
var root = JsonDocument.Parse(await resp.Content.ReadAsStringAsync()).RootElement;
int count = root.GetProperty("unread_present_count").GetInt32();
Assert.That(count, Is.GreaterThan(0),
"unread_present_count must be the viewer's live Unclaimed ViewerPresent count — a stub 0 hides the crate badge.");
}
}