import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'; import { RudderClient } from '../../src/client/RudderClient.js'; import { createTestClient } from '../helpers/createClient.js'; import { createFakeGateway, type FakeGateway } from '../helpers/fakeGateway.js'; describe('E2E: player storage', () => { let gateway: FakeGateway; let client: RudderClient; beforeEach(() => { gateway = createFakeGateway({ storage: new Map([ ['progress', { id: 'id-progress', type: 'progress', data: JSON.stringify({ level: 7, gold: 1200 }) }], ['prefs', { id: 'id-prefs', type: 'prefs', data: JSON.stringify({ sound: false }) }], ]), }); gateway.install(); client = createTestClient(); }); afterEach(() => vi.unstubAllGlobals()); it('reads the items written for the player', async () => { await client.auth.loginWithDevice(); const all = await client.storage.reload(); expect(all.items).toHaveLength(2); const progress = all.items!.find((i) => i.type === 'progress'); expect(JSON.parse(progress!.data!)).toEqual({ level: 7, gold: 1200 }); const getReq = gateway.recorded.findLast((r) => r.method === 'GET' && r.path === '/sdk/v1/storage'); expect(getReq?.query.get('limit')).toBe('100'); }); it('storage reads carry the auth token', async () => { const token = (await client.auth.loginWithDevice()).accessToken; await client.storage.reload(); const getReq = gateway.recorded.findLast((r) => r.method === 'GET' && r.path === '/sdk/v1/storage'); expect(getReq?.authToken).toBe(token); }); });