@@ -12,7 +12,26 @@ function jsonResponse(status: number, body: unknown) {
|
||||
} as unknown as Response;
|
||||
}
|
||||
|
||||
function sessionDetailPayload(status: string, options?: { roundQuestionId?: number | null }) {
|
||||
function sessionDetailPayload(
|
||||
status: string,
|
||||
options?: {
|
||||
roundQuestionId?: number | null;
|
||||
reveal?: {
|
||||
correct_answer: string;
|
||||
prompt?: string;
|
||||
lies?: Array<{ player_id: number; nickname: string; text: string; created_at?: string }>;
|
||||
guesses?: Array<{
|
||||
player_id: number;
|
||||
nickname: string;
|
||||
selected_text: string;
|
||||
is_correct: boolean;
|
||||
fooled_player_id: number | null;
|
||||
fooled_player_nickname?: string;
|
||||
created_at?: string;
|
||||
}>;
|
||||
} | null;
|
||||
}
|
||||
) {
|
||||
const roundQuestionId = options?.roundQuestionId ?? 41;
|
||||
|
||||
return {
|
||||
@@ -37,6 +56,23 @@ function sessionDetailPayload(status: string, options?: { roundQuestionId?: numb
|
||||
{ id: 1, nickname: 'Host', score: 0, is_connected: true },
|
||||
{ id: 2, nickname: 'Mads', score: 120, is_connected: true },
|
||||
],
|
||||
reveal:
|
||||
options?.reveal === undefined || options?.reveal === null
|
||||
? null
|
||||
: {
|
||||
round_question_id: roundQuestionId,
|
||||
round_number: 1,
|
||||
prompt: options.reveal.prompt ?? 'Q?',
|
||||
correct_answer: options.reveal.correct_answer,
|
||||
lies: (options.reveal.lies ?? []).map((lie) => ({
|
||||
...lie,
|
||||
created_at: lie.created_at ?? '2026-01-01T00:00:05Z',
|
||||
})),
|
||||
guesses: (options.reveal.guesses ?? []).map((guess) => ({
|
||||
...guess,
|
||||
created_at: guess.created_at ?? '2026-01-01T00:00:10Z',
|
||||
})),
|
||||
},
|
||||
phase_view_model: {
|
||||
status,
|
||||
round_number: 1,
|
||||
@@ -101,6 +137,48 @@ describe('HostShellComponent gameplay wiring', () => {
|
||||
expect(component.loading).toBe(false);
|
||||
});
|
||||
|
||||
it('hydrates canonical reveal payload in reveal phase', async () => {
|
||||
const fetchMock: FetchMock = vi.fn().mockResolvedValue(
|
||||
jsonResponse(
|
||||
200,
|
||||
sessionDetailPayload('reveal', {
|
||||
roundQuestionId: 77,
|
||||
reveal: {
|
||||
correct_answer: 'Mercury',
|
||||
lies: [{ player_id: 2, nickname: 'Mads', text: 'Venus' }],
|
||||
guesses: [
|
||||
{
|
||||
player_id: 3,
|
||||
nickname: 'Luna',
|
||||
selected_text: 'Venus',
|
||||
is_correct: false,
|
||||
fooled_player_id: 2,
|
||||
fooled_player_nickname: 'Mads',
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
const component = new HostShellComponent();
|
||||
component.sessionCode = 'ABCD12';
|
||||
|
||||
await component.refreshSession();
|
||||
|
||||
expect(component.session?.reveal?.correct_answer).toBe('Mercury');
|
||||
expect(component.session?.reveal?.lies[0]).toMatchObject({ player_id: 2, nickname: 'Mads', text: 'Venus' });
|
||||
expect(component.session?.reveal?.guesses[0]).toMatchObject({
|
||||
player_id: 3,
|
||||
nickname: 'Luna',
|
||||
selected_text: 'Venus',
|
||||
fooled_player_id: 2,
|
||||
fooled_player_nickname: 'Mads',
|
||||
});
|
||||
});
|
||||
|
||||
it('captures scoreboard error for retry path', async () => {
|
||||
const fetchMock: FetchMock = vi.fn().mockResolvedValue(jsonResponse(500, { error: 'Scoreboard unavailable' }));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user