Files
iptvnator/libs/services/src/lib/server-storage/server-migration-xtream.spec.ts
T
4grayandClaude Opus 5.5 f49ad59549 fix(server-storage): per-tab saved writes, memory overflow cache, snapshot aliases
- Unconfirmed writes and early edits are kept in the tab's own
  sessionStorage, so tabs never clear each other's; a shared registry of
  unconfirmed entries (one record per tab, ignored after ten minutes)
  keeps a re-read in one tab from replacing another tab's values.
- A cache value too big for localStorage stays readable from memory, so
  later edits are diffed against what the app reads.
- Typing legacy Xtream ids keeps each snapshot's bare key as an alias, so
  a reference not yet rewritten still resolves and a retry can type it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 08:33:32 +02:00

70 lines
2.5 KiB
TypeScript

import { combineUserData } from './server-migration-merge';
import { typeLegacyXtreamRefs } from './server-migration-xtream';
describe('typeLegacyXtreamRefs', () => {
it('types bare ids from the same copy snapshots', () => {
expect(
typeLegacyXtreamRefs({
'xtream-favorites': [42, 'movie:7', 99],
'xtream-recent-items': [{ id: 42, viewedAt: 't' }],
'xtream-collection-items': {
'42': { xtream_id: 42, type: 'live', title: 'News' },
'movie:7': { xtream_id: 7, type: 'movie' },
},
})
).toEqual({
'xtream-favorites': ['live:42', 'movie:7', 99],
'xtream-recent-items': [{ id: 'live:42', viewedAt: 't' }],
'xtream-collection-items': {
'42': { xtream_id: 42, type: 'live', title: 'News' },
'live:42': { xtream_id: 42, type: 'live', title: 'News' },
'movie:7': { xtream_id: 7, type: 'movie' },
},
});
});
it('keeps a live and a movie favorite that share an id apart', () => {
const browser = typeLegacyXtreamRefs({
'xtream-favorites': [42],
'xtream-collection-items': {
'42': { xtream_id: 42, type: 'live' },
},
});
const server = typeLegacyXtreamRefs({
'xtream-favorites': [42],
'xtream-collection-items': {
'42': { xtream_id: 42, type: 'movie' },
},
});
expect(
combineUserData([
server['xtream-favorites'],
browser['xtream-favorites'],
])
).toEqual(['movie:42', 'live:42']);
expect(
combineUserData([
server['xtream-collection-items'],
browser['xtream-collection-items'],
])
).toEqual({
// The server's own bare alias wins its key; both typed keys stay.
'42': { xtream_id: 42, type: 'movie' },
'movie:42': { xtream_id: 42, type: 'movie' },
'live:42': { xtream_id: 42, type: 'live' },
});
});
it('types numeric-string ids too', () => {
expect(
typeLegacyXtreamRefs({
'xtream-favorites': ['42'],
'xtream-collection-items': {
'42': { xtream_id: 42, type: 'movie' },
},
})['xtream-favorites']
).toEqual(['movie:42']);
});
});