UNPKG

tmdbrjs

Version:

A TypeScript wrapper for The Movie Database (TMDB) API

80 lines 3.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("../../index"); const vitest_1 = require("vitest"); (0, vitest_1.describe)('People', () => { let tmdb; (0, vitest_1.beforeAll)(() => { tmdb = new index_1.Client({ apiKey: '123' }); }); (0, vitest_1.beforeEach)(() => { vitest_1.vi.restoreAllMocks(); }); (0, vitest_1.describe)('getById', () => { (0, vitest_1.it)('should return a person object', async () => { const personId = '123'; const response = { id: personId, name: 'John Doe', birthday: '1990-01-01', known_for_department: 'Acting', }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.people.getById(personId); (0, vitest_1.expect)(result).toEqual(response); }); (0, vitest_1.it)('should append response with options', async () => { const personId = '123'; const options = { include: ['movieCredits'], }; const response = { id: personId, name: 'John Doe', movieCredits: { cast: [ { id: 1, title: 'Movie 1', }, { id: 2, title: 'Movie 2', }, ], }, }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.people.getById(personId, options); (0, vitest_1.expect)(result).toEqual(response); // Verify that the URL was constructed correctly with snake_case (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringContaining('append_to_response=movie_credits')); }); (0, vitest_1.it)('should convert multiple camelCase append options to snake_case', async () => { const personId = '123'; const options = { include: ['movieCredits', 'tvCredits', 'combinedCredits', 'images'], }; const response = { id: personId, name: 'John Doe', movieCredits: { cast: [] }, tvCredits: { cast: [] }, combinedCredits: { cast: [] }, images: { profiles: [] }, }; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockResolvedValue(response); const result = await tmdb.people.getById(personId, options); (0, vitest_1.expect)(result).toEqual(response); // Verify that the URL was constructed correctly with snake_case // URL encoding converts commas to %2C (0, vitest_1.expect)(tmdb.apiClient.get).toHaveBeenCalledWith(vitest_1.expect.stringMatching(/append_to_response=movie_credits(%2C|,)tv_credits(%2C|,)combined_credits(%2C|,)images/)); }); (0, vitest_1.it)('should throw an error if API call fails', async () => { const personId = '123'; vitest_1.vi.spyOn(tmdb.apiClient, 'get').mockRejectedValue(new Error('API error')); await (0, vitest_1.expect)(tmdb.people.getById(personId)).rejects.toThrow('API error'); }); }); }); //# sourceMappingURL=people.spec.js.map