fix(issue-301): gate client actions from canonical phase flags
This commit is contained in:
@@ -2,6 +2,8 @@ import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
allowedGameplayEvents,
|
||||
deriveGameplayPhase,
|
||||
isHostGameplayActionAllowed,
|
||||
isPlayerGameplayActionAllowed,
|
||||
transitionGameplayPhase,
|
||||
type GameplayPhase
|
||||
} from '../src/spa/gameplay-phase-machine';
|
||||
@@ -103,4 +105,44 @@ describe('gameplay phase machine skeleton', () => {
|
||||
})
|
||||
).toBe('scoreboard');
|
||||
});
|
||||
|
||||
it('gates host and player actions from canonical phase_view_model permissions', () => {
|
||||
const session = {
|
||||
session: { code: 'ABCD12', status: 'scoreboard', host_id: 1, current_round: 1, players_count: 3 },
|
||||
players: [],
|
||||
round_question: { id: 77, prompt: 'Q?', answers: [] },
|
||||
phase_view_model: {
|
||||
status: 'reveal',
|
||||
round_number: 1,
|
||||
players_count: 3,
|
||||
constraints: {
|
||||
min_players_to_start: 3,
|
||||
max_players_mvp: 5,
|
||||
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: true,
|
||||
can_finish_game: true
|
||||
},
|
||||
player: {
|
||||
can_join: false,
|
||||
can_submit_lie: false,
|
||||
can_submit_guess: false,
|
||||
can_view_final_result: false
|
||||
}
|
||||
}
|
||||
} as const;
|
||||
|
||||
expect(deriveGameplayPhase(session as any)).toBe('reveal');
|
||||
expect(isHostGameplayActionAllowed(session as any, 'loadScoreboard')).toBe(true);
|
||||
expect(isHostGameplayActionAllowed(session as any, 'startNextRound')).toBe(true);
|
||||
expect(isHostGameplayActionAllowed(session as any, 'finishGame')).toBe(true);
|
||||
expect(isPlayerGameplayActionAllowed(session as any, 'submitGuess')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user