Skip to content

Commit

Permalink
Fix duplicate summon ticket rows (#783)
Browse files Browse the repository at this point in the history
Fixes an issue where two summon ticket rows could be added if you
claimed two presents with summon tickets simultaneously, as subsequent
invocations of SummonTicketHandler weren't aware of the pending row in
the change tracker.

Additionally bump time tolerance due to summon history test failures in
CI
  • Loading branch information
SapiensAnatis authored May 4, 2024
1 parent 601a4dc commit 8330b1a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using DragaliaAPI.Database.Entities;
using DragaliaAPI.Shared.Definitions.Enums.Summon;
using DragaliaAPI.Shared.Features.Presents;
using DragaliaAPI.Shared.MasterAsset.Models.Summon;
using Microsoft.EntityFrameworkCore;

namespace DragaliaAPI.Integration.Test.Features.Present;
Expand Down Expand Up @@ -455,6 +457,51 @@ await this.Client.PostMsgpack<PresentReceiveResponse>(
.And.Contain(x => x.CharaId == Charas.Addis);
}

[Fact]
public async Task Receive_SummonTickets_StacksCorrectly()
{
List<DbPlayerPresent> presents =
[
new DbPlayerPresent()
{
EntityType = EntityTypes.SummonTicket,
EntityId = (int)SummonTickets.AdventurerSummon,
EntityQuantity = 2,
},
new DbPlayerPresent()
{
EntityType = EntityTypes.SummonTicket,
EntityId = (int)SummonTickets.AdventurerSummon,
EntityQuantity = 2,
}
];

await this.AddRangeToDatabase(presents);

await this.ApiContext.PlayerSummonTickets.ExecuteDeleteAsync();

IEnumerable<ulong> presentIdList = presents.Select(x => (ulong)x.PresentId);

await this.Client.PostMsgpack<PresentReceiveResponse>(
$"{Controller}/receive",
new PresentReceiveRequest() { PresentIdList = presentIdList }
);

this.ApiContext.PlayerSummonTickets.AsNoTracking()
.Should()
.BeEquivalentTo<DbSummonTicket>(
[
new DbSummonTicket()
{
ViewerId = this.ViewerId,
SummonTicketId = SummonTickets.AdventurerSummon,
Quantity = 4
},
],
opts => opts.Excluding(x => x.KeyId)
);
}

[Fact]
public async Task Receive_DragonGifts_HandlesCorrectly()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class SummonTest : TestFixture
public SummonTest(CustomWebApplicationFactory factory, ITestOutputHelper outputHelper)
: base(factory, outputHelper)
{
CommonAssertionOptions.ApplyTimeOptions();
CommonAssertionOptions.ApplyTimeOptions(toleranceSec: 2);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public async Task<GrantReturn> Grant(Entity entity)
private async Task AddStackableTicket(SummonTickets ticketId, int quantity)
{
DbSummonTicket ticket =
await apiContext
.PlayerSummonTickets.Where(x => x.SummonTicketId == ticketId)
.FirstOrDefaultAsync() ?? this.InitializeEmptyStackableTicket(ticketId);
apiContext.PlayerSummonTickets.Local.FirstOrDefault(x => x.SummonTicketId == ticketId)
?? await apiContext.PlayerSummonTickets.FirstOrDefaultAsync(x =>
x.SummonTicketId == ticketId
)
?? this.InitializeEmptyStackableTicket(ticketId);

ticket.Quantity += quantity;
}
Expand Down

0 comments on commit 8330b1a

Please sign in to comment.