From 8468269fd39c0db241509b7828ae752ccd706873 Mon Sep 17 00:00:00 2001 From: MillenniumEarl Date: Sun, 22 Nov 2020 10:42:43 +0100 Subject: [PATCH] Added tests and ignored not useful code --- app/index.js | 5 +++++ app/scripts/classes/tag-parser.js | 2 ++ test/suites/api-test.js | 35 ++++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/app/index.js b/app/index.js index 4f4afc1..4862d08 100644 --- a/app/index.js +++ b/app/index.js @@ -54,6 +54,7 @@ const USER_NOT_LOGGED = "User not authenticated, unable to continue"; * @returns {Promise} Result of the operation */ module.exports.login = async function (username, password) { + /* istanbul ignore next */ if (shared.isLogged) { shared.logger.info(`${username} already authenticated`); return new LoginResult(true, `${username} already authenticated`); @@ -81,6 +82,7 @@ module.exports.login = async function (username, password) { * @returns {Promise} true if an update is available, false otherwise */ module.exports.checkIfGameHasUpdate = async function (info) { + /* istanbul ignore next */ if (!shared.isLogged) { shared.logger.warn(USER_NOT_LOGGED); return false; @@ -109,6 +111,7 @@ module.exports.checkIfGameHasUpdate = async function (info) { * an identified game (in the case of homonymy of titles) */ module.exports.getGameData = async function (name, mod) { + /* istanbul ignore next */ if (!shared.isLogged) { shared.logger.warn(USER_NOT_LOGGED); return null; @@ -138,6 +141,7 @@ module.exports.getGameData = async function (name, mod) { * @returns {Promise} Information about the game. If no game was found, null is returned */ module.exports.getGameDataFromURL = async function (url) { + /* istanbul ignore next */ if (!shared.isLogged) { shared.logger.warn(USER_NOT_LOGGED); return null; @@ -159,6 +163,7 @@ module.exports.getGameDataFromURL = async function (url) { * @returns {Promise} Data of the user currently logged in */ module.exports.getUserData = async function () { + /* istanbul ignore next */ if (!shared.isLogged) { shared.logger.warn(USER_NOT_LOGGED); return null; diff --git a/app/scripts/classes/tag-parser.js b/app/scripts/classes/tag-parser.js index 70355a6..a77da58 100644 --- a/app/scripts/classes/tag-parser.js +++ b/app/scripts/classes/tag-parser.js @@ -63,6 +63,7 @@ class TagParser { for(const tag of tags) { // Extract the key from the value const key = this._getKeyByValue(this._tagsDict, tag); + /* istanbul ignore next */ if(key) ids.push(parseInt(key)); } return ids.sort((a, b) => a - b); // JS sort alphabetically, same old problem @@ -78,6 +79,7 @@ class TagParser { for(const id of ids) { // Check if the key exists in the dict const exist = id in this._tagsDict; + /* istanbul ignore next */ if (!exist) continue; // Save the value diff --git a/test/suites/api-test.js b/test/suites/api-test.js index 07e6016..b9a1000 100644 --- a/test/suites/api-test.js +++ b/test/suites/api-test.js @@ -20,6 +20,7 @@ const PASSWORD = process.env.F95_PASSWORD; module.exports.suite = function suite() { // Global suite variables const gameURL = "https://f95zone.to/threads/perverted-education-v0-9601-april-ryan.1854/"; + const updatedGameURL = "https://f95zone.to/threads/noxian-nights-v1-2-4-hreinn-games.2/"; it("Test login", async function testLogin() { const result = await F95API.login(USERNAME, PASSWORD); @@ -32,7 +33,7 @@ module.exports.suite = function suite() { expect(userdata.username).to.be.equal(USERNAME); }); - it("Test game update checking", async function testGameUpdateCheck() { + it("Test game for existing update", async function checkUpdateByURL() { // We force the creation of a GameInfo object, // knowing that the checkIfGameHasUpdate() function // only needs the game URL @@ -46,6 +47,38 @@ module.exports.suite = function suite() { expect(update).to.be.true; }); + it("Test game for non existing update", async function checkUpdateByVersion() { + // We force the creation of a GameInfo object, + // knowing that the checkIfGameHasUpdate() function + // only needs the game URL + const info = new F95API.GameInfo(); + + // The updatedGameURL identifies a game for which + // we know there is **not** an update + info.url = updatedGameURL; + info.version = "1.2.4"; // The hame is marked as "Completed" so it shouldn't change it's version + + // Check for updates + const update = await F95API.checkIfGameHasUpdate(info); + expect(update).to.be.false; + }); + + it("Test game for fake update", async function checkFakeUpdateByVersion() { + // We force the creation of a GameInfo object, + // knowing that the checkIfGameHasUpdate() function + // only needs the game URL + const info = new F95API.GameInfo(); + + // The updatedGameURL identifies a game for which + // we know there is **not** an update + info.url = updatedGameURL; + info.version = "ThisIsAFakeVersion"; // The real version is "1.2.4" + + // Check for updates + const update = await F95API.checkIfGameHasUpdate(info); + expect(update).to.be.true; + }); + it("Test game data fetching", async function testGameDataFetch() { // Search a game by name const gameList = await F95API.getGameData("perverted education", false);