Skip to content

Commit

Permalink
feat: add platforms filter
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrevano committed Apr 8, 2024
1 parent 85b2522 commit bc07870
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 62 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ app.get("/", async (req, res) => {
const limit_query = parseInt(req.query.limit);
const minimum_ratings_query = req.query.minimum_ratings;
const page_query = parseInt(req.query.page);
const platforms_query = req.query.platforms;
const popularity_filters_query = req.query.popularity_filters;
const ratings_filters_query = req.query.ratings_filters;
const seasons_number_query = req.query.seasons_number;
Expand All @@ -44,6 +45,7 @@ app.get("/", async (req, res) => {
limit_query,
minimum_ratings_query,
page_query,
platforms_query,
popularity_filters_query,
ratings_filters_query,
seasons_number_query,
Expand Down
31 changes: 31 additions & 0 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,37 @@ const params = {
});
},
},

only_platforms_netflix: {
query: "?platforms=Netflix",
expectedResult: (items) => {
items.forEach((item) => {
expect(item).toHaveProperty("platforms_links");
expect(item.platforms_links).not.toBeNull();
expect(item.platforms_links.some((platform) => platform.name === "Netflix")).toBeTruthy();
});
},
},

only_platforms_netflix_or_canal: {
query: "?platforms=Netflix,Canal%2B",
expectedResult: (items) => {
items.forEach((item) => {
expect(item).toHaveProperty("platforms_links");
expect(item.platforms_links).not.toBeNull();
const hasNetflix = item.platforms_links.some((platform) => platform.name === "Netflix");
const hasCanalPlus = item.platforms_links.some((platform) => platform.name === "Canal+");
expect(hasNetflix || hasCanalPlus).toBeTruthy();
});
},
},

include_all_platforms: {
query: "?platforms=all,Netflix,Canal%2B&limit=3000",
expectedResult: (items) => {
expect(items.filter((item) => item.platforms_links === null).length).toBeGreaterThan(config.minimumNumberOfItems.default);
},
},
};

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "whatson-api",
"version": "2.1.0",
"version": "2.2.0",
"description": "What's on? API to retrieve movies and tvshows",
"main": "index.js",
"scripts": {
Expand Down
Loading

0 comments on commit bc07870

Please sign in to comment.