Add new tests

pull/59/head
MillenniumEarl 2020-12-15 15:22:10 +01:00
parent 7b8eb5b357
commit c20d7d9597
4 changed files with 41 additions and 0 deletions

View File

@ -69,6 +69,7 @@ module.exports.login = async function (username, password) {
const result = await networkHelper.authenticate(creds); const result = await networkHelper.authenticate(creds);
shared.isLogged = result.success; shared.isLogged = result.success;
/* istambul ignore next */
if (result.success) shared.logger.info("User logged in through the platform"); if (result.success) shared.logger.info("User logged in through the platform");
else shared.logger.warn(`Error during authentication: ${result.message}`); else shared.logger.warn(`Error during authentication: ${result.message}`);

View File

@ -41,9 +41,11 @@ module.exports.fetchHTML = async function (url) {
const response = await exports.fetchGETResponse(url); const response = await exports.fetchGETResponse(url);
// Manage response // Manage response
/* istambul ignore next */
if (!response) { if (!response) {
shared.logger.warn(`Unable to fetch HTML for ${url}`); shared.logger.warn(`Unable to fetch HTML for ${url}`);
} }
/* istambul ignore next */
else if (!response.headers["content-type"].includes("text/html")) { else if (!response.headers["content-type"].includes("text/html")) {
// The response is not a HTML page // The response is not a HTML page
shared.logger.warn(`The ${url} returned a ${response.headers["content-type"]} response`); 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() { module.exports.getF95Token = async function() {
// Fetch the response of the platform // Fetch the response of the platform
const response = await exports.fetchGETResponse(f95url.F95_LOGIN_URL); const response = await exports.fetchGETResponse(f95url.F95_LOGIN_URL);
/* istambul ignore next */
if (!response) { if (!response) {
shared.logger.warn("Unable to get the token for the session"); shared.logger.warn("Unable to get the token for the session");
return null; return null;

View File

@ -94,4 +94,27 @@ module.exports.suite = function suite() {
const equal = isEqual(game, gameFromURL); const equal = isEqual(game, gameFromURL);
expect(equal).to.be.true; 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'");
});
}; };

View File

@ -11,7 +11,9 @@ const scraper = require("../../app/scripts/scraper.js");
module.exports.suite = function suite() { module.exports.suite = function suite() {
// Global suite variables // Global suite variables
const gameURL = "https://f95zone.to/threads/kingdom-of-deception-v0-10-8-hreinn-games.2733/"; 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 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 () { it("Search game", async function () {
// This test depend on the data on F95Zone at gameURL // 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"); 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() { it("Test game serialization", async function testGameSerialization() {
// This test depend on the data on F95Zone at gameURL // This test depend on the data on F95Zone at gameURL
const testGame = await scraper.getGameInfo(gameURL); const testGame = await scraper.getGameInfo(gameURL);