fix: prevent empty-team auction completion state

This commit is contained in:
dahyeon committed 2026-06-25 05:26:09 -07:00
1 parent 2984bd1604
commit ab721873f3
6 files changed
+748 -452

No files matched your search

@@ -158,11 +158,12 @@ describe('AuctionService', () => {
it('rejects non-positive or fractional bid amounts before loading auction state', async () => {
const matchId = new mongoose.Types.ObjectId();
const auctionFindOne = jest.fn();
const { service, auctionRedisCommandService, auctionRedisService } = createService({
auction: {
findOne: auctionFindOne,
},
});
const { service, auctionRedisCommandService, auctionRedisService } =
createService({
auction: {
findOne: auctionFindOne,
},
});
await expect(
service.placeBid({
@@ -266,7 +267,7 @@ describe('AuctionService', () => {
});
expect(match.status).toBe('team-built');
expect(match.teamBuiltAt).toBeInstanceOf(Date);
expect(match.teamBuiltAt).toBeUndefined();
expect(match.save).toHaveBeenCalledTimes(1);
expect(tournamentCodeService.reserveForMatch).not.toHaveBeenCalled();
expect(tournamentResultService.scheduleInitialPoll).not.toHaveBeenCalled();
@@ -542,44 +543,45 @@ describe('AuctionService', () => {
}));
const auctionDeleteOne = jest.fn().mockResolvedValue({ deletedCount: 1 });
const historyDeleteMany = jest.fn().mockResolvedValue({ deletedCount: 2 });
const { service, auctionRedisCommandService, auctionRedisService } = createService({
match: {
findById: jest.fn().mockResolvedValue(match),
},
user: {
find: jest.fn().mockResolvedValue(users),
},
auction: {
create: auctionCreate,
deleteOne: auctionDeleteOne,
findOne: jest.fn().mockResolvedValue(existingAuction),
},
auctionHistory: {
create: jest.fn().mockResolvedValue(undefined),
deleteMany: historyDeleteMany,
findOne: jest.fn().mockReturnValue({
sort: jest.fn().mockReturnValue({
const { service, auctionRedisCommandService, auctionRedisService } =
createService({
match: {
findById: jest.fn().mockResolvedValue(match),
},
user: {
find: jest.fn().mockResolvedValue(users),
},
auction: {
create: auctionCreate,
deleteOne: auctionDeleteOne,
findOne: jest.fn().mockResolvedValue(existingAuction),
},
auctionHistory: {
create: jest.fn().mockResolvedValue(undefined),
deleteMany: historyDeleteMany,
findOne: jest.fn().mockReturnValue({
sort: jest.fn().mockReturnValue({
select: jest.fn().mockReturnValue({
lean: jest.fn().mockReturnValue({
exec: jest.fn().mockResolvedValue(null),
}),
}),
}),
}),
},
community: {
findById: jest.fn().mockReturnValue({
select: jest.fn().mockReturnValue({
lean: jest.fn().mockReturnValue({
exec: jest.fn().mockResolvedValue(null),
exec: jest.fn().mockResolvedValue({
riotPlatform: 'kr',
riotRegion: 'asia',
}),
}),
}),
}),
}),
},
community: {
findById: jest.fn().mockReturnValue({
select: jest.fn().mockReturnValue({
lean: jest.fn().mockReturnValue({
exec: jest.fn().mockResolvedValue({
riotPlatform: 'kr',
riotRegion: 'asia',
}),
}),
}),
}),
},
});
},
});
await service.start({
matchId,
@@ -800,7 +802,9 @@ describe('AuctionService', () => {
findOne: jest.fn().mockResolvedValue(auction),
},
});
auctionRedisStateReaderService.readLiveStateIdentity.mockResolvedValue(null);
auctionRedisStateReaderService.readLiveStateIdentity.mockResolvedValue(
null,
);
auctionRedisStateReaderService.readAuctionStateView.mockResolvedValue(
redisState,
);
@@ -870,12 +874,15 @@ describe('AuctionService', () => {
phase: 'bidding',
revision: 2,
};
const { service, auctionRedisCommandService, auctionRedisStateReaderService } =
createService({
auction: {
findOne: jest.fn().mockResolvedValue(auction),
},
});
const {
service,
auctionRedisCommandService,
auctionRedisStateReaderService,
} = createService({
auction: {
findOne: jest.fn().mockResolvedValue(auction),
},
});
auctionRedisStateReaderService.readAuctionStateView
.mockResolvedValueOnce(presentingState)
.mockResolvedValueOnce(biddingState);
@@ -973,12 +980,15 @@ describe('AuctionService', () => {
currentHighestBidPointAmount: 120,
revision: 3,
};
const { service, auctionRedisCommandService, auctionRedisStateReaderService } =
createService({
auction: {
findOne: jest.fn().mockResolvedValue(auction),
},
});
const {
service,
auctionRedisCommandService,
auctionRedisStateReaderService,
} = createService({
auction: {
findOne: jest.fn().mockResolvedValue(auction),
},
});
auctionRedisStateReaderService.readAuctionStateView
.mockResolvedValueOnce(biddingState)
.mockResolvedValueOnce(afterBidState);
@@ -1189,15 +1199,14 @@ describe('AuctionService', () => {
auctionRedisStateReaderService,
tournamentCodeService,
tournamentResultService,
} =
createService({
auction: {
findOne: jest.fn().mockResolvedValue(auction),
},
match: {
findById: jest.fn().mockResolvedValue(match),
},
});
} = createService({
auction: {
findOne: jest.fn().mockResolvedValue(auction),
},
match: {
findById: jest.fn().mockResolvedValue(match),
},
});
auctionRedisStateReaderService.readAuctionStateView
.mockResolvedValueOnce(soldState)
.mockResolvedValueOnce(completeState);
@@ -1377,8 +1386,7 @@ describe('AuctionService', () => {
const signupOrder = userIds.slice(2).map((userId) => userId.toString());
const auctionOrder = auctionCreate.mock.calls[0][0].order.map(
(player: { userId: mongoose.Types.ObjectId }) =>
player.userId.toString(),
(player: { userId: mongoose.Types.ObjectId }) => player.userId.toString(),
);
expect(auctionOrder).not.toEqual(signupOrder);
@@ -1647,9 +1655,7 @@ describe('AuctionService', () => {
amount: 20,
});
expect(auction.currentDeadline).toEqual(
new Date(now.getTime() + 12000),
);
expect(auction.currentDeadline).toEqual(new Date(now.getTime() + 12000));
expect(auction.save).toHaveBeenCalledTimes(1);
});
@@ -2151,21 +2157,25 @@ describe('AuctionService', () => {
const auctionReplaceOne = jest.fn().mockReturnValue({
exec: jest.fn().mockResolvedValue(undefined),
});
const { service, connectionService, tournamentCodeService, tournamentResultService } =
createService({
auction: {
findOne: jest.fn().mockReturnValue(auctionFindOneQuery),
replaceOne: auctionReplaceOne,
findById: jest.fn().mockResolvedValue(restored),
},
auctionHistory: {
findOne: jest.fn().mockReturnValue(historyFindOneQuery),
deleteMany: jest.fn().mockReturnValue(historyDeleteManyQuery),
},
match: {
findById: jest.fn().mockReturnValue(matchFindByIdQuery),
},
});
const {
service,
connectionService,
tournamentCodeService,
tournamentResultService,
} = createService({
auction: {
findOne: jest.fn().mockReturnValue(auctionFindOneQuery),
replaceOne: auctionReplaceOne,
findById: jest.fn().mockResolvedValue(restored),
},
auctionHistory: {
findOne: jest.fn().mockReturnValue(historyFindOneQuery),
deleteMany: jest.fn().mockReturnValue(historyDeleteManyQuery),
},
match: {
findById: jest.fn().mockReturnValue(matchFindByIdQuery),
},
});
connectionService.createSession.mockResolvedValue(session);
await expect(
@@ -2261,23 +2271,27 @@ describe('AuctionService', () => {
}),
};
const auctionReplaceOne = jest.fn();
const { service, connectionService, auctionRedisCommandService, auctionRedisStateReaderService } =
createService({
auction: {
findOne: jest.fn().mockReturnValue({
session: jest.fn().mockResolvedValue(auction),
}),
replaceOne: auctionReplaceOne,
},
auctionHistory: {
findOne: jest.fn().mockReturnValue(historyFindOneQuery),
},
match: {
findById: jest.fn().mockReturnValue({
session: jest.fn().mockResolvedValue(match),
}),
},
});
const {
service,
connectionService,
auctionRedisCommandService,
auctionRedisStateReaderService,
} = createService({
auction: {
findOne: jest.fn().mockReturnValue({
session: jest.fn().mockResolvedValue(auction),
}),
replaceOne: auctionReplaceOne,
},
auctionHistory: {
findOne: jest.fn().mockReturnValue(historyFindOneQuery),
},
match: {
findById: jest.fn().mockReturnValue({
session: jest.fn().mockResolvedValue(match),
}),
},
});
connectionService.createSession.mockResolvedValue(session);
auctionRedisStateReaderService.readAuctionStateView
.mockResolvedValueOnce(currentRedisState)
@@ -2298,7 +2312,9 @@ describe('AuctionService', () => {
).resolves.toBe(restoredRedisState);
expect(auctionReplaceOne).not.toHaveBeenCalled();
expect(auctionRedisCommandService.reserveActionRequest).toHaveBeenCalledWith(
expect(
auctionRedisCommandService.reserveActionRequest,
).toHaveBeenCalledWith(
matchId.toString(),
expect.objectContaining({
auctionActionRequestId: '00000000-0000-4000-8000-000000000070',
@@ -2319,9 +2335,7 @@ describe('AuctionService', () => {
durationSeconds: 30,
mode: 'set-relative',
});
const durabilityPayload = JSON.parse(
transitionInput.durabilityPayloadJson,
);
const durabilityPayload = JSON.parse(transitionInput.durabilityPayloadJson);
expect(durabilityPayload).toMatchObject({
auctionActionType: 'undo',
historyMutation: {