Updated unit tests

pull/36/head
samuele.berlusconi 2020-10-21 22:35:48 +02:00
parent e1a08bba06
commit 22bd79684c
6 changed files with 617 additions and 670 deletions

View File

@ -86,6 +86,7 @@ class GameInfo {
/**
* Converts the object to a dictionary used for JSON serialization
*/
/* istanbul ignore next */
toJSON() {
return {
name: this.name,
@ -110,6 +111,7 @@ class GameInfo {
* @param {String} json JSON string used to create the new object
* @returns {GameInfo}
*/
/* istanbul ignore next */
static fromJSON(json) {
return Object.assign(new GameInfo(), json);
}

View File

@ -194,10 +194,16 @@ function parseConversationPage(text) {
* @private
* Gets the URL of the image used as a preview for the game in the conversation.
* @param {puppeteer.Page} page Page containing the URL to be extrapolated
* @returns {Promise<String>} URL (String) of the image or a empty string if failed to get it
* @returns {Promise<String>} URL (String) of the image or null if failed to get it
*/
async function getGamePreviewSource(page) {
// Wait for the selector or return an empty value
try {
await page.waitForSelector(selectorK.GAME_IMAGES);
} catch {
return null;
}
const src = await page.evaluate(
/* istanbul ignore next */
(selector) => {
@ -211,7 +217,7 @@ async function getGamePreviewSource(page) {
);
// Check if the URL is valid
return urlHelper.isStringAValidURL(src) ? src : "";
return urlHelper.isStringAValidURL(src) ? src : null;
}
/**
@ -454,6 +460,6 @@ function extractGameHostingData(platform, text) {
* @param {String} string
*/
function capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
return string.toLowerCase().charAt(0).toUpperCase() + string.slice(1);
}
//#endregion Private methods

File diff suppressed because it is too large Load Diff

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "f95api",
"version": "1.3.4",
"version": "1.3.5",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -40,6 +40,7 @@
"devDependencies": {
"chai": "^4.2.0",
"dotenv": "^8.2.0",
"lodash": "^4.17.20",
"mocha": "^8.1.3",
"nyc": "^15.1.0",
"sleep": "^6.3.0"

View File

@ -1,11 +1,19 @@
"use strict";
const urlHelper = require("../app/scripts/url-helper.js");
const expect = require("chai").expect;
const F95API = require("../app/index");
// Core modules
const fs = require("fs");
// Public modules from npm
const _ = require('lodash');
const expect = require("chai").expect;
const sleep = require("sleep");
const dotenv = require("dotenv");
// Modules from file
const urlHelper = require("../app/scripts/url-helper.js");
const F95API = require("../app/index.js");
// Configure the .env reader
dotenv.config();
const COOKIES_SAVE_PATH = "./f95cache/cookies.json";
@ -16,7 +24,7 @@ const PASSWORD = process.env.F95_PASSWORD;
const FAKE_USERNAME = "FakeUsername091276";
const FAKE_PASSWORD = "fake_password";
F95API.debug(false);
//F95API.debug(false);
function randomSleep() {
const random = Math.floor(Math.random() * 500) + 50;
@ -174,7 +182,8 @@ describe("Search game data", function () {
it("Test game serialization", function () {
const json = JSON.stringify(testGame);
const parsedGameInfo = JSON.parse(json);
expect(parsedGameInfo).to.be.equal(testGame);
const result = _.isEqual(parsedGameInfo, testGame);
expect(result).to.be.true;
});
});
@ -247,26 +256,26 @@ describe("Test url-helper", function () {
it("Check if URL exists", async function () {
// Check generic URLs...
let exists = urlHelper.urlExists("https://www.google.com/");
expect(exists).to.be.true;
let exists = await urlHelper.urlExists("https://www.google.com/");
expect(exists, "Complete valid URL").to.be.true;
exists = urlHelper.urlExists("www.google.com");
expect(exists).to.be.true;
exists = await urlHelper.urlExists("www.google.com");
expect(exists, "URl without protocol prefix").to.be.false;
exists = urlHelper.urlExists("https://www.google/");
expect(exists).to.be.false;
exists = await urlHelper.urlExists("https://www.google/");
expect(exists, "URL without third level domain").to.be.false;
// Now check for more specific URLs (with redirect)...
exists = urlHelper.urlExists(
exists = await urlHelper.urlExists(
"https://f95zone.to/threads/perverted-education-v0-9601-april-ryan.1854/"
);
expect(exists).to.be.true;
expect(exists, "URL with redirect without check").to.be.true;
exists = urlHelper.urlExists(
exists = await urlHelper.urlExists(
"https://f95zone.to/threads/perverted-education-v0-9601-april-ryan.1854/",
true
);
expect(exists).to.be.false;
expect(exists, "URL with redirect with check").to.be.false;
});
it("Check if URL belong to the platform", async function () {