external-reading.spec.ts 1.1 KB

12345678910111213141516171819202122
  1. import { extractReadingWords, readNcloudSessionToken } from './external-reading';
  2. import { normalizeReadingParams } from '../features/english-reading/reading.utils';
  3. describe('external reading migration', () => {
  4. it('extracts source Title values from serialized xxqs data', () => {
  5. expect(extractReadingWords('[{"Title":"apple"},{"Title":" book "}]')).toEqual(['apple', 'book']);
  6. expect(extractReadingWords('{"0":{"Title":"cat"}}')).toEqual(['cat']);
  7. expect(extractReadingWords('not-json')).toEqual([]);
  8. });
  9. it('reads the original NCloud cache key without failing on invalid data', () => {
  10. const storage = { getItem: () => JSON.stringify({ sessionToken: 'session-123' }) };
  11. expect(readNcloudSessionToken(storage)).toBe('session-123');
  12. expect(readNcloudSessionToken({ getItem: () => '{' })).toBe('');
  13. });
  14. it('accepts packed legacy params in the internal reading route', () => {
  15. const value = JSON.stringify({ wordList: ['one'], token: 'token' });
  16. expect(normalizeReadingParams({ params: value }).wordList).toEqual(['one']);
  17. expect(normalizeReadingParams({ params: encodeURIComponent(value) }).token).toBe('token');
  18. });
  19. });