perf: cache auction history summaries
This commit is contained in:
1 parent
8567948084
commit
b9aaf55193
2 files changed
+141
-6
No files matched your search
@@ -183,6 +183,77 @@ describe('AuctionService', () => {
|
||||
expect(auctionRedisCommandService.placeBid).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('lists auction history with a summary projection and short local cache', async () => {
|
||||
const nowSpy = jest.spyOn(Date, 'now').mockReturnValue(1000);
|
||||
const matchId = new mongoose.Types.ObjectId();
|
||||
const communityId = new mongoose.Types.ObjectId();
|
||||
const match = {
|
||||
communityId: {
|
||||
equals: jest.fn((value) => value.toString() === communityId.toString()),
|
||||
},
|
||||
};
|
||||
const historyRows = [
|
||||
{
|
||||
action: 'sold',
|
||||
sequence: 4,
|
||||
takenAt: new Date('2026-06-26T00:00:00.000Z'),
|
||||
},
|
||||
{
|
||||
action: 'open-bidding',
|
||||
sequence: 3,
|
||||
takenAt: new Date('2026-06-26T00:00:01.000Z'),
|
||||
},
|
||||
];
|
||||
const historyExec = jest.fn().mockResolvedValue(historyRows);
|
||||
const historyLean = jest.fn().mockReturnValue({ exec: historyExec });
|
||||
const historyLimit = jest.fn().mockReturnValue({ lean: historyLean });
|
||||
const historySort = jest.fn().mockReturnValue({ limit: historyLimit });
|
||||
const historySelect = jest.fn().mockReturnValue({ sort: historySort });
|
||||
const historyFind = jest.fn().mockReturnValue({ select: historySelect });
|
||||
const { service } = createService({
|
||||
auctionHistory: {
|
||||
find: historyFind,
|
||||
},
|
||||
match: {
|
||||
findById: jest.fn().mockReturnValue({
|
||||
select: jest.fn().mockResolvedValue(match),
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
await expect(
|
||||
service.listHistory({ matchId, communityId }),
|
||||
).resolves.toEqual([
|
||||
{
|
||||
action: 'sold',
|
||||
actionLabel: '낙찰 처리',
|
||||
sequence: 4,
|
||||
takenAt: historyRows[0].takenAt,
|
||||
},
|
||||
{
|
||||
action: 'open-bidding',
|
||||
actionLabel: '입찰 열기',
|
||||
sequence: 3,
|
||||
takenAt: historyRows[1].takenAt,
|
||||
},
|
||||
]);
|
||||
await service.listHistory({ matchId, communityId });
|
||||
|
||||
expect(historyFind).toHaveBeenCalledTimes(1);
|
||||
expect(historySelect).toHaveBeenCalledWith({
|
||||
_id: 0,
|
||||
action: 1,
|
||||
sequence: 1,
|
||||
takenAt: 1,
|
||||
});
|
||||
expect(historySort).toHaveBeenCalledWith({ sequence: -1 });
|
||||
expect(historyLimit).toHaveBeenCalledWith(100);
|
||||
|
||||
nowSpy.mockReturnValue(3101);
|
||||
await service.listHistory({ matchId, communityId });
|
||||
expect(historyFind).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('starts an auction without reserving tournament codes before teams are complete', async () => {
|
||||
const matchId = new mongoose.Types.ObjectId();
|
||||
const communityId = new mongoose.Types.ObjectId();
|
||||
|
||||
Reference in new issue
Block a user