@lorenzopant/tmdb 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { ApiClient } from "../client";
2
2
  import { MovieResultItem } from "../types/movies";
3
- import { PaginatedResponse } from "../types/params";
3
+ import { PaginatedResponse, SearchMoviesParams } from "../types/params";
4
4
  export declare const SEARCH_ENDPOINTS: {
5
5
  MOVIE: string;
6
6
  };
@@ -21,5 +21,5 @@ export declare class SearchAPI {
21
21
  * @param year Year
22
22
  * @reference https://developer.themoviedb.org/reference/search-movie
23
23
  */
24
- movies(query: string, include_adult?: boolean, language?: string, page?: number, primary_release_year?: string, region?: string, year?: string): Promise<PaginatedResponse<MovieResultItem>>;
24
+ movies(params: SearchMoviesParams): Promise<PaginatedResponse<MovieResultItem>>;
25
25
  }
@@ -20,16 +20,7 @@ export class SearchAPI {
20
20
  * @param year Year
21
21
  * @reference https://developer.themoviedb.org/reference/search-movie
22
22
  */
23
- async movies(query, include_adult = false, language = "en-US", page = 1, primary_release_year, region, year) {
24
- const params = {
25
- query,
26
- include_adult,
27
- language,
28
- page,
29
- primary_release_year,
30
- year,
31
- region,
32
- };
23
+ async movies(params) {
33
24
  const endpoint = `${SEARCH_ENDPOINTS.MOVIE}`;
34
25
  return this.client.request(endpoint, params);
35
26
  }
@@ -0,0 +1,32 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { TMDB } from "../../tmdb";
3
+ const token = process.env.TMDB_ACCESS_TOKEN;
4
+ if (!token)
5
+ throw new Error("TMDB_ACCESS_TOKEN is not set, plaase set it in your enviroment variables.");
6
+ const tmdb = new TMDB(token);
7
+ describe("Movie List (integration)", () => {
8
+ it("(NOW PLAYING) should get now playing movies", async () => {
9
+ const now_playing = await tmdb.movie_lists.now_playing();
10
+ expect(now_playing.page).toBe(1);
11
+ expect(now_playing.total_results).toBeGreaterThan(0);
12
+ expect(now_playing.results.length).toBeGreaterThan(0);
13
+ });
14
+ it("(POPULAR) should get popular movies", async () => {
15
+ const popular = await tmdb.movie_lists.popular();
16
+ expect(popular.page).toBe(1);
17
+ expect(popular.total_results).toBeGreaterThan(0);
18
+ expect(popular.results.length).toBeGreaterThan(0);
19
+ });
20
+ it("(TOP RATED) should get top rated movies", async () => {
21
+ const top_rated = await tmdb.movie_lists.top_rated();
22
+ expect(top_rated.page).toBe(1);
23
+ expect(top_rated.total_results).toBeGreaterThan(0);
24
+ expect(top_rated.results.length).toBeGreaterThan(0);
25
+ });
26
+ it("(UPCOMING) should get upcoming movies", async () => {
27
+ const upcoming = await tmdb.movie_lists.upcoming();
28
+ expect(upcoming.page).toBe(1);
29
+ expect(upcoming.total_results).toBeGreaterThan(0);
30
+ expect(upcoming.results.length).toBeGreaterThan(0);
31
+ });
32
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,145 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { TMDB } from "../../tmdb";
3
+ import { TMDBError } from "../../errors/tmdb";
4
+ import { ISO3166Country } from "../../types/utility";
5
+ const token = process.env.TMDB_ACCESS_TOKEN;
6
+ if (!token)
7
+ throw new Error("TMDB_ACCESS_TOKEN is not set, plaase set it in your enviroment variables.");
8
+ const tmdb = new TMDB(token);
9
+ describe("Movies (integration)", () => {
10
+ it("(MOVIE DETAILS) should get movie details", async () => {
11
+ const movie_id = 550; // Fight Club
12
+ const movie = await tmdb.movies.details(movie_id);
13
+ expect(movie).toBeDefined();
14
+ expect(movie.id).toBe(movie_id);
15
+ expect(movie.title).toBe("Fight Club");
16
+ });
17
+ it("(MOVIE DETAILS) should throw an error for not found movie ID", async () => {
18
+ const invalid_movie_id = -1; // Invalid movie ID
19
+ // ** Can't test the specific error because API is not returning the same error for the same request
20
+ try {
21
+ await tmdb.movies.details(invalid_movie_id);
22
+ throw new Error("Expected TMDBError was not thrown");
23
+ }
24
+ catch (error) {
25
+ expect(error).toBeInstanceOf(TMDBError);
26
+ }
27
+ });
28
+ it("(MOVIE ALTERNATIVE TITLES) should get movie alternative titles", async () => {
29
+ const movie_id = 550; // Fight Club
30
+ const movie_titles = await tmdb.movies.alternative_titles(movie_id);
31
+ expect(movie_titles).toBeDefined();
32
+ expect(movie_titles.id).toBe(movie_id);
33
+ expect(movie_titles.titles.length).toBeGreaterThan(0);
34
+ });
35
+ it("(MOVIE CREDITS) should get movie credits", async () => {
36
+ const movie_id = 550; // Fight Club
37
+ const credits = await tmdb.movies.credits(movie_id);
38
+ expect(credits).toBeDefined();
39
+ expect(credits.id).toBe(movie_id);
40
+ expect(credits.cast.length).toBeGreaterThan(0);
41
+ expect(credits.crew.length).toBeGreaterThan(0);
42
+ expect(credits.cast[0].name).toBe("Edward Norton");
43
+ });
44
+ it("(MOVIE EXTERNAL IDS) should get movie external IDs", async () => {
45
+ const movie_id = 550; // Fight Club
46
+ const external_ids = await tmdb.movies.external_ids(movie_id);
47
+ expect(external_ids).toBeDefined();
48
+ expect(external_ids.id).toBe(movie_id);
49
+ expect(external_ids.imdb_id).toBe("tt0137523");
50
+ });
51
+ it("(MOVIE KEYWORDS) should get movie keywords", async () => {
52
+ const movie_id = 550; // Fight Club
53
+ const keywords = await tmdb.movies.keywords(movie_id);
54
+ expect(keywords).toBeDefined();
55
+ expect(keywords.id).toBe(movie_id);
56
+ expect(keywords.keywords.length).toBeGreaterThan(0);
57
+ });
58
+ it("(MOVIE CHANGES) should get movie changes", async () => {
59
+ const movie_id = 550; // Fight Club
60
+ const start_date = "2024-12-20";
61
+ const end_date = "2024-12-24";
62
+ const changes = await tmdb.movies.changes(movie_id, 1, start_date, end_date);
63
+ expect(changes).toBeDefined();
64
+ expect(changes.changes).toBeDefined();
65
+ expect(changes.changes[0].key).toBe("images");
66
+ expect(changes.changes[0].items.length).toBeGreaterThan(0);
67
+ });
68
+ it("(MOVIE IMAGES) should get movie images", async () => {
69
+ const movie_id = 550; // Fight Club
70
+ const images = await tmdb.movies.images(movie_id);
71
+ expect(images).toBeDefined();
72
+ expect(images.id).toBe(movie_id);
73
+ expect(images.backdrops.length).toBeGreaterThan(0);
74
+ expect(images.posters.length).toBeGreaterThan(0);
75
+ });
76
+ it("(MOVIE IMAGES) should get movie images for a specific language", async () => {
77
+ const movie_id = 550; // Fight Club
78
+ const images = await tmdb.movies.images(movie_id, "en");
79
+ expect(images).toBeDefined();
80
+ expect(images.id).toBe(movie_id);
81
+ expect(images.backdrops.length).toBeGreaterThan(0);
82
+ expect(images.posters.length).toBeGreaterThan(0);
83
+ });
84
+ it("(MOVIE LATEST) should get the latest movie details", async () => {
85
+ const latestMovie = await tmdb.movies.latest();
86
+ expect(latestMovie).toBeDefined();
87
+ expect(latestMovie.id).toBeDefined();
88
+ expect(latestMovie.title).toBeDefined();
89
+ });
90
+ it("(MOVIE RECOMMENDATIONS) should get movie recommendations", async () => {
91
+ const movie_id = 550; // Fight Club
92
+ const recommendations = await tmdb.movies.recommendations(movie_id);
93
+ expect(recommendations).toBeDefined();
94
+ expect(recommendations.results.length).toBeGreaterThan(0);
95
+ expect(recommendations.results[0].id).toBeDefined();
96
+ expect(recommendations.page).toBe(1);
97
+ expect(recommendations.total_results).toBeGreaterThan(0);
98
+ expect(recommendations.total_pages).toBeGreaterThan(0);
99
+ });
100
+ it("(MOVIE RELEASE DATES) should get movie release dates", async () => {
101
+ const movie_id = 550; // Fight Club
102
+ const release_dates = await tmdb.movies.release_dates(movie_id);
103
+ expect(release_dates).toBeDefined();
104
+ expect(release_dates.id).toBe(movie_id);
105
+ expect(release_dates.results.length).toBeGreaterThan(0);
106
+ expect(release_dates.results[0].iso_3166_1).toBeDefined();
107
+ expect(release_dates.results[0].release_dates.length).toBeGreaterThan(0);
108
+ });
109
+ it("(MOVIE SIMILAR) should get similar movies", async () => {
110
+ const movie_id = 550;
111
+ const similar = await tmdb.movies.similar(movie_id);
112
+ expect(similar).toBeDefined();
113
+ expect(similar.results.length).toBeGreaterThan(0);
114
+ expect(similar.results[0].id).toBeDefined();
115
+ expect(similar.page).toBe(1);
116
+ expect(similar.total_results).toBeGreaterThan(0);
117
+ expect(similar.total_pages).toBeGreaterThan(0);
118
+ });
119
+ it("(MOVIE TRANSLATIONS) should get translations for a movie", async () => {
120
+ const movie_id = 550;
121
+ const translations = await tmdb.movies.translations(movie_id);
122
+ expect(translations).toBeDefined();
123
+ expect(translations.id).toBe(movie_id);
124
+ expect(translations.translations).toBeDefined();
125
+ expect(translations.translations.length).toBeGreaterThan(0);
126
+ expect(translations.translations[0].data).toBeDefined();
127
+ });
128
+ it("(MOVIE VIDEOS) should get videos for a movie", async () => {
129
+ const movie_id = 550;
130
+ const videos = await tmdb.movies.videos(movie_id);
131
+ expect(videos).toBeDefined();
132
+ expect(videos.id).toBe(movie_id);
133
+ expect(videos.results).toBeDefined();
134
+ expect(videos.results.length).toBeGreaterThan(0);
135
+ expect(videos.results[0].id).toBeDefined();
136
+ });
137
+ it("(MOVIE WATCH PROVIDERS) should get watch providers for a movie", async () => {
138
+ const movie_id = 550;
139
+ const watch_providers = await tmdb.movies.watch_providers(movie_id);
140
+ expect(watch_providers).toBeDefined();
141
+ expect(watch_providers.id).toBe(movie_id);
142
+ expect(watch_providers.results).toBeDefined();
143
+ expect(watch_providers.results[ISO3166Country.US]).toBeDefined();
144
+ });
145
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
+ import { ApiClient } from "../../client";
3
+ import { MoviesAPI } from "../../endpoints/movies";
4
+ import { TMDB } from "../../tmdb";
5
+ let tmdb = new TMDB("valid_access_token");
6
+ describe("MoviesAPI", () => {
7
+ let clientMock;
8
+ let moviesAPI;
9
+ beforeEach(() => {
10
+ clientMock = new ApiClient("valid_access_token");
11
+ clientMock.request = vi.fn();
12
+ moviesAPI = new MoviesAPI(clientMock);
13
+ });
14
+ it("should call client.request with the correct parameters", async () => {
15
+ const movie_id = 550;
16
+ const append_to_response = ["credits", "images"];
17
+ const language = "en-US";
18
+ await moviesAPI.details(movie_id, append_to_response, language);
19
+ expect(clientMock.request).toHaveBeenCalledOnce();
20
+ expect(clientMock.request).toHaveBeenCalledWith("/movie/550", {
21
+ append_to_response,
22
+ language,
23
+ });
24
+ });
25
+ it("should work correctly without optional parameters", async () => {
26
+ const movie_id = 550;
27
+ await moviesAPI.details(movie_id);
28
+ expect(clientMock.request).toHaveBeenCalledOnce();
29
+ expect(clientMock.request).toHaveBeenCalledWith("/movie/550", {
30
+ append_to_response: undefined,
31
+ language: undefined,
32
+ });
33
+ });
34
+ it("should return the result from client.request", async () => {
35
+ const fakeResponse = { id: 550, title: "Fight Club" };
36
+ clientMock.request.mockResolvedValue(fakeResponse);
37
+ const result = await moviesAPI.details(550);
38
+ expect(result).toEqual(fakeResponse);
39
+ });
40
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { TMDB } from "../../tmdb";
3
+ const token = process.env.TMDB_ACCESS_TOKEN;
4
+ if (!token)
5
+ throw new Error("TMDB_ACCESS_TOKEN is not set, plaase set it in your enviroment variables.");
6
+ const tmdb = new TMDB(token);
7
+ describe("Search (integration)", () => {
8
+ it("(SEARCH MOVIE) should search for a particular movie", async () => {
9
+ const movies = await tmdb.search.movies({ query: "Fight Club" });
10
+ expect(movies.page).toBe(1);
11
+ expect(movies.total_results).toBeGreaterThan(0);
12
+ expect(movies.results.length).toBeGreaterThan(0);
13
+ expect(movies.results[0].title).toBe("Fight Club");
14
+ });
15
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { TMDB } from "../tmdb";
3
+ import { Errors } from "../errors/messages";
4
+ describe("TMDB API Client", () => {
5
+ it("should throw an error if no access token is provided", () => {
6
+ expect(() => new TMDB("")).toThrowError(Errors.NO_ACCESS_TOKEN);
7
+ });
8
+ it("should create an instance of TMDB with a valid access token", () => {
9
+ const tmdb = new TMDB("valid_access_token");
10
+ expect(tmdb).toBeInstanceOf(TMDB);
11
+ });
12
+ });
@@ -4,3 +4,12 @@ export type PaginatedResponse<T> = {
4
4
  total_results: number;
5
5
  results: T[];
6
6
  };
7
+ export type SearchMoviesParams = {
8
+ query: string;
9
+ include_adult?: boolean;
10
+ language?: string;
11
+ page?: number;
12
+ primary_release_year?: string;
13
+ region?: string;
14
+ year?: string;
15
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lorenzopant/tmdb",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "A completely type-safe The Movie Database (TMDB) API wrapper for typescript applications.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,14 +8,6 @@
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/lorenzopantano/tmdb-api-ts"
10
10
  },
11
- "scripts": {
12
- "build": "tsc",
13
- "build:watch": "tsc --watch",
14
- "test": "vitest",
15
- "test:ui": "vitest --ui",
16
- "test:coverage": "vitest --coverage",
17
- "prepare": "npm run build"
18
- },
19
11
  "author": "Lorenzo Pantano",
20
12
  "license": "MIT",
21
13
  "keywords": [
@@ -32,6 +24,16 @@
32
24
  "release-it": "^19.0.3",
33
25
  "release-it-pnpm": "^4.6.6",
34
26
  "typescript": "^5.8.3",
35
- "vitest": "^3.1.2"
27
+ "vitest": "^3.2.4"
28
+ },
29
+ "dependencies": {
30
+ "vite": "^7.0.0"
31
+ },
32
+ "scripts": {
33
+ "build": "tsc",
34
+ "build:watch": "tsc --watch",
35
+ "test": "vitest",
36
+ "test:ui": "vitest --ui",
37
+ "test:coverage": "vitest --coverage"
36
38
  }
37
- }
39
+ }