import { extractReadingWords, readNcloudSessionToken } from './external-reading'; import { normalizeReadingParams } from '../features/english-reading/reading.utils'; describe('external reading migration', () => { it('extracts source Title values from serialized xxqs data', () => { expect(extractReadingWords('[{"Title":"apple"},{"Title":" book "}]')).toEqual(['apple', 'book']); expect(extractReadingWords('{"0":{"Title":"cat"}}')).toEqual(['cat']); expect(extractReadingWords('not-json')).toEqual([]); }); it('reads the original NCloud cache key without failing on invalid data', () => { const storage = { getItem: () => JSON.stringify({ sessionToken: 'session-123' }) }; expect(readNcloudSessionToken(storage)).toBe('session-123'); expect(readNcloudSessionToken({ getItem: () => '{' })).toBe(''); }); it('accepts packed legacy params in the internal reading route', () => { const value = JSON.stringify({ wordList: ['one'], token: 'token' }); expect(normalizeReadingParams({ params: value }).wordList).toEqual(['one']); expect(normalizeReadingParams({ params: encodeURIComponent(value) }).token).toBe('token'); }); });