import assert from 'node:assert/strict' import test from 'node:test' import { createPinia, setActivePinia } from 'pinia' import { installFetchMock, resetAppTestState } from './helpers/fetchMock' test.beforeEach(async () => { installFetchMock() await resetAppTestState() setActivePinia(createPinia()) }) test('games catalog exposes gold-guess rewards from GET /games', async () => { globalThis.routeHandlers!.set('/games', () => ({ status: 200, body: [ { id: 'gold-guess', title: 'حدس', description: 'd', icon: '📈', color: '#7438c9', route: '/games/gold-guess', rewardCoins: 20, rewardXp: 50, }, ], })) const { useGamesStore } = await import('../src/stores/games') const games = useGamesStore() await games.loadCatalog() const item = games.gameById('gold-guess') assert.ok(item) assert.equal(item!.rewardCoins, 20) assert.equal(item!.rewardXp, 50) }) test('unknown game id returns null without throwing', async () => { globalThis.routeHandlers!.set('/games', () => ({ status: 200, body: [] })) const { useGamesStore } = await import('../src/stores/games') const games = useGamesStore() await games.loadCatalog() assert.equal(games.gameById('missing-game'), null) }) declare global { // eslint-disable-next-line no-var var routeHandlers: Map import('./helpers/fetchMock').MockResponse | Promise> }