UNPKG

tmdbrjs

Version:

A TypeScript wrapper for The Movie Database (TMDB) API

615 lines 26.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const __1 = require("../.."); (0, vitest_1.describe)('Tv', () => { let tmdb; (0, vitest_1.beforeAll)(() => { tmdb = new __1.Client({ apiKey: '123' }); }); (0, vitest_1.describe)('getPopular', () => { (0, vitest_1.it)('should return a list of popular TV shows', async () => { const response = { results: [ { id: '1', name: 'TV Show 1', }, { id: '2', name: 'TV Show 2', }, ], }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getPopular(); (0, vitest_1.expect)(result).toEqual(response); }); (0, vitest_1.it)('should support pagination', async () => { const response = { page: 2, results: [ { id: '1', name: 'TV Show 1', }, ], }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); await tmdb.tv.getPopular(2); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining('page=2')); }); }); (0, vitest_1.describe)('getTopRated', () => { (0, vitest_1.it)('should return a list of top rated TV shows', async () => { const response = { results: [ { id: '1', name: 'TV Show 1', }, { id: '2', name: 'TV Show 2', }, ], }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getTopRated(); (0, vitest_1.expect)(result).toEqual(response); }); }); (0, vitest_1.describe)('getAiringToday', () => { (0, vitest_1.it)('should return a list of TV shows airing today', async () => { const response = { results: [ { id: '1', name: 'TV Show 1', }, ], }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getAiringToday(); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining('tv/airing_today')); }); }); (0, vitest_1.describe)('getOnTheAir', () => { (0, vitest_1.it)('should return a list of TV shows on the air', async () => { const response = { results: [ { id: '1', name: 'TV Show 1', }, ], }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getOnTheAir(); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining('tv/on_the_air')); }); }); (0, vitest_1.describe)('getLatest', () => { (0, vitest_1.it)('should return the latest TV show', async () => { const response = { id: '1', name: 'Latest TV Show', }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getLatest(); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith('tv/latest'); }); }); (0, vitest_1.describe)('getById', () => { (0, vitest_1.it)('should return a TV show object', async () => { const tvId = '123'; const response = { id: tvId, name: 'TV Show 1', firstAirDate: '2021-01-01', }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getById(tvId); (0, vitest_1.expect)(result).toEqual(response); }); (0, vitest_1.it)('should append response with options', async () => { const tvId = '123'; const options = { include: ['credits'], }; const response = { id: tvId, name: 'TV Show 1', credits: { cast: [ { id: 1, name: 'Actor 1', }, { id: 2, name: 'Actor 2', }, ], }, }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getById(tvId, options); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining('append_to_response=credits')); }); (0, vitest_1.it)('should convert TV-specific camelCase append options to snake_case', async () => { const tvId = '123'; const options = { include: ['aggregateCredits', 'contentRatings', 'externalIds'], }; const response = { id: tvId, name: 'TV Show 1', aggregateCredits: { cast: [] }, contentRatings: { results: [] }, externalIds: { imdbId: 'tt123' }, }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getById(tvId, options); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringMatching(/append_to_response=aggregate_credits(%2C|,)content_ratings(%2C|,)external_ids/)); }); (0, vitest_1.it)('should throw an error if API call fails', async () => { const tvId = '123'; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockRejectedValue(new Error('API error')); await (0, vitest_1.expect)(tmdb.tv.getById(tvId)).rejects.toThrow('Failed to fetch tv/{id}: API error'); }); }); (0, vitest_1.describe)('getCredits', () => { (0, vitest_1.it)('should return TV show credits', async () => { const tvId = '123'; const response = { cast: [ { id: 1, name: 'Actor 1', }, { id: 2, name: 'Actor 2', }, ], }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getCredits(tvId); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining(`tv/${tvId}/credits`)); }); }); (0, vitest_1.describe)('getAggregateCredits', () => { (0, vitest_1.it)('should return TV show aggregate credits', async () => { const tvId = '123'; const response = { cast: [ { id: 1, name: 'Actor 1', roles: [ { creditId: 'credit1', character: 'Character 1', episodeCount: 10, }, ], }, ], }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getAggregateCredits(tvId); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining(`tv/${tvId}/aggregate_credits`)); }); }); (0, vitest_1.describe)('getExternalIds', () => { (0, vitest_1.it)('should return TV show external IDs', async () => { const tvId = '123'; const response = { imdbId: 'tt123456', tvdbId: 789, facebookId: 'tvshow', }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getExternalIds(tvId); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining(`tv/${tvId}/external_ids`)); }); }); (0, vitest_1.describe)('getContentRatings', () => { (0, vitest_1.it)('should return TV show content ratings', async () => { const tvId = '123'; const response = { results: [ { iso31661: 'US', rating: 'TV-14', }, ], }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getContentRatings(tvId); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining(`tv/${tvId}/content_ratings`)); }); }); (0, vitest_1.describe)('getWatchProviders', () => { (0, vitest_1.it)('should return TV show watch providers', async () => { const tvId = '123'; const response = { id: 123, results: { US: { link: 'https://www.themoviedb.org/tv/123/watch?locale=US', flatrate: [ { logoPath: '/logo.jpg', providerId: 8, providerName: 'Netflix', displayPriority: 0, }, ], }, }, }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getWatchProviders(tvId); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining(`tv/${tvId}/watch/providers`)); }); }); (0, vitest_1.describe)('getImages', () => { (0, vitest_1.it)('should return TV show images', async () => { const tvId = '123'; const response = { id: 123, backdrops: [ { aspectRatio: 1.777, filePath: '/backdrop.jpg', height: 1080, iso6391: null, voteAverage: 7.5, voteCount: 100, width: 1920, }, ], posters: [ { aspectRatio: 0.666, filePath: '/poster.jpg', height: 1500, iso6391: null, voteAverage: 7.5, voteCount: 100, width: 1000, }, ], }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getImages(tvId); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining(`tv/${tvId}/images`)); }); }); (0, vitest_1.describe)('getVideos', () => { (0, vitest_1.it)('should return TV show videos', async () => { const tvId = '123'; const response = { id: 123, results: [ { id: 'video1', key: 'dQw4w9WgXcQ', name: 'Official Trailer', site: 'YouTube', size: 1080, type: 'Trailer', }, ], }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getVideos(tvId); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining(`tv/${tvId}/videos`)); }); }); (0, vitest_1.describe)('getReviews', () => { (0, vitest_1.it)('should return TV show reviews', async () => { const tvId = '123'; const response = { id: 123, page: 1, results: [ { id: 'review1', author: 'reviewer123', content: 'Great show!', createdAt: '2023-01-01T00:00:00.000Z', url: 'https://example.com/review', }, ], totalPages: 1, totalResults: 1, }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getReviews(tvId); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining(`tv/${tvId}/reviews`)); }); (0, vitest_1.it)('should support pagination for reviews', async () => { const tvId = '123'; const page = 2; const response = { id: 123, page, results: [] }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); await tmdb.tv.getReviews(tvId, page); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining('page=2')); }); }); (0, vitest_1.describe)('getSimilar', () => { (0, vitest_1.it)('should return similar TV shows', async () => { const tvId = '123'; const response = { page: 1, results: [ { id: 456, name: 'Similar Show', firstAirDate: '2023-01-01', }, ], totalPages: 1, totalResults: 1, }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getSimilar(tvId); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining(`tv/${tvId}/similar`)); }); (0, vitest_1.it)('should support pagination for similar shows', async () => { const tvId = '123'; const page = 2; const response = { page, results: [] }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); await tmdb.tv.getSimilar(tvId, page); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining('page=2')); }); }); (0, vitest_1.describe)('getRecommendations', () => { (0, vitest_1.it)('should return TV show recommendations', async () => { const tvId = '123'; const response = { page: 1, results: [ { id: 789, name: 'Recommended Show', firstAirDate: '2023-02-01', }, ], totalPages: 1, totalResults: 1, }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getRecommendations(tvId); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining(`tv/${tvId}/recommendations`)); }); (0, vitest_1.it)('should support pagination for recommendations', async () => { const tvId = '123'; const page = 3; const response = { page, results: [] }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); await tmdb.tv.getRecommendations(tvId, page); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining('page=3')); }); }); (0, vitest_1.describe)('getKeywords', () => { (0, vitest_1.it)('should return TV show keywords', async () => { const tvId = '123'; const response = { id: 123, results: [ { id: 1, name: 'comedy', }, { id: 2, name: 'family', }, ], }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getKeywords(tvId); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining(`tv/${tvId}/keywords`)); }); }); (0, vitest_1.describe)('getTranslations', () => { (0, vitest_1.it)('should return TV show translations', async () => { const tvId = '123'; const response = { id: 123, translations: [ { iso31661: 'FR', iso6391: 'fr', name: 'Français', englishName: 'French', data: { name: 'Nom en français', overview: 'Description en français', homepage: '', }, }, ], }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getTranslations(tvId); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining(`tv/${tvId}/translations`)); }); }); (0, vitest_1.describe)('getAlternativeTitles', () => { (0, vitest_1.it)('should return TV show alternative titles', async () => { const tvId = '123'; const response = { id: 123, titles: [ { iso31661: 'US', title: 'Alternative Title', type: 'original title', }, ], }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getAlternativeTitles(tvId); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining(`tv/${tvId}/alternative_titles`)); }); }); (0, vitest_1.describe)('getEpisodeGroups', () => { (0, vitest_1.it)('should return TV show episode groups', async () => { const tvId = '123'; const response = { id: 123, results: [ { id: 'group1', name: 'Season 1', description: 'First season episodes', episodeCount: 10, groupCount: 1, type: 1, }, ], }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getEpisodeGroups(tvId); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining(`tv/${tvId}/episode_groups`)); }); }); (0, vitest_1.describe)('getScreenedTheatrically', () => { (0, vitest_1.it)('should return TV show theatrical screenings', async () => { const tvId = '123'; const response = { id: 123, results: [ { id: 1, episodeNumber: 1, seasonNumber: 1, }, ], }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getScreenedTheatrically(tvId); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining(`tv/${tvId}/screened_theatrically`)); }); }); (0, vitest_1.describe)('getLists', () => { (0, vitest_1.it)('should return TV show lists', async () => { const tvId = '123'; const response = { id: 123, page: 1, results: [ { id: 'list1', name: 'Best TV Shows', description: 'A list of the best TV shows', favoriteCount: 100, itemCount: 50, iso6391: 'en', listType: 'tv', posterPath: '/poster.jpg', }, ], totalPages: 1, totalResults: 1, }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getLists(tvId); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining(`tv/${tvId}/lists`)); }); (0, vitest_1.it)('should support pagination for lists', async () => { const tvId = '123'; const page = 2; const response = { page, results: [] }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); await tmdb.tv.getLists(tvId, page); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining('page=2')); }); }); (0, vitest_1.describe)('getChanges', () => { (0, vitest_1.it)('should return TV show changes', async () => { const tvId = '123'; const response = { changes: [ { key: 'name', items: [ { id: 'change1', action: 'updated', time: '2023-01-01T00:00:00.000Z', originalValue: 'Old Name', value: 'New Name', }, ], }, ], }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getChanges(tvId); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining(`tv/${tvId}/changes`)); }); (0, vitest_1.it)('should support date range for changes', async () => { const tvId = '123'; const startDate = '2023-01-01'; const endDate = '2023-01-31'; const response = { changes: [] }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); await tmdb.tv.getChanges(tvId, startDate, endDate); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringMatching(/start_date=2023-01-01/)); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringMatching(/end_date=2023-01-31/)); }); (0, vitest_1.it)('should support pagination for changes', async () => { const tvId = '123'; const page = 2; const response = { changes: [] }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); await tmdb.tv.getChanges(tvId, undefined, undefined, page); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining('page=2')); }); }); (0, vitest_1.describe)('getAccountStates', () => { (0, vitest_1.it)('should return TV show account states', async () => { const tvId = '123'; const response = { id: 123, favorite: false, rated: false, watchlist: true, }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.tv.getAccountStates(tvId); (0, vitest_1.expect)(result).toEqual(response); (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining(`tv/${tvId}/account_states`)); }); }); }); //# sourceMappingURL=tv.spec.js.map