97 lines
2.5 KiB
TypeScript
97 lines
2.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import { deriveGameplayPhase, transitionGameplayPhase } from '../../../src/spa/gameplay-phase-machine';
|
|
|
|
describe('gameplay phase machine sync guards', () => {
|
|
it('keeps explicit scoreboard status as scoreboard phase', () => {
|
|
const phase = deriveGameplayPhase({
|
|
session: {
|
|
code: 'ABCD12',
|
|
status: 'scoreboard',
|
|
host_id: 1,
|
|
current_round: 1,
|
|
players_count: 2,
|
|
},
|
|
round_question: null,
|
|
players: [],
|
|
phase_view_model: {
|
|
status: 'scoreboard',
|
|
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: false,
|
|
can_start_next_round: true,
|
|
can_finish_game: true,
|
|
},
|
|
player: {
|
|
can_join: false,
|
|
can_submit_lie: false,
|
|
can_submit_guess: false,
|
|
can_view_final_result: false,
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(phase).toBe('scoreboard');
|
|
});
|
|
|
|
it('maps finished status to scoreboard phase fallback', () => {
|
|
const phase = deriveGameplayPhase({
|
|
session: {
|
|
code: 'ABCD12',
|
|
status: 'finished',
|
|
host_id: 1,
|
|
current_round: 1,
|
|
players_count: 2,
|
|
},
|
|
round_question: null,
|
|
players: [],
|
|
phase_view_model: {
|
|
status: 'finished',
|
|
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: false,
|
|
can_start_next_round: false,
|
|
can_finish_game: false,
|
|
},
|
|
player: {
|
|
can_join: false,
|
|
can_submit_lie: false,
|
|
can_submit_guess: false,
|
|
can_view_final_result: true,
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(phase).toBe('scoreboard');
|
|
});
|
|
|
|
it('transitions reveal -> scoreboard on SCOREBOARD_READY', () => {
|
|
expect(transitionGameplayPhase('reveal', 'SCOREBOARD_READY')).toEqual({
|
|
phase: 'scoreboard',
|
|
changed: true,
|
|
});
|
|
});
|
|
});
|