fix: prevent auction snapshot mutation
This commit is contained in:
1 parent
6dbc643c44
commit
37f1f4225d
5 files changed
+166
-19
No files matched your search
@@ -1017,6 +1017,115 @@ describe('AuctionService', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps Redis sold snapshotBefore isolated from the sold structure mutation', async () => {
|
||||
const matchId = new mongoose.Types.ObjectId();
|
||||
const captainUserId = new mongoose.Types.ObjectId();
|
||||
const playerUserId = new mongoose.Types.ObjectId();
|
||||
const auction = {
|
||||
_id: new mongoose.Types.ObjectId(),
|
||||
auctionEngineVersion: 'redis-v1',
|
||||
matchId,
|
||||
matchSideEffectRevision: 0,
|
||||
};
|
||||
const biddingState = {
|
||||
auctionBidHistory: [],
|
||||
auctionLifecycleId: 'life-1',
|
||||
auctionPlayerOrder: [
|
||||
{
|
||||
userId: playerUserId.toString(),
|
||||
preferredPositions: [{ position: 'MID', priority: 1 }],
|
||||
},
|
||||
],
|
||||
auctionTeams: [
|
||||
{
|
||||
captainUserId: captainUserId.toString(),
|
||||
members: [],
|
||||
remainingBidPointAmount: 1000,
|
||||
teamIndex: 1,
|
||||
},
|
||||
],
|
||||
bidRoundExtensionSeconds: 5,
|
||||
currentAuctionHistorySequence: 3,
|
||||
currentAuctionPlayerOrderIndex: 0,
|
||||
currentAuctionRound: 1,
|
||||
currentBidRoundPlayerUserId: playerUserId.toString(),
|
||||
currentHighestBidPointAmount: 120,
|
||||
currentHighestBidderTeamIndex: 1,
|
||||
initialTeamBidPointAmount: 1000,
|
||||
maximumBidRoundDurationSeconds: 30,
|
||||
passedAuctionPlayerQueue: [],
|
||||
phase: 'bidding',
|
||||
revision: 4,
|
||||
topTierAuctionPriorityThreshold: 'NONE',
|
||||
};
|
||||
const soldState = {
|
||||
...biddingState,
|
||||
auctionTeams: [
|
||||
{
|
||||
...biddingState.auctionTeams[0],
|
||||
members: [
|
||||
{
|
||||
assignedPosition: 'MID',
|
||||
memberAcquisitionBidPointAmount: 120,
|
||||
userId: playerUserId.toString(),
|
||||
},
|
||||
],
|
||||
remainingBidPointAmount: 880,
|
||||
},
|
||||
],
|
||||
currentAuctionHistorySequence: 4,
|
||||
currentHighestBidPointAmount: 120,
|
||||
phase: 'sold',
|
||||
revision: 5,
|
||||
};
|
||||
const {
|
||||
service,
|
||||
auctionRedisCommandService,
|
||||
auctionRedisStateReaderService,
|
||||
} = createService({
|
||||
auction: {
|
||||
findOne: jest.fn().mockResolvedValue(auction),
|
||||
},
|
||||
});
|
||||
auctionRedisStateReaderService.readAuctionStateView
|
||||
.mockResolvedValueOnce(biddingState)
|
||||
.mockResolvedValueOnce(soldState);
|
||||
|
||||
await expect(
|
||||
service.markSold({
|
||||
auctionActionRequestId: '00000000-0000-4000-8000-000000000061',
|
||||
clientObservedAuctionLifecycleId: 'life-1',
|
||||
clientObservedCurrentAuctionPlayerOrderIndex: 0,
|
||||
clientObservedCurrentBidRoundPlayerUserId: playerUserId.toString(),
|
||||
clientObservedPhase: 'bidding',
|
||||
clientObservedRevision: 4,
|
||||
matchId,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
phase: 'sold',
|
||||
revision: 5,
|
||||
});
|
||||
|
||||
const transitionInput =
|
||||
auctionRedisCommandService.applyTransition.mock.calls[0][1];
|
||||
const durabilityPayload = JSON.parse(transitionInput.durabilityPayloadJson);
|
||||
expect(durabilityPayload.snapshotBefore).toMatchObject({
|
||||
phase: 'bidding',
|
||||
revision: 4,
|
||||
});
|
||||
expect(durabilityPayload.snapshotBefore.auctionTeams[0].members).toEqual(
|
||||
[],
|
||||
);
|
||||
expect(
|
||||
durabilityPayload.afterAuctionMongoProjection.auctionTeams[0].members,
|
||||
).toEqual([
|
||||
expect.objectContaining({
|
||||
memberAcquisitionBidPointAmount: 120,
|
||||
userId: playerUserId.toString(),
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns bid deltas without re-reading the full Redis state', async () => {
|
||||
const matchId = new mongoose.Types.ObjectId();
|
||||
const captainUserId = new mongoose.Types.ObjectId();
|
||||
|
||||
Reference in new issue
Block a user