Skip to content

Commit

Permalink
feat: add title ordering if average ratings are equals
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrevano committed Apr 8, 2024
1 parent 702ec87 commit 85b2522
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
19 changes: 17 additions & 2 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const fs = require("fs");

const config = require("./src/config").config;

const baseURL = process.env.SOURCE === "remote" ? config.baseURLRemote : config.baseURLLocal;

/**
* A function to count the number of lines in a file.
*
Expand Down Expand Up @@ -458,6 +460,21 @@ const params = {
}),
},

compare_two_minimum_ratings: {
query: "?item_type=tvshow&popularity_filters=none&minimum_ratings=3.5",
expectedResult: async (items) => {
const response = await axios.get(`${baseURL}?item_type=tvshow&popularity_filters=none&minimum_ratings=3.5,1`);
const data = response.data;
const itemsFromExtraCall = data.results;

expect(items.length).toEqual(itemsFromExtraCall.length);

items.forEach((item, index) => {
expect(item).toEqual(itemsFromExtraCall[index]);
});
},
},

ratings_average_for_incorrect_minimum_ratings: {
query: "?item_type=tvshow&popularity_filters=none&minimum_ratings=some invalid value to be tested",
expectedResult: (items) => {
Expand Down Expand Up @@ -535,8 +552,6 @@ const params = {
* @returns None
*/
describe("What's on? API tests", () => {
const param = process.env.SOURCE;
const baseURL = param === "remote" ? config.baseURLRemote : config.baseURLLocal;
console.log(`Testing on ${baseURL}`);

Object.entries(params).forEach(([name, { query, expectedResult }]) => {
Expand Down
14 changes: 7 additions & 7 deletions src/content/getPlatformsLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ const getPlatformsLinks = async (betaseriesHomepage, betaseriesId, allocineHomep
}

const processSvods = (svods) => {
platformsLinks = [];
svods.forEach((element) => {
platformsLinks.push({
name: element.name,
link_url: element.link_url,
});
});
let platformsLinks = [];

if (Array.isArray(svods)) {
platformsLinks = svods.map((element) => ({ name: element.name, link_url: element.link_url }));
} else if (typeof svods === "object") {
platformsLinks = Object.values(svods).map((element) => ({ name: element.name, link_url: element.link_url }));
}
};

if (data.show && data.show.platforms && data.show.platforms.svods) {
Expand Down
2 changes: 1 addition & 1 deletion src/getItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const getItems = async (

const limit_results = { $limit: limit };
const skip_results = { $skip: (page - 1) * limit };
const sort_popularity_and_ratings = { $sort: { sortAvgField: 1, popularity_average: 1, ratings_average: -1 } };
const sort_popularity_and_ratings = { $sort: { sortAvgField: 1, popularity_average: 1, ratings_average: -1, title: 1 } };
const remove_sort_popularity = { $project: { sortAvgField: 0 } };

const facet = {
Expand Down

0 comments on commit 85b2522

Please sign in to comment.