UNPKG

tmdbrjs

Version:

A TypeScript wrapper for The Movie Database (TMDB) API

346 lines 11.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const validation_1 = require("../validation"); const zod_1 = require("zod"); // Common test data const testData = { valid: { genre: { id: 1, name: 'Action' }, productionCompany: { id: 1, logoPath: '/path/to/logo.png', name: 'Warner Bros', originCountry: 'US', }, productionCountry: { iso_3166_1: 'US', name: 'United States', }, spokenLanguage: { englishName: 'English', iso_639_1: 'en', name: 'English', }, movie: { adult: false, backdropPath: '/path/to/backdrop.jpg', belongsToCollection: null, budget: 1000000, genres: [{ id: 1, name: 'Action' }], homepage: 'https://example.com', id: 1, imdbId: 'tt1234567', originalLanguage: 'en', originalTitle: 'Original Title', overview: 'Movie overview', popularity: 100, posterPath: '/path/to/poster.jpg', productionCompanies: [ { id: 1, logoPath: '/path/to/logo.png', name: 'Warner Bros', originCountry: 'US', }, ], productionCountries: [ { iso_3166_1: 'US', name: 'United States', }, ], releaseDate: '2024-01-01', revenue: 2000000, runtime: 120, spokenLanguages: [ { englishName: 'English', iso_639_1: 'en', name: 'English', }, ], status: 'Released', tagline: 'Movie tagline', title: 'Movie Title', video: false, voteAverage: 7.5, voteCount: 1000, }, popularMovie: { adult: false, backdropPath: '/path/to/backdrop.jpg', genreIds: [1, 2, 3], id: 1, originalLanguage: 'en', originalTitle: 'Original Title', overview: 'Movie overview', popularity: 100, posterPath: '/path/to/poster.jpg', releaseDate: '2024-01-01', title: 'Movie Title', video: false, voteAverage: 7.5, voteCount: 1000, }, person: { adult: false, alsoKnownAs: ['John Doe'], biography: 'Actor biography', birthday: '1990-01-01', deathday: null, gender: 1, homepage: null, id: 1, imdbId: null, knownForDepartment: 'Acting', name: 'John Doe', placeOfBirth: 'New York', popularity: 100, profilePath: '/path/to/profile.jpg', }, popularPerson: { adult: false, gender: 1, id: 1, knownFor: [ { adult: false, backdropPath: '/path/to/backdrop.jpg', genreIds: [1, 2, 3], id: 1, originalLanguage: 'en', originalTitle: 'Original Title', overview: 'Movie overview', popularity: 100, posterPath: '/path/to/poster.jpg', releaseDate: '2024-01-01', title: 'Movie Title', video: false, voteAverage: 7.5, voteCount: 1000, }, ], knownForDepartment: 'Acting', name: 'John Doe', popularity: 100, profilePath: '/path/to/profile.jpg', }, }, invalid: { genre: { id: '1', name: 123 }, productionCompany: { id: '1', logoPath: 123, name: null, originCountry: undefined, }, productionCountry: { iso_3166_1: 123, name: null, }, spokenLanguage: { englishName: 123, iso_639_1: null, name: undefined, }, movie: { adult: 'false', backdropPath: 123, belongsToCollection: 123, budget: '1000000', genres: [{ id: '1', name: 123 }], homepage: 123, id: '1', imdbId: 123, originalLanguage: 123, originalTitle: null, overview: 123, popularity: '100', posterPath: 123, productionCompanies: [ { id: '1', logoPath: 123, name: null, originCountry: undefined, }, ], productionCountries: [ { iso_3166_1: 123, name: null, }, ], releaseDate: 123, revenue: '2000000', runtime: '120', spokenLanguages: [ { englishName: 123, iso_639_1: null, name: undefined, }, ], status: null, tagline: 123, title: null, video: 'false', voteAverage: '7.5', voteCount: '1000', }, popularMovie: { adult: 'false', backdropPath: 123, genreIds: ['1', '2', '3'], id: '1', originalLanguage: 123, originalTitle: null, overview: 123, popularity: '100', posterPath: 123, releaseDate: 123, title: null, video: 'false', voteAverage: '7.5', voteCount: '1000', }, person: { adult: 'false', alsoKnownAs: [123], biography: null, birthday: 123, deathday: 123, gender: '1', homepage: 123, id: '1', imdbId: 123, knownForDepartment: 123, name: null, placeOfBirth: 123, popularity: '100', profilePath: 123, }, popularPerson: { adult: 'false', gender: '1', id: '1', knownFor: [ { adult: 'false', backdropPath: 123, genreIds: ['1', '2', '3'], id: '1', originalLanguage: 123, originalTitle: null, overview: 123, popularity: '100', posterPath: 123, releaseDate: 123, title: null, video: 'false', voteAverage: '7.5', voteCount: '1000', }, ], knownForDepartment: 123, name: null, popularity: '100', profilePath: 123, }, }, }; // Helper function to test schema validation const testSchemaValidation = (schema, validData, invalidData) => { (0, vitest_1.it)('should validate valid data', () => { const result = schema.safeParse(validData); (0, vitest_1.expect)(result.success).toBe(true); }); (0, vitest_1.it)('should reject invalid data', () => { const result = schema.safeParse(invalidData); (0, vitest_1.expect)(result.success).toBe(false); }); }; (0, vitest_1.describe)('Validation Utils', () => { (0, vitest_1.describe)('GenreSchema', () => { testSchemaValidation(validation_1.GenreSchema, testData.valid.genre, testData.invalid.genre); }); (0, vitest_1.describe)('ProductionCompanySchema', () => { testSchemaValidation(validation_1.ProductionCompanySchema, testData.valid.productionCompany, testData.invalid.productionCompany); }); (0, vitest_1.describe)('ProductionCountrySchema', () => { testSchemaValidation(validation_1.ProductionCountrySchema, testData.valid.productionCountry, testData.invalid.productionCountry); }); (0, vitest_1.describe)('SpokenLanguageSchema', () => { testSchemaValidation(validation_1.SpokenLanguageSchema, testData.valid.spokenLanguage, testData.invalid.spokenLanguage); }); (0, vitest_1.describe)('MovieSchema', () => { testSchemaValidation(validation_1.MovieSchema, testData.valid.movie, testData.invalid.movie); }); (0, vitest_1.describe)('PersonSchema', () => { testSchemaValidation(validation_1.PersonSchema, testData.valid.person, testData.invalid.person); }); (0, vitest_1.describe)('PopularMoviesSchema', () => { const validResponse = { page: 1, results: [testData.valid.popularMovie], totalPages: 10, totalResults: 100, }; const invalidResponse = { page: '1', results: [testData.invalid.popularMovie], totalPages: '10', totalResults: '100', }; (0, vitest_1.it)('should validate valid paginated response', () => { const result = validation_1.PopularMoviesSchema.safeParse(validResponse); (0, vitest_1.expect)(result.success).toBe(true); }); (0, vitest_1.it)('should reject invalid paginated response', () => { const result = validation_1.PopularMoviesSchema.safeParse(invalidResponse); (0, vitest_1.expect)(result.success).toBe(false); }); }); (0, vitest_1.describe)('PopularPeopleSchema', () => { const validResponse = { page: 1, results: [testData.valid.popularPerson], totalPages: 10, totalResults: 100, }; const invalidResponse = { page: '1', results: [testData.invalid.popularPerson], totalPages: '10', totalResults: '100', }; (0, vitest_1.it)('should validate valid paginated response', () => { const result = validation_1.PopularPeopleSchema.safeParse(validResponse); (0, vitest_1.expect)(result.success).toBe(true); }); (0, vitest_1.it)('should reject invalid paginated response', () => { const result = validation_1.PopularPeopleSchema.safeParse(invalidResponse); (0, vitest_1.expect)(result.success).toBe(false); }); }); (0, vitest_1.describe)('validateResponse', () => { const TestSchema = zod_1.z.object({ id: zod_1.z.number(), name: zod_1.z.string(), }); (0, vitest_1.it)('should validate valid data', () => { const validData = { id: 1, name: 'test' }; (0, vitest_1.expect)(() => (0, validation_1.validateResponse)(TestSchema, validData)).not.toThrow(); }); (0, vitest_1.it)('should throw error for invalid data', () => { const invalidData = { id: '1', name: 123 }; (0, vitest_1.expect)(() => (0, validation_1.validateResponse)(TestSchema, invalidData)).toThrow(); }); (0, vitest_1.it)('should handle non-Zod errors', () => { const invalidData = { id: '1', name: 123 }; (0, vitest_1.expect)(() => (0, validation_1.validateResponse)(TestSchema, invalidData)).toThrow(); }); }); }); //# sourceMappingURL=validation.spec.js.map