- Add double-click handler to make file names editable in UI - Remove duplicate IPC handler for rename-file in renderer.js - Fix checkEpisodeCountMatch to properly validate sequential episodes - Fix begin-mapping to handle both season folder and show folder cases - Improve open-file-in-player handler to properly log results
134 lines
5.5 KiB
JavaScript
134 lines
5.5 KiB
JavaScript
// Test TheTVDB API integration and search functionality
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert');
|
|
|
|
// Test API authentication flow
|
|
test('TVDB API - should have login endpoint', () => {
|
|
const mainJs = require('fs').readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('login'), 'Login endpoint should be defined');
|
|
assert.ok(mainJs.includes('api4.thetvdb.com'), 'Should use TVDB v4 API');
|
|
});
|
|
|
|
test('TVDB API - should use bearer token authentication', () => {
|
|
const mainJs = require('fs').readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('Bearer'), 'Bearer token authentication should be used');
|
|
assert.ok(mainJs.includes('Authorization'), 'Authorization header should be set');
|
|
});
|
|
|
|
test('TVDB API - should cache authentication token', () => {
|
|
const mainJs = require('fs').readFileSync('./main.js', 'utf8');
|
|
|
|
// Verify token is obtained from login response
|
|
assert.ok(mainJs.includes('token'), 'Token should be obtained from login');
|
|
assert.ok(mainJs.includes('loginResponse.data.data.token'), 'Token extraction should be implemented');
|
|
});
|
|
|
|
// Test search functionality
|
|
test('TVDB API search - should have search endpoint', () => {
|
|
const mainJs = require('fs').readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('/search'), 'Search endpoint should be defined');
|
|
assert.ok(mainJs.includes('query'), 'Query parameter should be supported');
|
|
});
|
|
|
|
test('TVDB API search - should return show results', () => {
|
|
const mainJs = require('fs').readFileSync('./main.js', 'utf8');
|
|
|
|
// Verify result mapping
|
|
assert.ok(mainJs.includes('seriesName') || mainJs.includes('name'), 'Show name should be in results');
|
|
assert.ok(mainJs.includes('id'), 'Show ID should be in results');
|
|
assert.ok(mainJs.includes('firstAired') || mainJs.includes('first_air_time'), 'Air date should be in results');
|
|
});
|
|
|
|
test('TVDB API search - should handle multiple result types', () => {
|
|
const mainJs = require('fs').readFileSync('./main.js', 'utf8');
|
|
|
|
// Verify it handles both series and movies
|
|
assert.ok(mainJs.includes('series') || mainJs.includes('movie'), 'Should handle series and movies');
|
|
});
|
|
|
|
// Test show details functionality
|
|
test('TVDB show details - should have series endpoint', () => {
|
|
const mainJs = require('fs').readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('/series/'), 'Series endpoint should be defined');
|
|
assert.ok(mainJs.includes('extended'), 'Extended details endpoint should be used');
|
|
});
|
|
|
|
test('TVDB show details - should return season information', () => {
|
|
const mainJs = require('fs').readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('seasons'), 'Seasons should be in show details');
|
|
assert.ok(mainJs.includes('season.number'), 'Season number should be extracted');
|
|
});
|
|
|
|
test('TVDB show details - should handle both ID formats', () => {
|
|
const mainJs = require('fs').readFileSync('./main.js', 'utf8');
|
|
|
|
// Verify it handles both 'series-XXXXX' and 'XXXXX' formats
|
|
assert.ok(mainJs.includes('series-'), 'Should handle series-XXXXX format');
|
|
assert.ok(mainJs.includes('split'), 'Should parse ID formats');
|
|
});
|
|
|
|
// Test season episodes functionality
|
|
test('TVDB season episodes - should have episodes endpoint', () => {
|
|
const mainJs = require('fs').readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('/episodes'), 'Episodes endpoint should be defined');
|
|
});
|
|
|
|
test('TVDB season episodes - should filter by season number', () => {
|
|
const mainJs = require('fs').readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('seasonNumber'), 'Should filter by season number');
|
|
assert.ok(mainJs.includes('episode.number'), 'Should extract episode number');
|
|
});
|
|
|
|
test('TVDB season episodes - should have fallback endpoint', () => {
|
|
const mainJs = require('fs').readFileSync('./main.js', 'utf8');
|
|
|
|
// Verify fallback mechanism exists
|
|
assert.ok(mainJs.includes('fallback'), 'Fallback mechanism should be implemented');
|
|
});
|
|
|
|
// Test begin-mapping functionality
|
|
test('Begin mapping - should rename files with season and episode', () => {
|
|
const mainJs = require('fs').readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('S'), 'Season prefix should be S');
|
|
assert.ok(mainJs.includes('E'), 'Episode prefix should be E');
|
|
assert.ok(mainJs.includes('padStart'), 'Should pad numbers with zeros');
|
|
});
|
|
|
|
test('Begin mapping - should handle episode ranges', () => {
|
|
const mainJs = require('fs').readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('episodeStart') && mainJs.includes('episodeEnd'), 'Should handle episode ranges');
|
|
assert.ok(mainJs.includes('-E'), 'Range format should include -E');
|
|
});
|
|
|
|
test('Begin mapping - should rename show folder with TVDB ID', () => {
|
|
const mainJs = require('fs').readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('tvdbid'), 'TVDB ID should be in folder name');
|
|
assert.ok(mainJs.includes('[tvdbid-'), 'TVDB ID should be in brackets');
|
|
});
|
|
|
|
// Test error handling
|
|
test('Error handling - should catch API errors', () => {
|
|
const mainJs = require('fs').readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('catch'), 'Catch blocks should be implemented');
|
|
assert.ok(mainJs.includes('error.message'), 'Error messages should be returned');
|
|
});
|
|
|
|
test('Error handling - should validate API key', () => {
|
|
const mainJs = require('fs').readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('TVDB_API_KEY'), 'API key should be validated');
|
|
assert.ok(mainJs.includes('environment variables'), 'Should check environment variables');
|
|
});
|
|
|
|
console.log('\n✅ All TheTVDB API tests passed!'); |