Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions server/api/jellyfin.test.ts
Comment thread
fallenbagel marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import assert from 'node:assert/strict';
import { afterEach, describe, it, mock } from 'node:test';

import type { AxiosInstance } from 'axios';

import JellyfinAPI from '@server/api/jellyfin';

function buildJellyfin(): JellyfinAPI {
return new JellyfinAPI('http://localhost:8096');
}

function getAxios(jellyfin: JellyfinAPI): AxiosInstance {
return (jellyfin as unknown as { axios: AxiosInstance }).axios;
}

describe('JellyfinAPI getEpisodes', () => {
afterEach(() => mock.restoreAll());

it('filters special and virtual episodes', async () => {
const jellyfin = buildJellyfin();
mock.method(getAxios(jellyfin), 'get', async () => ({
data: {
Items: [
{
Id: 'ep1',
SeasonId: 'season-1',
LocationType: 'FileSystem',
},
{
Id: 'ep-special',
SeasonId: 'season-0',
LocationType: 'FileSystem',
},
{
Id: 'ep2',
SeasonId: 'season-1',
LocationType: 'FileSystem',
},
{
Id: 'ep-virtual',
SeasonId: 'season-1',
LocationType: 'Virtual',
},
],
},
}));

const episodes = await jellyfin.getEpisodes('test-series', 'season-1');
assert.deepStrictEqual(
episodes.map((episode) => episode.Id),
['ep1', 'ep2']
);
});

it('keeps episodes without a SeasonId', async () => {
const jellyfin = buildJellyfin();
mock.method(getAxios(jellyfin), 'get', async () => ({
data: {
Items: [{ Id: 'ep1', LocationType: 'FileSystem' }],
},
}));

const episodes = await jellyfin.getEpisodes('test-series', 'season-1');
assert.deepStrictEqual(
episodes.map((episode) => episode.Id),
['ep1']
);
});
});
4 changes: 3 additions & 1 deletion server/api/jellyfin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,9 @@ class JellyfinAPI extends ExternalAPI {
);

return episodeResponse.Items.filter(
(item: JellyfinLibraryItem) => item.LocationType !== 'Virtual'
(item: JellyfinLibraryItem) =>
item.LocationType !== 'Virtual' &&
(!item.SeasonId || item.SeasonId === seasonID)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
);
} catch (e) {
logger.error(
Expand Down
Loading