57 lines
2.7 KiB
JavaScript
57 lines
2.7 KiB
JavaScript
'use strict';
|
|
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const {
|
|
sanitizeOverride,
|
|
applyMetadataOverride,
|
|
platformForGame,
|
|
annotateRegionalVariants,
|
|
} = require('../../src/services/game-metadata-view');
|
|
|
|
test('manual metadata is a bounded overlay and preserves provider data underneath', () => {
|
|
const original = {
|
|
game_id: 'PPSA00001',
|
|
prospero_name: 'Provider title',
|
|
prospero_icon_url: 'https://provider/icon.webp',
|
|
prospero_cover_url: 'https://provider/cover.webp',
|
|
metadata_source: 'online',
|
|
metadata_confidence: 'provider',
|
|
metadata_override: JSON.stringify({ title: 'My title', iconUrl: 'https://me/icon.webp', coverUrl: 'https://me/cover.webp', ignored: 'nope' }),
|
|
};
|
|
const result = applyMetadataOverride(original);
|
|
assert.equal(result.prospero_name, 'My title');
|
|
assert.equal(result.prospero_icon_url, 'https://me/icon.webp');
|
|
assert.equal(result.prospero_cover_url, 'https://me/cover.webp');
|
|
assert.equal(result.metadata.source, 'manual');
|
|
assert.deepEqual(result.metadata.overriddenFields, ['title', 'iconUrl', 'coverUrl']);
|
|
assert.equal(original.prospero_name, 'Provider title');
|
|
});
|
|
|
|
test('override sanitizer rejects unknown and empty fields', () => {
|
|
assert.deepEqual(sanitizeOverride({ title: ' Chimera ', unknown: 'x', region: '' }), { title: 'Chimera' });
|
|
assert.deepEqual(sanitizeOverride({ iconUrl: 'javascript:alert(1)', bannerUrl: 'https://user:pass@example.test/x' }), {});
|
|
assert.throws(() => sanitizeOverride({ iconUrl: 'http://example.test/x' }, { strict: true }), /HTTPS-URL/);
|
|
});
|
|
|
|
test('regional variants remain distinct and include provider and installed matches', () => {
|
|
const result = annotateRegionalVariants([
|
|
{
|
|
game_id: 'PPSA00001', prospero_name: 'Example™ PS5', prospero_region: 'EU', installed: 1,
|
|
prospero_other_regions: JSON.stringify([{ titleid: 'PPSA00002', region: 'US' }]),
|
|
},
|
|
{ game_id: 'PPSA00003', prospero_name: 'Example', prospero_region: 'JP', installed: 1 },
|
|
]);
|
|
assert.deepEqual(result[0].regional_variants.map(item => item.titleId).sort(), ['PPSA00002', 'PPSA00003']);
|
|
assert.equal(result[0].regional_variants.find(item => item.titleId === 'PPSA00003').source, 'library');
|
|
assert.equal(result[0].platform, 'ps5');
|
|
assert.equal(result.length, 2);
|
|
});
|
|
|
|
test('platform classification separates PS4, PS5 and future unknown title IDs', () => {
|
|
assert.equal(platformForGame({ game_id: 'CUSA03041' }), 'ps4');
|
|
assert.equal(platformForGame({ game_id: 'PPSA00001' }), 'ps5');
|
|
assert.equal(platformForGame({ content_id: 'EP9000-PPSA12345_00-EXAMPLE000000000' }), 'ps5');
|
|
assert.equal(platformForGame({ game_id: 'HOME00001' }), 'unknown');
|
|
});
|