From 77a14f6ef3665f1684adfc59da5ad8dfe5dc3287 Mon Sep 17 00:00:00 2001 From: Jay Malhotra <5047192+SapiensAnatis@users.noreply.github.com> Date: Wed, 20 Mar 2024 07:20:37 +0000 Subject: [PATCH] Fix change tracker error with rotating gifts (#729) Golden chalice appears twice in the rotating gift list, so we must continually update the dict as we go along --- .../Features/Login/LoginTest.cs | 30 +++++++++++++++++++ .../Features/Login/DragonGiftResetAction.cs | 4 +++ 2 files changed, 34 insertions(+) diff --git a/DragaliaAPI/DragaliaAPI.Integration.Test/Features/Login/LoginTest.cs b/DragaliaAPI/DragaliaAPI.Integration.Test/Features/Login/LoginTest.cs index c4e4b9853..9033b561e 100644 --- a/DragaliaAPI/DragaliaAPI.Integration.Test/Features/Login/LoginTest.cs +++ b/DragaliaAPI/DragaliaAPI.Integration.Test/Features/Login/LoginTest.cs @@ -86,6 +86,36 @@ await this .Be(100, because: "the reset action should not affect stored gifts"); } + [Fact] + public async Task LoginIndex_LastLoginBeforeReset_NoDragonGifts_ResetsDragonGiftCount() + { + await this + .ApiContext.PlayerDragonGifts.Where(x => x.ViewerId == ViewerId) + .ExecuteDeleteAsync(); + + this.MockTimeProvider.SetUtcNow( + new DateTimeOffset(2049, 03, 15, 23, 13, 59, TimeSpan.Zero) + ); // Monday + + await this.Client.PostMsgpack("/login/index", new LoginIndexRequest()); + + List dbPlayerDragonGifts = await this.GetDragonGifts(); + + dbPlayerDragonGifts + .Where(x => x.DragonGiftId <= DragonGifts.HeartyStew) + .Should() + .AllSatisfy( + x => x.Quantity.Should().Be(1), + because: "purchasable gifts should be reset" + ); + + dbPlayerDragonGifts + .Should() + .Contain(x => x.DragonGiftId == DragonGifts.JuicyMeat) + .Which.Quantity.Should() + .Be(1, because: "the current day's rotating gift should be made available"); + } + [Fact] public async Task LoginIndex_GrantsLoginBonusBasedOnDb_GrantsEachDayReward() { diff --git a/DragaliaAPI/DragaliaAPI/Features/Login/DragonGiftResetAction.cs b/DragaliaAPI/DragaliaAPI/Features/Login/DragonGiftResetAction.cs index c4c12a1f7..66d653d82 100644 --- a/DragaliaAPI/DragaliaAPI/Features/Login/DragonGiftResetAction.cs +++ b/DragaliaAPI/DragaliaAPI/Features/Login/DragonGiftResetAction.cs @@ -34,6 +34,8 @@ public async Task Apply() }; apiContext.PlayerDragonGifts.Add(dbGift); + + dbGifts[giftId] = dbGift; } dbGift.Quantity = 1; @@ -56,6 +58,8 @@ public async Task Apply() }; apiContext.PlayerDragonGifts.Add(dbGift); + + dbGifts[dailyGiftId] = dbGift; } if (dayNo == (int)todayDayOfWeek)