feat: redesign auction engine with redis sot
This commit is contained in:
1 parent
737702d78c
commit
e8bb20d988
75 files changed
+12737
-542
No files matched your search
@@ -0,0 +1,94 @@
|
||||
import {
|
||||
AuctionHistoryEntrySchema,
|
||||
AuctionSchema,
|
||||
AuctionSideEffectApplicationSchema,
|
||||
tournamentModelDefinitions,
|
||||
} from './schema';
|
||||
|
||||
function indexWithKeys(
|
||||
schemaIndexes: ReturnType<typeof AuctionSchema.indexes>,
|
||||
expectedKeys: Record<string, 1 | -1>,
|
||||
) {
|
||||
return schemaIndexes.find(([keys]) => {
|
||||
return JSON.stringify(keys) === JSON.stringify(expectedKeys);
|
||||
});
|
||||
}
|
||||
|
||||
describe('auction Redis schema foundation', () => {
|
||||
it('defines Redis v1 projection metadata on auction documents', () => {
|
||||
expect(AuctionSchema.path('revision')).toBeDefined();
|
||||
expect(AuctionSchema.path('auctionEngineVersion')).toBeDefined();
|
||||
expect(AuctionSchema.path('auctionLifecycleId')).toBeDefined();
|
||||
expect(AuctionSchema.path('lastAppliedAuctionStateTransitionId')).toBeDefined();
|
||||
expect(AuctionSchema.path('currentAuctionHistorySequence')).toBeDefined();
|
||||
expect(AuctionSchema.path('startAuctionRequestId')).toBeDefined();
|
||||
expect(AuctionSchema.path('startAuctionStateTransitionId')).toBeDefined();
|
||||
expect(AuctionSchema.path('matchSideEffectStatus')).toBeDefined();
|
||||
expect(AuctionSchema.path('matchSideEffectRevision')).toBeDefined();
|
||||
});
|
||||
|
||||
it('defines the new auction state field names for migration targets', () => {
|
||||
expect(AuctionSchema.path('auctionTeams')).toBeDefined();
|
||||
expect(AuctionSchema.path('auctionPlayerOrder')).toBeDefined();
|
||||
expect(AuctionSchema.path('passedAuctionPlayerQueue')).toBeDefined();
|
||||
expect(AuctionSchema.path('currentAuctionRound')).toBeDefined();
|
||||
expect(AuctionSchema.path('currentAuctionPlayerOrderIndex')).toBeDefined();
|
||||
expect(AuctionSchema.path('auctionBidHistory')).toBeDefined();
|
||||
expect(AuctionSchema.path('currentHighestBidPointAmount')).toBeDefined();
|
||||
expect(AuctionSchema.path('currentHighestBidderTeamIndex')).toBeDefined();
|
||||
expect(AuctionSchema.path('currentBidRoundDeadlineTimestampMS')).toBeDefined();
|
||||
expect(AuctionSchema.path('maximumBidRoundDurationSeconds')).toBeDefined();
|
||||
expect(AuctionSchema.path('bidRoundExtensionSeconds')).toBeDefined();
|
||||
expect(AuctionSchema.path('initialTeamBidPointAmount')).toBeDefined();
|
||||
expect(AuctionSchema.path('topTierAuctionPriorityThreshold')).toBeDefined();
|
||||
expect(AuctionSchema.path('manualTopTierAuctionPriorityUserIds')).toBeDefined();
|
||||
expect(AuctionSchema.path('auctionStartedAtTimestampMS')).toBeDefined();
|
||||
expect(AuctionSchema.path('auctionCompletedAtTimestampMS')).toBeDefined();
|
||||
});
|
||||
|
||||
it('adds history transition fields and reset/undo action enum values', () => {
|
||||
expect(AuctionHistoryEntrySchema.path('auctionStateTransitionId')).toBeDefined();
|
||||
expect(AuctionHistoryEntrySchema.path('auctionLifecycleId')).toBeDefined();
|
||||
expect(AuctionHistoryEntrySchema.path('revision')).toBeDefined();
|
||||
expect(AuctionHistoryEntrySchema.path('historyMutation')).toBeDefined();
|
||||
expect(AuctionHistoryEntrySchema.path('matchSideEffectMutation')).toBeDefined();
|
||||
expect(
|
||||
AuctionHistoryEntrySchema.path<string>('action').options.enum,
|
||||
).toEqual(
|
||||
expect.arrayContaining(['start', 'open-bidding', 'bid', 'sold', 'passed', 'next', 'complete', 'reset', 'undo']),
|
||||
);
|
||||
});
|
||||
|
||||
it('adds unique history indexes for sequence and transition idempotency', () => {
|
||||
const indexes = AuctionHistoryEntrySchema.indexes();
|
||||
|
||||
expect(indexWithKeys(indexes, { auctionId: 1, sequence: 1 })?.[1]).toMatchObject({
|
||||
unique: true,
|
||||
});
|
||||
expect(
|
||||
indexWithKeys(indexes, { auctionId: 1, auctionStateTransitionId: 1 })?.[1],
|
||||
).toMatchObject({ unique: true, sparse: true });
|
||||
});
|
||||
|
||||
it('registers auction side effect application model with lease fields and unique idempotency index', () => {
|
||||
expect(AuctionSideEffectApplicationSchema.path('processingOwnerToken')).toBeDefined();
|
||||
expect(
|
||||
AuctionSideEffectApplicationSchema.path('processingLeaseExpiresAtTimestampMS'),
|
||||
).toBeDefined();
|
||||
expect(AuctionSideEffectApplicationSchema.path('payloadChecksum')).toBeDefined();
|
||||
|
||||
const indexes = AuctionSideEffectApplicationSchema.indexes();
|
||||
expect(
|
||||
indexWithKeys(indexes, {
|
||||
auctionId: 1,
|
||||
auctionStateTransitionId: 1,
|
||||
sideEffectType: 1,
|
||||
})?.[1],
|
||||
).toMatchObject({ unique: true });
|
||||
expect(
|
||||
tournamentModelDefinitions.some(
|
||||
(definition) => definition.name === 'auctionSideEffectApplication',
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user