Genre cleanup tools
This commit is contained in:
@@ -9,6 +9,11 @@ import {
|
||||
getWatchlistLabelsForTarget
|
||||
} from '../src/lib/constants.js';
|
||||
import { normalizeLookupItem, rankRecommendationResults } from '../src/lib/collection-tools.js';
|
||||
import {
|
||||
buildSingleGenreUpdate,
|
||||
normalizeGenreNames,
|
||||
pickSuggestedGenre
|
||||
} from '../src/lib/genre-cleanup.js';
|
||||
import * as embyUserCache from '../src/lib/server/emby-user-cache.js';
|
||||
|
||||
const tests = [];
|
||||
@@ -280,6 +285,44 @@ test('normalizeLookupItem preserves already-normalized recommendation items', ()
|
||||
});
|
||||
});
|
||||
|
||||
test('normalizeGenreNames trims and deduplicates genre labels', () => {
|
||||
assert.deepEqual(
|
||||
normalizeGenreNames([' Drama ', 'Comedy', 'drama', '', null, 'Comedy ']),
|
||||
['Drama', 'Comedy']
|
||||
);
|
||||
});
|
||||
|
||||
test('pickSuggestedGenre prefers an existing Emby genre if TMDB also includes it', () => {
|
||||
assert.equal(
|
||||
pickSuggestedGenre(['Action', 'Drama', 'Thriller'], ['Drama', 'Crime']),
|
||||
'Drama'
|
||||
);
|
||||
});
|
||||
|
||||
test('pickSuggestedGenre falls back to the first TMDB genre when there is no overlap', () => {
|
||||
assert.equal(
|
||||
pickSuggestedGenre(['Action', 'Adventure'], ['Comedy']),
|
||||
'Action'
|
||||
);
|
||||
});
|
||||
|
||||
test('buildSingleGenreUpdate keeps only the selected genre in both genre fields', () => {
|
||||
const updated = buildSingleGenreUpdate(
|
||||
{
|
||||
Name: 'Example',
|
||||
Genres: ['Drama', 'Crime'],
|
||||
GenreItems: [
|
||||
{ Name: 'Drama', Id: 62 },
|
||||
{ Name: 'Crime', Id: 4910 }
|
||||
]
|
||||
},
|
||||
'Crime'
|
||||
);
|
||||
|
||||
assert.deepEqual(updated.Genres, ['Crime']);
|
||||
assert.deepEqual(updated.GenreItems, [{ Name: 'Crime', Id: 4910 }]);
|
||||
});
|
||||
|
||||
test('recommendation ranking deduplicates and prioritizes overlaps across seeds', () => {
|
||||
const ranked = rankRecommendationResults(
|
||||
['seed-a', 'seed-b'],
|
||||
|
||||
Reference in New Issue
Block a user