fix(downloads): align episode identity contract

This commit is contained in:
4gray committed 2026-08-02 10:19:19 +02:00
1 parent 907e5f5a28
commit 626c6142f3
2 files changed
+9 -5

No files matched your search

@@ -19,6 +19,7 @@ function row(
overrides: Partial<EpisodeDownloadRecord> = {}
): EpisodeDownloadRecord {
return {
id: 1,
playlistId: identity.playlistId,
contentType: identity.contentType,
xtreamId: identity.xtreamId,
@@ -26,6 +27,7 @@ function row(
seasonNumber: identity.seasonNumber,
episodeNumber: identity.episodeNumber,
status: 'queued',
filePath: '/downloads/episode-3.mp4',
...overrides,
};
}
@@ -40,14 +42,14 @@ describe('episode download identity', () => {
});
expect(
findEpisodeDownload([coordinateFallback, canonical], identity)
findEpisodeDownload(identity, [coordinateFallback, canonical])
).toBe(canonical);
});
it('falls back to complete matching episode coordinates', () => {
const coordinateFallback = row({ xtreamId: 999 });
expect(findEpisodeDownload([coordinateFallback], identity)).toBe(
expect(findEpisodeDownload(identity, [coordinateFallback])).toBe(
coordinateFallback
);
});
@@ -61,7 +63,7 @@ describe('episode download identity', () => {
row({ contentType: 'vod', xtreamId: 995 }),
];
expect(findEpisodeDownload(candidates, identity)).toBeUndefined();
expect(findEpisodeDownload(identity, candidates)).toBeUndefined();
});
it('allows an episode with no existing download', () => {
@@ -14,6 +14,7 @@ export interface EpisodeDownloadIdentity {
}
export interface EpisodeDownloadRecord {
readonly id: number;
readonly playlistId: string;
readonly contentType: ElectronBridgePlaybackContentType;
readonly xtreamId: number;
@@ -22,11 +23,12 @@ export interface EpisodeDownloadRecord {
readonly episodeNumber?: number;
readonly status: ElectronBridgeDownloadStatus;
readonly fileAvailability?: ElectronDownloadFileAvailability;
readonly filePath?: string;
}
export function findEpisodeDownload<T extends EpisodeDownloadRecord>(
downloads: readonly T[],
identity: EpisodeDownloadIdentity
identity: EpisodeDownloadIdentity,
downloads: readonly T[]
): T | undefined {
const canonicalMatch = downloads.find(
(download) =>