@lorenzopant/tmdb 0.0.2 → 0.0.4
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.
- package/dist/endpoints/movie_lists.d.ts +19 -13
- package/dist/endpoints/movie_lists.js +26 -25
- package/dist/endpoints/movies.d.ts +6 -4
- package/dist/endpoints/movies.js +12 -9
- package/dist/endpoints/search.d.ts +5 -3
- package/dist/endpoints/search.js +7 -12
- package/dist/tests/movie_list/movie_list.integration.test.d.ts +1 -0
- package/dist/tests/movie_list/movie_list.integration.test.js +32 -0
- package/dist/tests/movies/movies.integration.test.d.ts +1 -0
- package/dist/tests/movies/movies.integration.test.js +145 -0
- package/dist/tests/movies/movies.test.d.ts +1 -0
- package/dist/tests/movies/movies.test.js +42 -0
- package/dist/tests/search/search.integration.test.d.ts +1 -0
- package/dist/tests/search/search.integration.test.js +23 -0
- package/dist/tests/tmdb.test.d.ts +1 -0
- package/dist/tests/tmdb.test.js +12 -0
- package/dist/tmdb.d.ts +17 -1
- package/dist/tmdb.js +18 -4
- package/dist/types/countries.d.ts +6 -0
- package/dist/types/countries.js +1257 -0
- package/dist/types/lang.d.ts +6 -0
- package/dist/types/lang.js +937 -0
- package/dist/types/params.d.ts +25 -0
- package/dist/utils/params.d.ts +6 -0
- package/dist/utils/params.js +13 -0
- package/package.json +13 -11
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { ApiClient } from "../client";
|
|
2
2
|
import { MovieResultItem } from "../types/movies";
|
|
3
|
-
import { PaginatedResponse } from "../types/params";
|
|
3
|
+
import { MovieListParams, PaginatedResponse } from "../types/params";
|
|
4
|
+
import { TMDBOptions } from "../tmdb";
|
|
5
|
+
export declare enum MovieListEndpoints {
|
|
6
|
+
NOW_PLAYING = "/now_playing",
|
|
7
|
+
POPULAR = "/popular",
|
|
8
|
+
TOP_RATED = "/top_rated",
|
|
9
|
+
UPCOMING = "/upcoming"
|
|
10
|
+
}
|
|
4
11
|
export declare class MovieListsAPI {
|
|
5
12
|
private client;
|
|
6
|
-
|
|
13
|
+
private defaultOptions;
|
|
14
|
+
constructor(client: ApiClient, defaultOptions?: TMDBOptions);
|
|
7
15
|
/**
|
|
8
16
|
* Fetch Movie List Wrapper
|
|
9
17
|
* @param endpoint Endpoint to call
|
|
10
|
-
* @param
|
|
11
|
-
* @param page Page (Defaults to 1)
|
|
12
|
-
* @param region ISO-3166-1 code
|
|
18
|
+
* @param params Params for the request (language, page, region, etc)
|
|
13
19
|
* @returns Specific to endpoint (MovieListResult)
|
|
14
20
|
*/
|
|
15
21
|
private fetch_movie_list;
|
|
@@ -18,39 +24,39 @@ export declare class MovieListsAPI {
|
|
|
18
24
|
* GET - https://api.themoviedb.org/3/movie/now_playing
|
|
19
25
|
*
|
|
20
26
|
* Get a list of movies that are currently in theatres.
|
|
21
|
-
* @param language Language (Defaults to en-US)
|
|
27
|
+
* @param language Language (Defaults to en-US or TMDB default)
|
|
22
28
|
* @param page Page (Defaults to 1)
|
|
23
29
|
* @param region ISO-3166-1 code
|
|
24
30
|
*/
|
|
25
|
-
now_playing(
|
|
31
|
+
now_playing(params?: MovieListParams): Promise<PaginatedResponse<MovieResultItem>>;
|
|
26
32
|
/**
|
|
27
33
|
* Popular
|
|
28
34
|
* GET - https://api.themoviedb.org/3/movie/popular
|
|
29
35
|
*
|
|
30
36
|
* Get a list of movies ordered by popularity.
|
|
31
|
-
* @param language Language (Defaults to en-US)
|
|
37
|
+
* @param language Language (Defaults to en-US or TMDB default)
|
|
32
38
|
* @param page Page (Defaults to 1)
|
|
33
39
|
* @param region ISO-3166-1 code
|
|
34
40
|
*/
|
|
35
|
-
popular(
|
|
41
|
+
popular(params?: MovieListParams): Promise<PaginatedResponse<MovieResultItem>>;
|
|
36
42
|
/**
|
|
37
43
|
* Top Rated
|
|
38
44
|
* GET - https://api.themoviedb.org/3/movie/top_rated
|
|
39
45
|
*
|
|
40
46
|
* Get a list of movies ordered by rating.
|
|
41
|
-
* @param language Language (Defaults to en-US)
|
|
47
|
+
* @param language Language (Defaults to en-US or TMDB default)
|
|
42
48
|
* @param page Page (Defaults to 1)
|
|
43
49
|
* @param region ISO-3166-1 code
|
|
44
50
|
*/
|
|
45
|
-
top_rated(
|
|
51
|
+
top_rated(params?: MovieListParams): Promise<PaginatedResponse<MovieResultItem>>;
|
|
46
52
|
/**
|
|
47
53
|
* Upcoming
|
|
48
54
|
* GET - https://api.themoviedb.org/3/movie/upcoming
|
|
49
55
|
*
|
|
50
56
|
* Get a list of movies that are being released soon.
|
|
51
|
-
* @param language Language (Defaults to en-US)
|
|
57
|
+
* @param language Language (Defaults to en-US or TMDB default)
|
|
52
58
|
* @param page Page (Defaults to 1)
|
|
53
59
|
* @param region ISO-3166-1 code
|
|
54
60
|
*/
|
|
55
|
-
upcoming(
|
|
61
|
+
upcoming(params?: MovieListParams): Promise<PaginatedResponse<MovieResultItem>>;
|
|
56
62
|
}
|
|
@@ -1,73 +1,74 @@
|
|
|
1
1
|
import { MOVIE_ENDPOINTS } from "./movies";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
export var MovieListEndpoints;
|
|
3
|
+
(function (MovieListEndpoints) {
|
|
4
|
+
MovieListEndpoints["NOW_PLAYING"] = "/now_playing";
|
|
5
|
+
MovieListEndpoints["POPULAR"] = "/popular";
|
|
6
|
+
MovieListEndpoints["TOP_RATED"] = "/top_rated";
|
|
7
|
+
MovieListEndpoints["UPCOMING"] = "/upcoming";
|
|
8
|
+
})(MovieListEndpoints || (MovieListEndpoints = {}));
|
|
8
9
|
export class MovieListsAPI {
|
|
9
10
|
client;
|
|
10
|
-
|
|
11
|
+
defaultOptions;
|
|
12
|
+
constructor(client, defaultOptions = {}) {
|
|
11
13
|
this.client = client;
|
|
14
|
+
this.defaultOptions = defaultOptions;
|
|
12
15
|
}
|
|
13
16
|
/**
|
|
14
17
|
* Fetch Movie List Wrapper
|
|
15
18
|
* @param endpoint Endpoint to call
|
|
16
|
-
* @param
|
|
17
|
-
* @param page Page (Defaults to 1)
|
|
18
|
-
* @param region ISO-3166-1 code
|
|
19
|
+
* @param params Params for the request (language, page, region, etc)
|
|
19
20
|
* @returns Specific to endpoint (MovieListResult)
|
|
20
21
|
*/
|
|
21
|
-
fetch_movie_list(endpoint,
|
|
22
|
-
const
|
|
23
|
-
return this.client.request(MOVIE_ENDPOINTS.MOVIE + endpoint,
|
|
22
|
+
fetch_movie_list(endpoint, params = {}) {
|
|
23
|
+
const mergedParams = { ...this.defaultOptions, ...params };
|
|
24
|
+
return this.client.request(MOVIE_ENDPOINTS.MOVIE + endpoint, mergedParams);
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
27
|
* Now Playing
|
|
27
28
|
* GET - https://api.themoviedb.org/3/movie/now_playing
|
|
28
29
|
*
|
|
29
30
|
* Get a list of movies that are currently in theatres.
|
|
30
|
-
* @param language Language (Defaults to en-US)
|
|
31
|
+
* @param language Language (Defaults to en-US or TMDB default)
|
|
31
32
|
* @param page Page (Defaults to 1)
|
|
32
33
|
* @param region ISO-3166-1 code
|
|
33
34
|
*/
|
|
34
|
-
async now_playing(
|
|
35
|
-
return this.fetch_movie_list(
|
|
35
|
+
async now_playing(params = {}) {
|
|
36
|
+
return this.fetch_movie_list(MovieListEndpoints.NOW_PLAYING, params);
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
39
|
* Popular
|
|
39
40
|
* GET - https://api.themoviedb.org/3/movie/popular
|
|
40
41
|
*
|
|
41
42
|
* Get a list of movies ordered by popularity.
|
|
42
|
-
* @param language Language (Defaults to en-US)
|
|
43
|
+
* @param language Language (Defaults to en-US or TMDB default)
|
|
43
44
|
* @param page Page (Defaults to 1)
|
|
44
45
|
* @param region ISO-3166-1 code
|
|
45
46
|
*/
|
|
46
|
-
async popular(
|
|
47
|
-
return this.fetch_movie_list(
|
|
47
|
+
async popular(params = {}) {
|
|
48
|
+
return this.fetch_movie_list(MovieListEndpoints.POPULAR, params);
|
|
48
49
|
}
|
|
49
50
|
/**
|
|
50
51
|
* Top Rated
|
|
51
52
|
* GET - https://api.themoviedb.org/3/movie/top_rated
|
|
52
53
|
*
|
|
53
54
|
* Get a list of movies ordered by rating.
|
|
54
|
-
* @param language Language (Defaults to en-US)
|
|
55
|
+
* @param language Language (Defaults to en-US or TMDB default)
|
|
55
56
|
* @param page Page (Defaults to 1)
|
|
56
57
|
* @param region ISO-3166-1 code
|
|
57
58
|
*/
|
|
58
|
-
async top_rated(
|
|
59
|
-
return this.fetch_movie_list(
|
|
59
|
+
async top_rated(params = {}) {
|
|
60
|
+
return this.fetch_movie_list(MovieListEndpoints.TOP_RATED, params);
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
62
63
|
* Upcoming
|
|
63
64
|
* GET - https://api.themoviedb.org/3/movie/upcoming
|
|
64
65
|
*
|
|
65
66
|
* Get a list of movies that are being released soon.
|
|
66
|
-
* @param language Language (Defaults to en-US)
|
|
67
|
+
* @param language Language (Defaults to en-US or TMDB default)
|
|
67
68
|
* @param page Page (Defaults to 1)
|
|
68
69
|
* @param region ISO-3166-1 code
|
|
69
70
|
*/
|
|
70
|
-
async upcoming(
|
|
71
|
-
return this.fetch_movie_list(
|
|
71
|
+
async upcoming(params = {}) {
|
|
72
|
+
return this.fetch_movie_list(MovieListEndpoints.UPCOMING, params);
|
|
72
73
|
}
|
|
73
74
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ApiClient } from "../client";
|
|
2
|
+
import { TMDBOptions } from "../tmdb";
|
|
2
3
|
import { Changes } from "../types/common";
|
|
3
4
|
import { MovieAlternativeTitles, MovieCredits, MovieDetails, MovieExternalIDs, MovieImages, MovieKeywords, MovieReleaseDates, MovieResultItem, MovieTranslations, MovieVideos, MovieWatchProvider } from "../types/movies";
|
|
4
|
-
import { PaginatedResponse } from "../types/params";
|
|
5
|
+
import { MovieAlternativeTitlesParams, MovieDetailsParams, PaginatedResponse } from "../types/params";
|
|
5
6
|
export declare const MOVIE_ENDPOINTS: {
|
|
6
7
|
MOVIE: string;
|
|
7
8
|
ALTERNATIVE_TITLES: string;
|
|
@@ -20,7 +21,8 @@ export declare const MOVIE_ENDPOINTS: {
|
|
|
20
21
|
};
|
|
21
22
|
export declare class MoviesAPI {
|
|
22
23
|
private client;
|
|
23
|
-
|
|
24
|
+
private defaultOptions;
|
|
25
|
+
constructor(client: ApiClient, options?: TMDBOptions);
|
|
24
26
|
/**
|
|
25
27
|
* Details
|
|
26
28
|
* GET - https://api.themoviedb.org/3/movie/{movie_id}
|
|
@@ -32,7 +34,7 @@ export declare class MoviesAPI {
|
|
|
32
34
|
* @returns A promise that resolves to the movie details.
|
|
33
35
|
* @reference https://developer.themoviedb.org/reference/movie-details
|
|
34
36
|
*/
|
|
35
|
-
details(
|
|
37
|
+
details(params: MovieDetailsParams): Promise<MovieDetails>;
|
|
36
38
|
/**
|
|
37
39
|
* Alternative Titles
|
|
38
40
|
* GET - https://api.themoviedb.org/3/movie/{movie_id}/alternative_titles
|
|
@@ -43,7 +45,7 @@ export declare class MoviesAPI {
|
|
|
43
45
|
* @returns A promise that resolves to the movie alternative titles.
|
|
44
46
|
* @reference https://developer.themoviedb.org/reference/movie-alternative-titles
|
|
45
47
|
*/
|
|
46
|
-
alternative_titles(
|
|
48
|
+
alternative_titles(params: MovieAlternativeTitlesParams): Promise<MovieAlternativeTitles>;
|
|
47
49
|
/**
|
|
48
50
|
* Credits
|
|
49
51
|
* GET - https://api.themoviedb.org/3/movie/{movie_id}/credits
|
package/dist/endpoints/movies.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { mergeParams } from "../utils/params";
|
|
1
2
|
export const MOVIE_ENDPOINTS = {
|
|
2
3
|
MOVIE: "/movie",
|
|
3
4
|
ALTERNATIVE_TITLES: "/alternative_titles",
|
|
@@ -22,8 +23,10 @@ export const MOVIE_ENDPOINTS = {
|
|
|
22
23
|
};
|
|
23
24
|
export class MoviesAPI {
|
|
24
25
|
client;
|
|
25
|
-
|
|
26
|
+
defaultOptions;
|
|
27
|
+
constructor(client, options = {}) {
|
|
26
28
|
this.client = client;
|
|
29
|
+
this.defaultOptions = options;
|
|
27
30
|
}
|
|
28
31
|
/**
|
|
29
32
|
* Details
|
|
@@ -36,10 +39,10 @@ export class MoviesAPI {
|
|
|
36
39
|
* @returns A promise that resolves to the movie details.
|
|
37
40
|
* @reference https://developer.themoviedb.org/reference/movie-details
|
|
38
41
|
*/
|
|
39
|
-
async details(
|
|
40
|
-
const
|
|
41
|
-
const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}`;
|
|
42
|
-
return this.client.request(endpoint,
|
|
42
|
+
async details(params) {
|
|
43
|
+
const mergedParams = { ...this.defaultOptions, ...params };
|
|
44
|
+
const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${mergedParams.movie_id}`;
|
|
45
|
+
return this.client.request(endpoint, mergedParams);
|
|
43
46
|
}
|
|
44
47
|
/**
|
|
45
48
|
* Alternative Titles
|
|
@@ -51,10 +54,10 @@ export class MoviesAPI {
|
|
|
51
54
|
* @returns A promise that resolves to the movie alternative titles.
|
|
52
55
|
* @reference https://developer.themoviedb.org/reference/movie-alternative-titles
|
|
53
56
|
*/
|
|
54
|
-
async alternative_titles(
|
|
55
|
-
const
|
|
56
|
-
const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.ALTERNATIVE_TITLES}`;
|
|
57
|
-
return this.client.request(endpoint,
|
|
57
|
+
async alternative_titles(params) {
|
|
58
|
+
const mergedParams = mergeParams(this.defaultOptions, params);
|
|
59
|
+
const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${mergedParams.movie_id}${MOVIE_ENDPOINTS.ALTERNATIVE_TITLES}`;
|
|
60
|
+
return this.client.request(endpoint, mergedParams);
|
|
58
61
|
}
|
|
59
62
|
/**
|
|
60
63
|
* Credits
|
|
@@ -1,12 +1,14 @@
|
|
|
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
|
+
import { TMDBOptions } from "../tmdb";
|
|
4
5
|
export declare const SEARCH_ENDPOINTS: {
|
|
5
6
|
MOVIE: string;
|
|
6
7
|
};
|
|
7
8
|
export declare class SearchAPI {
|
|
8
9
|
private client;
|
|
9
|
-
|
|
10
|
+
private defaultOptions;
|
|
11
|
+
constructor(client: ApiClient, defaultOptions?: TMDBOptions);
|
|
10
12
|
/**
|
|
11
13
|
* Search
|
|
12
14
|
* GET - https://api.themoviedb.org/3/search/movie
|
|
@@ -21,5 +23,5 @@ export declare class SearchAPI {
|
|
|
21
23
|
* @param year Year
|
|
22
24
|
* @reference https://developer.themoviedb.org/reference/search-movie
|
|
23
25
|
*/
|
|
24
|
-
movies(
|
|
26
|
+
movies(params: SearchMoviesParams): Promise<PaginatedResponse<MovieResultItem>>;
|
|
25
27
|
}
|
package/dist/endpoints/search.js
CHANGED
|
@@ -3,8 +3,10 @@ export const SEARCH_ENDPOINTS = {
|
|
|
3
3
|
};
|
|
4
4
|
export class SearchAPI {
|
|
5
5
|
client;
|
|
6
|
-
|
|
6
|
+
defaultOptions; // ** Default options for all requests
|
|
7
|
+
constructor(client, defaultOptions = {}) {
|
|
7
8
|
this.client = client;
|
|
9
|
+
this.defaultOptions = defaultOptions;
|
|
8
10
|
}
|
|
9
11
|
/**
|
|
10
12
|
* Search
|
|
@@ -20,17 +22,10 @@ export class SearchAPI {
|
|
|
20
22
|
* @param year Year
|
|
21
23
|
* @reference https://developer.themoviedb.org/reference/search-movie
|
|
22
24
|
*/
|
|
23
|
-
async movies(
|
|
24
|
-
const params = {
|
|
25
|
-
query,
|
|
26
|
-
include_adult,
|
|
27
|
-
language,
|
|
28
|
-
page,
|
|
29
|
-
primary_release_year,
|
|
30
|
-
year,
|
|
31
|
-
region,
|
|
32
|
-
};
|
|
25
|
+
async movies(params) {
|
|
33
26
|
const endpoint = `${SEARCH_ENDPOINTS.MOVIE}`;
|
|
34
|
-
|
|
27
|
+
// Merge defaultOptions with params, giving precedence to params
|
|
28
|
+
const mergedParams = { ...this.defaultOptions, ...params };
|
|
29
|
+
return this.client.request(endpoint, mergedParams);
|
|
35
30
|
}
|
|
36
31
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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, { language: "it-IT", region: "IT", country: "IT" });
|
|
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({ movie_id: 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,42 @@
|
|
|
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";
|
|
18
|
+
await moviesAPI.details({ movie_id, append_to_response, language });
|
|
19
|
+
expect(clientMock.request).toHaveBeenCalledOnce();
|
|
20
|
+
expect(clientMock.request).toHaveBeenCalledWith("/movie/550", {
|
|
21
|
+
movie_id,
|
|
22
|
+
append_to_response,
|
|
23
|
+
language,
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
it("should work correctly without optional parameters", async () => {
|
|
27
|
+
const movie_id = 550;
|
|
28
|
+
await moviesAPI.details({ movie_id });
|
|
29
|
+
expect(clientMock.request).toHaveBeenCalledOnce();
|
|
30
|
+
expect(clientMock.request).toHaveBeenCalledWith("/movie/550", {
|
|
31
|
+
movie_id,
|
|
32
|
+
append_to_response: undefined,
|
|
33
|
+
language: undefined,
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
it("should return the result from client.request", async () => {
|
|
37
|
+
const fakeResponse = { id: 550, title: "Fight Club" };
|
|
38
|
+
clientMock.request.mockResolvedValue(fakeResponse);
|
|
39
|
+
const result = await moviesAPI.details({ movie_id: 550 });
|
|
40
|
+
expect(result).toEqual(fakeResponse);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
it("(SEARCH MOVIE) should search for a movie with default options", async () => {
|
|
16
|
+
const tmdb = new TMDB(token, { language: "it-IT", region: "IT" });
|
|
17
|
+
const movies = await tmdb.search.movies({ query: "Fight Club" });
|
|
18
|
+
expect(movies.page).toBe(1);
|
|
19
|
+
expect(movies.total_results).toBeGreaterThan(0);
|
|
20
|
+
expect(movies.results.length).toBeGreaterThan(0);
|
|
21
|
+
expect(movies.results[0].title).toBe("Fight Club");
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -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
|
+
});
|
package/dist/tmdb.d.ts
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
import { MovieListsAPI } from "./endpoints/movie_lists";
|
|
2
2
|
import { MoviesAPI } from "./endpoints/movies";
|
|
3
3
|
import { SearchAPI } from "./endpoints/search";
|
|
4
|
+
export type TMDBOptions = {
|
|
5
|
+
language?: string;
|
|
6
|
+
region?: string;
|
|
7
|
+
country?: string;
|
|
8
|
+
};
|
|
4
9
|
export declare class TMDB {
|
|
5
10
|
private client;
|
|
11
|
+
private options;
|
|
6
12
|
movies: MoviesAPI;
|
|
7
13
|
movie_lists: MovieListsAPI;
|
|
8
14
|
search: SearchAPI;
|
|
9
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new TMDB instance.
|
|
17
|
+
* @param accessToken The TMDB API access token.
|
|
18
|
+
* @param options Optional default options (e.g., language) for all requests.
|
|
19
|
+
*/
|
|
20
|
+
constructor(accessToken: string, options?: TMDBOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Helper to merge default options with method-specific params.
|
|
23
|
+
* Method-level params override defaults.
|
|
24
|
+
*/
|
|
25
|
+
withDefaults<T extends object>(params?: T): T & TMDBOptions;
|
|
10
26
|
}
|
package/dist/tmdb.js
CHANGED
|
@@ -6,16 +6,30 @@ import { SearchAPI } from "./endpoints/search";
|
|
|
6
6
|
import { Errors } from "./errors/messages";
|
|
7
7
|
export class TMDB {
|
|
8
8
|
client;
|
|
9
|
+
options; // ** Default options for all requests
|
|
9
10
|
movies;
|
|
10
11
|
movie_lists;
|
|
11
12
|
search;
|
|
12
13
|
// etc...
|
|
13
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new TMDB instance.
|
|
16
|
+
* @param accessToken The TMDB API access token.
|
|
17
|
+
* @param options Optional default options (e.g., language) for all requests.
|
|
18
|
+
*/
|
|
19
|
+
constructor(accessToken, options = {}) {
|
|
14
20
|
if (!accessToken)
|
|
15
21
|
throw new Error(Errors.NO_ACCESS_TOKEN);
|
|
22
|
+
this.options = options;
|
|
16
23
|
this.client = new ApiClient(accessToken);
|
|
17
|
-
this.movies = new MoviesAPI(this.client);
|
|
18
|
-
this.movie_lists = new MovieListsAPI(this.client);
|
|
19
|
-
this.search = new SearchAPI(this.client);
|
|
24
|
+
this.movies = new MoviesAPI(this.client, options);
|
|
25
|
+
this.movie_lists = new MovieListsAPI(this.client, options);
|
|
26
|
+
this.search = new SearchAPI(this.client, options);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Helper to merge default options with method-specific params.
|
|
30
|
+
* Method-level params override defaults.
|
|
31
|
+
*/
|
|
32
|
+
withDefaults(params) {
|
|
33
|
+
return { ...this.options, ...params };
|
|
20
34
|
}
|
|
21
35
|
}
|