diff --git a/app/index.js b/app/index.js index 578dfdc..4242a56 100644 --- a/app/index.js +++ b/app/index.js @@ -69,6 +69,7 @@ module.exports.login = async function (username, password) { const result = await networkHelper.authenticate(creds); shared.isLogged = result.success; + /* istambul ignore next */ if (result.success) shared.logger.info("User logged in through the platform"); else shared.logger.warn(`Error during authentication: ${result.message}`); diff --git a/app/scripts/network-helper.js b/app/scripts/network-helper.js index 92077e2..26a06fa 100644 --- a/app/scripts/network-helper.js +++ b/app/scripts/network-helper.js @@ -41,9 +41,11 @@ module.exports.fetchHTML = async function (url) { const response = await exports.fetchGETResponse(url); // Manage response + /* istambul ignore next */ if (!response) { shared.logger.warn(`Unable to fetch HTML for ${url}`); } + /* istambul ignore next */ else if (!response.headers["content-type"].includes("text/html")) { // The response is not a HTML page shared.logger.warn(`The ${url} returned a ${response.headers["content-type"]} response`); @@ -113,6 +115,7 @@ module.exports.authenticate = async function (credentials, force) { module.exports.getF95Token = async function() { // Fetch the response of the platform const response = await exports.fetchGETResponse(f95url.F95_LOGIN_URL); + /* istambul ignore next */ if (!response) { shared.logger.warn("Unable to get the token for the session"); return null; diff --git a/test/suites/api-test.js b/test/suites/api-test.js index b9a1000..16557ec 100644 --- a/test/suites/api-test.js +++ b/test/suites/api-test.js @@ -94,4 +94,27 @@ module.exports.suite = function suite() { const equal = isEqual(game, gameFromURL); expect(equal).to.be.true; }); + + it("Test latest games fetching", async function testLatestFetch() { + // Prepare a search query + const query = { + datelimit: 0, + tags: ["male protagonist", "3dcg"], + prefixes: ["Completed", "Unity"], + sorting: "views", + }; + + // TODO + // First test the parameters validation + // assert.throws(() => { F95API.getLatestUpdates(query, 0); }, + // Error, + // "Error thrown if limit is <= 0"); + + // Now we fetch certain games that are "stables" as per 2020 + const LIMIT = 3; + const result = await F95API.getLatestUpdates(query, LIMIT); + expect(result[0].id).to.be.equal(3691, "The game should be: 'Man of the house'"); + expect(result[1].id).to.be.equal(5483, "The game should be: 'Lucky mark'"); + expect(result[2].id).to.be.equal(5949, "The game should be: 'Timestamps, Unconditional Love'"); + }); }; \ No newline at end of file diff --git a/test/suites/scraper-test.js b/test/suites/scraper-test.js index a68666b..07a6072 100644 --- a/test/suites/scraper-test.js +++ b/test/suites/scraper-test.js @@ -11,7 +11,9 @@ const scraper = require("../../app/scripts/scraper.js"); module.exports.suite = function suite() { // Global suite variables const gameURL = "https://f95zone.to/threads/kingdom-of-deception-v0-10-8-hreinn-games.2733/"; + const modURL = "https://f95zone.to/threads/witch-trainer-silver-mod-v1-39-silver-studio-games.1697/"; const previewSrc = "https://attachments.f95zone.to/2018/09/162821_f9nXfwF.png"; + const modPreviewSrc = "https://attachments.f95zone.to/2018/10/178357_banner.png"; it("Search game", async function () { // This test depend on the data on F95Zone at gameURL @@ -25,6 +27,18 @@ module.exports.suite = function suite() { expect(result.previewSrc).to.equal(previewSrc, "Preview not equals"); }); + it("Search mod", async function () { + // This test depend on the data on F95Zone at modURL + const result = await scraper.getGameInfo(modURL); + + // Test only the main information + expect(result.name).to.equal("Witch Trainer: Silver Mod"); + expect(result.author).to.equal("Silver Studio Games"); + expect(result.isMod, "Should be true").to.be.true; + expect(result.engine).to.equal("Ren'Py"); + expect(result.previewSrc).to.equal(modPreviewSrc, "Preview not equals"); + }); + it("Test game serialization", async function testGameSerialization() { // This test depend on the data on F95Zone at gameURL const testGame = await scraper.getGameInfo(gameURL);