feat: show tier history in auction spotlight
This commit is contained in:
1 parent
de8bc87940
commit
ebca348723
8 files changed
+160
-3
No files matched your search
@@ -322,6 +322,119 @@ describe('AuctionService', () => {
|
||||
expect(randomSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('includes tier history in auction player snapshots when starting an auction', async () => {
|
||||
const matchId = new mongoose.Types.ObjectId();
|
||||
const communityId = new mongoose.Types.ObjectId();
|
||||
const userIds = Array.from(
|
||||
{ length: 10 },
|
||||
() => new mongoose.Types.ObjectId(),
|
||||
);
|
||||
const participants = userIds.map((userId, index) => ({
|
||||
userId,
|
||||
preferredPositions: [{ position: 'MID', priority: 1 }],
|
||||
joinedAt: new Date(index),
|
||||
excluded: false,
|
||||
}));
|
||||
const match = {
|
||||
_id: matchId,
|
||||
communityId,
|
||||
participants,
|
||||
status: 'recruiting',
|
||||
teamBuiltAt: undefined,
|
||||
save: jest.fn().mockResolvedValue(undefined),
|
||||
};
|
||||
const tierHistory = [
|
||||
{
|
||||
queueType: 'RANKED_SOLO_5x5',
|
||||
tier: 'GOLD',
|
||||
rank: 'II',
|
||||
leaguePoints: 42,
|
||||
wins: 30,
|
||||
losses: 24,
|
||||
recordedAt: new Date('2026-05-01T00:00:00.000Z'),
|
||||
},
|
||||
{
|
||||
queueType: 'RANKED_SOLO_5x5',
|
||||
tier: 'PLATINUM',
|
||||
rank: 'IV',
|
||||
leaguePoints: 15,
|
||||
wins: 34,
|
||||
losses: 27,
|
||||
recordedAt: new Date('2026-05-08T00:00:00.000Z'),
|
||||
},
|
||||
];
|
||||
const users = userIds.slice(2).map((userId, index) => ({
|
||||
_id: userId,
|
||||
riotAccounts: [
|
||||
{
|
||||
puuid: `puuid-${index}`,
|
||||
gameName: `Player${index}`,
|
||||
tagLine: 'KR1',
|
||||
profileIconId: index,
|
||||
tiers: [],
|
||||
tierHistory: index === 0 ? tierHistory : [],
|
||||
championMasteries: [],
|
||||
recentStatsSummary: undefined,
|
||||
lastRefreshRequestedAt: new Date(),
|
||||
isPrimary: true,
|
||||
},
|
||||
],
|
||||
}));
|
||||
const auctionCreate = jest.fn().mockImplementation(async (payload) => ({
|
||||
_id: new mongoose.Types.ObjectId(),
|
||||
matchId,
|
||||
toObject: jest.fn().mockReturnValue({ matchId, ...payload }),
|
||||
}));
|
||||
const { service } = createService({
|
||||
match: {
|
||||
findById: jest.fn().mockResolvedValue(match),
|
||||
},
|
||||
user: {
|
||||
find: jest.fn().mockResolvedValue(users),
|
||||
},
|
||||
auction: {
|
||||
findOne: jest.fn().mockResolvedValue(null),
|
||||
create: auctionCreate,
|
||||
},
|
||||
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,
|
||||
communityId,
|
||||
captains: [
|
||||
{ teamIndex: 1, userId: userIds[0] },
|
||||
{ teamIndex: 2, userId: userIds[1] },
|
||||
],
|
||||
initialPoints: 1000,
|
||||
maxTimerSeconds: 30,
|
||||
bidExtensionSeconds: 5,
|
||||
topTierThreshold: 'NONE',
|
||||
manualTopTierUserIds: [],
|
||||
});
|
||||
|
||||
const firstPlayerSnapshot = auctionCreate.mock.calls[0][0].order.find(
|
||||
(player: { userId: mongoose.Types.ObjectId }) =>
|
||||
player.userId.equals(userIds[2]),
|
||||
);
|
||||
|
||||
expect(firstPlayerSnapshot).toMatchObject({
|
||||
userId: userIds[2],
|
||||
tierHistory,
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects bids when the team already has 5 members including captain', async () => {
|
||||
const matchId = new mongoose.Types.ObjectId();
|
||||
const auction = {
|
||||
|
||||
@@ -174,6 +174,7 @@ export class AuctionService {
|
||||
profileIconId: primary.profileIconId,
|
||||
preferredPositions: participant.preferredPositions,
|
||||
tiers: primary.tiers,
|
||||
tierHistory: primary.tierHistory ?? [],
|
||||
masteries: primary.championMasteries,
|
||||
recentStatsSummary: primary.recentStatsSummary,
|
||||
passCount: 0,
|
||||
@@ -919,6 +920,7 @@ export class AuctionService {
|
||||
'order.$.tagLine': account.tagLine,
|
||||
'order.$.profileIconId': account.profileIconId,
|
||||
'order.$.tiers': account.tiers,
|
||||
'order.$.tierHistory': account.tierHistory ?? [],
|
||||
'order.$.masteries': account.championMasteries,
|
||||
'order.$.recentStatsSummary': account.recentStatsSummary,
|
||||
updatedAt: new Date(),
|
||||
|
||||
@@ -593,6 +593,7 @@ export interface AuctionPlayerSnapshot {
|
||||
profileIconId: number;
|
||||
preferredPositions: PositionPreference[];
|
||||
tiers: TierInfo[];
|
||||
tierHistory: TierHistoryEntry[];
|
||||
masteries: ChampionMasteryEntry[];
|
||||
recentStatsSummary?: RiotRecentStatsSummary;
|
||||
passCount: number;
|
||||
@@ -1531,6 +1532,11 @@ const AuctionPlayerSnapshotSubSchema = new Schema<AuctionPlayerSnapshot>(
|
||||
default: [],
|
||||
},
|
||||
tiers: { type: [TierInfoSubSchema], required: true, default: [] },
|
||||
tierHistory: {
|
||||
type: [TierHistoryEntrySubSchema],
|
||||
required: true,
|
||||
default: [],
|
||||
},
|
||||
masteries: {
|
||||
type: [ChampionMasteryEntrySubSchema],
|
||||
required: true,
|
||||
|
||||
@@ -225,6 +225,7 @@ function createUserHistoryPath(
|
||||
export function useUserHistoryProfile(
|
||||
userId: string | undefined,
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
enabled = true,
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: ['user-history-profile', communityId, userId ?? null],
|
||||
@@ -233,7 +234,7 @@ export function useUserHistoryProfile(
|
||||
`/communities/${communityId}/users/${userId}/history-profile`,
|
||||
{ auth: 'none' },
|
||||
),
|
||||
enabled: Boolean(communityId && userId),
|
||||
enabled: enabled && Boolean(communityId && userId),
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import type {
|
||||
ApiPositionPreference,
|
||||
ApiRiotLaneStats,
|
||||
ApiRiotRecentStatsSummary,
|
||||
ApiTierHistoryEntry,
|
||||
ApiTierInfo,
|
||||
MatchStatus,
|
||||
Position,
|
||||
@@ -91,6 +92,7 @@ export interface AuctionPlayerView extends ParticipantView {
|
||||
level: number;
|
||||
points: number;
|
||||
}[];
|
||||
tierHistory: ApiTierHistoryEntry[];
|
||||
recentStats: {
|
||||
overall: ApiRiotLaneStats;
|
||||
byLane: Partial<Record<RiotLane, ApiRiotLaneStats>>;
|
||||
@@ -236,6 +238,7 @@ function mapAuctionPlayerToView(
|
||||
summonerName: player.gameName,
|
||||
tag: player.tagLine,
|
||||
tier: selectPrimaryTier(player.tiers),
|
||||
tierHistory: player.tierHistory ?? [],
|
||||
mainPosition,
|
||||
subPosition,
|
||||
profileIconId: player.profileIconId,
|
||||
@@ -288,12 +291,14 @@ function mapAuctionTeamToView(
|
||||
...participant,
|
||||
passCount: 0,
|
||||
masteries: [],
|
||||
tierHistory: [],
|
||||
recentStats: createEmptyRecentStatsView(),
|
||||
}
|
||||
: {
|
||||
...createFallbackParticipant(member.userId),
|
||||
passCount: 0,
|
||||
masteries: [],
|
||||
tierHistory: [],
|
||||
recentStats: createEmptyRecentStatsView(),
|
||||
});
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ export interface ApiRiotAccount {
|
||||
summonerLevel: number;
|
||||
isPrimary: boolean;
|
||||
tiers: ApiTierInfo[];
|
||||
tierHistory: unknown[];
|
||||
tierHistory: ApiTierHistoryEntry[];
|
||||
matchIds: string[];
|
||||
championMasteries: ApiChampionMasteryEntry[];
|
||||
championRecords: Record<string, Record<string, unknown>>;
|
||||
@@ -247,6 +247,7 @@ export interface ApiAuctionPlayerSnapshot {
|
||||
profileIconId: number;
|
||||
preferredPositions: ApiPositionPreference[];
|
||||
tiers: ApiTierInfo[];
|
||||
tierHistory: ApiTierHistoryEntry[];
|
||||
masteries: ApiChampionMasteryEntry[];
|
||||
recentStatsSummary?: ApiRiotRecentStatsSummary;
|
||||
passCount: number;
|
||||
|
||||
@@ -159,8 +159,10 @@ function TierTooltip({
|
||||
|
||||
export default function TierHistoryChart({
|
||||
entries,
|
||||
className = "border border-base-content/10 bg-base-100 mb-5 overflow-hidden",
|
||||
}: {
|
||||
entries: ApiTierHistoryEntry[];
|
||||
className?: string;
|
||||
}) {
|
||||
// 데이터에 존재하는 큐 목록 (솔로 우선)
|
||||
const availableQueues = useMemo(() => {
|
||||
@@ -264,7 +266,7 @@ export default function TierHistoryChart({
|
||||
);
|
||||
|
||||
return (
|
||||
<section className="border border-base-content/10 bg-base-100 mb-5 overflow-hidden">
|
||||
<section className={className}>
|
||||
{header}
|
||||
{points.length < 2 ? (
|
||||
<div className="px-4 py-10 text-center text-xs text-base-content/35">
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import {
|
||||
lazy,
|
||||
Suspense,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
@@ -17,6 +19,7 @@ import {
|
||||
useMe,
|
||||
useResetAuction,
|
||||
useUndoAuction,
|
||||
useUserHistoryProfile,
|
||||
} from '../api/hooks';
|
||||
import {
|
||||
mapApiAuctionToAuctionState,
|
||||
@@ -50,6 +53,8 @@ import type {
|
||||
Position,
|
||||
} from '../api/types';
|
||||
|
||||
const TierHistoryChart = lazy(() => import('../components/TierHistoryChart'));
|
||||
|
||||
type CaptainRole = {
|
||||
teamIndex: number;
|
||||
};
|
||||
@@ -481,7 +486,16 @@ function PlayerSpotlight({
|
||||
}) {
|
||||
const { data: ddragon } = useDdragonManifest();
|
||||
const player = state.currentPlayer;
|
||||
const historyProfileQuery = useUserHistoryProfile(
|
||||
player?.userId,
|
||||
DEFAULT_COMMUNITY_ID,
|
||||
Boolean(player && player.tierHistory.length === 0),
|
||||
);
|
||||
if (!player) return null;
|
||||
const tierHistory =
|
||||
player.tierHistory.length > 0
|
||||
? player.tierHistory
|
||||
: (historyProfileQuery.data?.tierHistory ?? []);
|
||||
|
||||
return (
|
||||
<div className="border border-base-content/10 bg-base-100">
|
||||
@@ -575,6 +589,19 @@ function PlayerSpotlight({
|
||||
<RecentSoloStats player={player} />
|
||||
</div>
|
||||
|
||||
{tierHistory.length > 0 && (
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="h-[180px] border-t border-base-content/8 bg-base-100" />
|
||||
}
|
||||
>
|
||||
<TierHistoryChart
|
||||
entries={tierHistory}
|
||||
className="border-t border-base-content/8 bg-base-100 overflow-hidden"
|
||||
/>
|
||||
</Suspense>
|
||||
)}
|
||||
|
||||
{(state.phase === 'bidding' || state.phase === 'sold') && (
|
||||
<div className="border-t border-base-content/8 px-4 py-3 bg-base-content/[0.02]">
|
||||
<div className="flex items-center justify-between">
|
||||
|
||||
Reference in new issue
Block a user