From f0142f33b62180f882a41f5db6ad8f37721e147a Mon Sep 17 00:00:00 2001 From: DEV-bot Date: Mon, 16 Mar 2026 12:50:33 +0000 Subject: [PATCH] test(issue-301): align host gating specs with canonical phases --- .../host/host-shell.component.spec.ts | 19 +++++++++++++++---- frontend/src/spa/gameplay-phase-machine.ts | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/frontend/angular/src/app/features/host/host-shell.component.spec.ts b/frontend/angular/src/app/features/host/host-shell.component.spec.ts index cabc641..8535bfd 100644 --- a/frontend/angular/src/app/features/host/host-shell.component.spec.ts +++ b/frontend/angular/src/app/features/host/host-shell.component.spec.ts @@ -183,7 +183,11 @@ describe('HostShellComponent gameplay wiring', () => { const fetchMock: FetchMock = vi .fn() .mockResolvedValueOnce(jsonResponse(200, { session: { code: 'ABCD12', status: 'lie', current_round: 2 } })) - .mockResolvedValueOnce(jsonResponse(200, sessionDetailPayload('lie', { roundQuestionId: 99 }))); + .mockResolvedValueOnce(jsonResponse(200, sessionDetailPayload('lie', { roundQuestionId: 99 }))) + .mockResolvedValueOnce(jsonResponse(200, { session: { code: 'ABCD12', status: 'guess', current_round: 2 } })) + .mockResolvedValueOnce(jsonResponse(200, sessionDetailPayload('guess', { roundQuestionId: 77 }))) + .mockResolvedValueOnce(jsonResponse(200, { session: { code: 'ABCD12', status: 'reveal', current_round: 2 } })) + .mockResolvedValueOnce(jsonResponse(200, sessionDetailPayload('reveal', { roundQuestionId: 77 }))); vi.stubGlobal('fetch', fetchMock); @@ -206,8 +210,8 @@ describe('HostShellComponent gameplay wiring', () => { it('runs next-round transition without reload and clears scoreboard payload', async () => { const fetchMock: FetchMock = vi .fn() - .mockResolvedValueOnce(jsonResponse(200, { session: { code: 'ABCD12', status: 'lobby', current_round: 2 } })) - .mockResolvedValueOnce(jsonResponse(200, sessionDetailPayload('lobby', { roundQuestionId: null }))); + .mockResolvedValueOnce(jsonResponse(200, { session: { code: 'ABCD12', status: 'lie', current_round: 2 } })) + .mockResolvedValueOnce(jsonResponse(200, sessionDetailPayload('lie', { roundQuestionId: 99 }))); vi.stubGlobal('fetch', fetchMock); @@ -216,6 +220,7 @@ describe('HostShellComponent gameplay wiring', () => { component.scoreboardPayload = '{"leaderboard":[]}'; component.finalLeaderboardPayload = '{"leaderboard":[{"nickname":"Old","score":1}]}' ; component.finalLeaderboard = [{ id: 9, nickname: 'Old', score: 1 }]; + component.session = sessionDetailPayload('reveal', { roundQuestionId: 77 }) as any; await component.startNextRound(); @@ -252,6 +257,7 @@ describe('HostShellComponent gameplay wiring', () => { const component = new HostShellComponent(); component.sessionCode = 'ABCD12'; + component.session = sessionDetailPayload('reveal', { roundQuestionId: 77 }) as any; await component.finishGame(); expect(component.finishError).toContain('Finish game failed: Final leaderboard timeout'); @@ -275,6 +281,7 @@ describe('HostShellComponent gameplay wiring', () => { const component = new HostShellComponent(); component.sessionCode = ' '; + component.session = sessionDetailPayload('reveal', { roundQuestionId: 77 }) as any; await component.startNextRound(); await component.finishGame(); @@ -359,8 +366,12 @@ describe('HostShellComponent gameplay wiring', () => { expect(component.canStartNextRound).toBe(false); expect(component.canFinishGame).toBe(false); - component.session = sessionDetailPayload('scoreboard') as any; + component.session = sessionDetailPayload('reveal') as any; expect(component.canStartNextRound).toBe(true); expect(component.canFinishGame).toBe(true); + + component.session = sessionDetailPayload('scoreboard') as any; + expect(component.canStartNextRound).toBe(false); + expect(component.canFinishGame).toBe(false); }); }); diff --git a/frontend/src/spa/gameplay-phase-machine.ts b/frontend/src/spa/gameplay-phase-machine.ts index 257d220..17d57db 100644 --- a/frontend/src/spa/gameplay-phase-machine.ts +++ b/frontend/src/spa/gameplay-phase-machine.ts @@ -81,7 +81,7 @@ export function deriveGameplayPhase(session: SessionDetailResponse | null): Game export function isHostGameplayActionAllowed(session: SessionDetailResponse | null, action: HostGameplayAction): boolean { if (!session) { - return true; + return action === 'startRound'; } const host = session.phase_view_model?.host;