154 lines
4.4 KiB
TypeScript
154 lines
4.4 KiB
TypeScript
import mongoose from 'mongoose';
|
|
import {
|
|
buildAuctionRedisLiveStatePatchFromStructure,
|
|
buildAuctionRedisStructureState,
|
|
convertLegacyAuctionTeamsToRedisTeams,
|
|
} from './auction-redis-projection';
|
|
|
|
describe('auction redis projection helpers', () => {
|
|
it('converts legacy auction team fields to redis-v1 names', () => {
|
|
const captainUserId = new mongoose.Types.ObjectId();
|
|
const memberUserId = new mongoose.Types.ObjectId();
|
|
|
|
expect(
|
|
convertLegacyAuctionTeamsToRedisTeams([
|
|
{
|
|
teamIndex: 1,
|
|
captainUserId,
|
|
points: 970,
|
|
members: [
|
|
{
|
|
userId: memberUserId,
|
|
assignedPosition: 'ADC',
|
|
cost: 30,
|
|
},
|
|
],
|
|
},
|
|
]),
|
|
).toEqual([
|
|
{
|
|
teamIndex: 1,
|
|
captainUserId,
|
|
remainingBidPointAmount: 970,
|
|
members: [
|
|
{
|
|
userId: memberUserId,
|
|
assignedPosition: 'ADC',
|
|
memberAcquisitionBidPointAmount: 30,
|
|
},
|
|
],
|
|
},
|
|
]);
|
|
});
|
|
|
|
it('builds the redis structure state with only structure/config fields', () => {
|
|
const captainUserId = new mongoose.Types.ObjectId();
|
|
const playerUserId = new mongoose.Types.ObjectId();
|
|
|
|
expect(
|
|
buildAuctionRedisStructureState({
|
|
auctionPlayerOrder: [
|
|
{
|
|
userId: playerUserId,
|
|
puuid: 'puuid',
|
|
gameName: 'Player',
|
|
tagLine: 'KR1',
|
|
profileIconId: 1,
|
|
preferredPositions: [{ position: 'MID', priority: 1 }],
|
|
tiers: [],
|
|
tierHistory: [],
|
|
masteries: [],
|
|
passCount: 0,
|
|
},
|
|
],
|
|
auctionTeams: [
|
|
{
|
|
teamIndex: 1,
|
|
captainUserId,
|
|
remainingBidPointAmount: 1000,
|
|
members: [],
|
|
},
|
|
],
|
|
bidRoundExtensionSeconds: 5,
|
|
currentAuctionPlayerOrderIndex: 0,
|
|
currentAuctionRound: 1,
|
|
initialTeamBidPointAmount: 1000,
|
|
manualTopTierAuctionPriorityUserIds: [],
|
|
maximumBidRoundDurationSeconds: 30,
|
|
passedAuctionPlayerQueue: [],
|
|
topTierAuctionPriorityThreshold: 'NONE',
|
|
}),
|
|
).toMatchObject({
|
|
auctionPlayerOrder: [expect.objectContaining({ userId: playerUserId })],
|
|
auctionTeams: [
|
|
expect.objectContaining({
|
|
captainUserId,
|
|
remainingBidPointAmount: 1000,
|
|
teamIndex: 1,
|
|
}),
|
|
],
|
|
bidRoundExtensionSeconds: 5,
|
|
currentAuctionPlayerOrderIndex: 0,
|
|
currentAuctionRound: 1,
|
|
initialTeamBidPointAmount: 1000,
|
|
maximumBidRoundDurationSeconds: 30,
|
|
passedAuctionPlayerQueue: [],
|
|
topTierAuctionPriorityThreshold: 'NONE',
|
|
});
|
|
});
|
|
|
|
it('builds live state patch required by BID Lua', () => {
|
|
const captainUserId = new mongoose.Types.ObjectId();
|
|
const playerUserId = new mongoose.Types.ObjectId();
|
|
|
|
expect(
|
|
buildAuctionRedisLiveStatePatchFromStructure({
|
|
auctionPlayerOrder: [
|
|
{
|
|
userId: playerUserId,
|
|
puuid: 'puuid',
|
|
gameName: 'Player',
|
|
tagLine: 'KR1',
|
|
profileIconId: 1,
|
|
preferredPositions: [{ position: 'MID', priority: 1 }],
|
|
tiers: [],
|
|
tierHistory: [],
|
|
masteries: [],
|
|
passCount: 0,
|
|
},
|
|
],
|
|
auctionTeams: [
|
|
{
|
|
teamIndex: 2,
|
|
captainUserId,
|
|
remainingBidPointAmount: 970,
|
|
members: [
|
|
{
|
|
userId: new mongoose.Types.ObjectId(),
|
|
assignedPosition: 'ADC',
|
|
memberAcquisitionBidPointAmount: 30,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
bidRoundExtensionSeconds: 5,
|
|
currentAuctionPlayerOrderIndex: 0,
|
|
currentAuctionRound: 1,
|
|
initialTeamBidPointAmount: 1000,
|
|
manualTopTierAuctionPriorityUserIds: [],
|
|
maximumBidRoundDurationSeconds: 30,
|
|
passedAuctionPlayerQueue: [],
|
|
topTierAuctionPriorityThreshold: 'NONE',
|
|
}),
|
|
).toEqual({
|
|
bidRoundExtensionSeconds: 5,
|
|
currentAuctionPlayerOrderIndex: 0,
|
|
currentBidRoundPlayerUserId: playerUserId.toString(),
|
|
maximumBidRoundDurationSeconds: 30,
|
|
'team:2:assignedAuctionTeamMemberCount': 2,
|
|
'team:2:captainUserId': captainUserId.toString(),
|
|
'team:2:remainingBidPointAmount': 970,
|
|
});
|
|
});
|
|
});
|