test(frontend): normalize reveal guess fooled-player nullability
This commit is contained in:
@@ -131,10 +131,11 @@ function mapSessionDetail(payload: unknown): SessionDetailResponse {
|
||||
}),
|
||||
guesses: guessesRaw.map((guess, index) => {
|
||||
const record = asRecord(guess, `session_detail.reveal.guesses[${index}]`);
|
||||
const fooledPlayerId = record.fooled_player_id;
|
||||
if (fooledPlayerId !== null && !isNumber(fooledPlayerId)) {
|
||||
const fooledPlayerIdRaw = record.fooled_player_id;
|
||||
if (fooledPlayerIdRaw !== undefined && fooledPlayerIdRaw !== null && !isNumber(fooledPlayerIdRaw)) {
|
||||
throw new Error(`Invalid API contract: expected number|null at session_detail.reveal.guesses[${index}].fooled_player_id`);
|
||||
}
|
||||
const fooledPlayerId = fooledPlayerIdRaw === undefined ? null : fooledPlayerIdRaw;
|
||||
const fooledPlayerNickname = record.fooled_player_nickname;
|
||||
if (fooledPlayerNickname !== undefined && !isString(fooledPlayerNickname)) {
|
||||
throw new Error(`Invalid API contract: expected string at session_detail.reveal.guesses[${index}].fooled_player_nickname`);
|
||||
|
||||
@@ -283,6 +283,79 @@ describe('createAngularApiClient', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('normalizes omitted fooled_player_id to null in canonical reveal payload guesses', async () => {
|
||||
const get = vi.fn<AngularHttpClientLike['get']>(async <T>(url: string) => {
|
||||
if (url === '/lobby/sessions/ABCD12') {
|
||||
return {
|
||||
session: { code: 'ABCD12', status: 'reveal', host_id: 1, current_round: 1, players_count: 2 },
|
||||
players: [
|
||||
{ id: 2, nickname: 'Maja', score: 10, is_connected: true },
|
||||
{ id: 3, nickname: 'Bo', score: 7, is_connected: true }
|
||||
],
|
||||
round_question: {
|
||||
id: 77,
|
||||
round_number: 1,
|
||||
prompt: 'Q?',
|
||||
shown_at: '2026-03-01T18:00:00Z',
|
||||
answers: [{ text: 'A' }, { text: 'B' }]
|
||||
},
|
||||
reveal: {
|
||||
round_question_id: 77,
|
||||
round_number: 1,
|
||||
prompt: 'Q?',
|
||||
correct_answer: 'A',
|
||||
lies: [],
|
||||
guesses: [
|
||||
{
|
||||
player_id: 3,
|
||||
nickname: 'Bo',
|
||||
selected_text: 'A',
|
||||
is_correct: true,
|
||||
created_at: '2026-03-01T18:00:15Z'
|
||||
}
|
||||
]
|
||||
},
|
||||
phase_view_model: {
|
||||
status: 'reveal',
|
||||
round_number: 1,
|
||||
players_count: 2,
|
||||
constraints: {
|
||||
min_players_to_start: 2,
|
||||
max_players_mvp: 8,
|
||||
min_players_reached: true,
|
||||
max_players_allowed: true
|
||||
},
|
||||
host: {
|
||||
can_start_round: false,
|
||||
can_show_question: false,
|
||||
can_mix_answers: false,
|
||||
can_calculate_scores: false,
|
||||
can_reveal_scoreboard: true,
|
||||
can_start_next_round: false,
|
||||
can_finish_game: false
|
||||
},
|
||||
player: {
|
||||
can_join: true,
|
||||
can_submit_lie: false,
|
||||
can_submit_guess: false,
|
||||
can_view_final_result: false
|
||||
}
|
||||
}
|
||||
} as T;
|
||||
}
|
||||
throw { status: 404, error: { error: 'Not found' } };
|
||||
});
|
||||
|
||||
const client = createAngularApiClient({ get, post: vi.fn() } as unknown as AngularHttpClientLike);
|
||||
const session = await client.getSession('abcd12');
|
||||
|
||||
expect(session.ok).toBe(true);
|
||||
if (session.ok) {
|
||||
expect(session.data.reveal?.guesses[0].fooled_player_id).toBeNull();
|
||||
expect(session.data.reveal?.guesses[0]).not.toHaveProperty('fooled_player_nickname');
|
||||
}
|
||||
});
|
||||
|
||||
it('maps host/player gameplay endpoints through typed response mappers', async () => {
|
||||
const get = vi.fn<AngularHttpClientLike['get']>(async <T>(url: string) => {
|
||||
if (url === '/lobby/sessions/ABCD12/scoreboard') {
|
||||
|
||||
Reference in New Issue
Block a user