Updated unit tests
parent
e1a08bba06
commit
22bd79684c
|
@ -86,6 +86,7 @@ class GameInfo {
|
||||||
/**
|
/**
|
||||||
* Converts the object to a dictionary used for JSON serialization
|
* Converts the object to a dictionary used for JSON serialization
|
||||||
*/
|
*/
|
||||||
|
/* istanbul ignore next */
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return {
|
return {
|
||||||
name: this.name,
|
name: this.name,
|
||||||
|
@ -110,6 +111,7 @@ class GameInfo {
|
||||||
* @param {String} json JSON string used to create the new object
|
* @param {String} json JSON string used to create the new object
|
||||||
* @returns {GameInfo}
|
* @returns {GameInfo}
|
||||||
*/
|
*/
|
||||||
|
/* istanbul ignore next */
|
||||||
static fromJSON(json) {
|
static fromJSON(json) {
|
||||||
return Object.assign(new GameInfo(), json);
|
return Object.assign(new GameInfo(), json);
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,10 +194,16 @@ function parseConversationPage(text) {
|
||||||
* @private
|
* @private
|
||||||
* Gets the URL of the image used as a preview for the game in the conversation.
|
* 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
|
* @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) {
|
async function getGamePreviewSource(page) {
|
||||||
await page.waitForSelector(selectorK.GAME_IMAGES);
|
// Wait for the selector or return an empty value
|
||||||
|
try {
|
||||||
|
await page.waitForSelector(selectorK.GAME_IMAGES);
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const src = await page.evaluate(
|
const src = await page.evaluate(
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
(selector) => {
|
(selector) => {
|
||||||
|
@ -211,7 +217,7 @@ async function getGamePreviewSource(page) {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Check if the URL is valid
|
// 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
|
* @param {String} string
|
||||||
*/
|
*/
|
||||||
function capitalize(string) {
|
function capitalize(string) {
|
||||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
return string.toLowerCase().charAt(0).toUpperCase() + string.slice(1);
|
||||||
}
|
}
|
||||||
//#endregion Private methods
|
//#endregion Private methods
|
||||||
|
|
1229
coverage.lcov
1229
coverage.lcov
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "f95api",
|
"name": "f95api",
|
||||||
"version": "1.3.4",
|
"version": "1.3.5",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
|
"lodash": "^4.17.20",
|
||||||
"mocha": "^8.1.3",
|
"mocha": "^8.1.3",
|
||||||
"nyc": "^15.1.0",
|
"nyc": "^15.1.0",
|
||||||
"sleep": "^6.3.0"
|
"sleep": "^6.3.0"
|
||||||
|
|
|
@ -1,11 +1,19 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const urlHelper = require("../app/scripts/url-helper.js");
|
// Core modules
|
||||||
const expect = require("chai").expect;
|
|
||||||
const F95API = require("../app/index");
|
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
|
// Public modules from npm
|
||||||
|
const _ = require('lodash');
|
||||||
|
const expect = require("chai").expect;
|
||||||
const sleep = require("sleep");
|
const sleep = require("sleep");
|
||||||
const dotenv = require("dotenv");
|
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();
|
dotenv.config();
|
||||||
|
|
||||||
const COOKIES_SAVE_PATH = "./f95cache/cookies.json";
|
const COOKIES_SAVE_PATH = "./f95cache/cookies.json";
|
||||||
|
@ -16,7 +24,7 @@ const PASSWORD = process.env.F95_PASSWORD;
|
||||||
const FAKE_USERNAME = "FakeUsername091276";
|
const FAKE_USERNAME = "FakeUsername091276";
|
||||||
const FAKE_PASSWORD = "fake_password";
|
const FAKE_PASSWORD = "fake_password";
|
||||||
|
|
||||||
F95API.debug(false);
|
//F95API.debug(false);
|
||||||
|
|
||||||
function randomSleep() {
|
function randomSleep() {
|
||||||
const random = Math.floor(Math.random() * 500) + 50;
|
const random = Math.floor(Math.random() * 500) + 50;
|
||||||
|
@ -174,7 +182,8 @@ describe("Search game data", function () {
|
||||||
it("Test game serialization", function () {
|
it("Test game serialization", function () {
|
||||||
const json = JSON.stringify(testGame);
|
const json = JSON.stringify(testGame);
|
||||||
const parsedGameInfo = JSON.parse(json);
|
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 () {
|
it("Check if URL exists", async function () {
|
||||||
// Check generic URLs...
|
// Check generic URLs...
|
||||||
let exists = urlHelper.urlExists("https://www.google.com/");
|
let exists = await urlHelper.urlExists("https://www.google.com/");
|
||||||
expect(exists).to.be.true;
|
expect(exists, "Complete valid URL").to.be.true;
|
||||||
|
|
||||||
exists = urlHelper.urlExists("www.google.com");
|
exists = await urlHelper.urlExists("www.google.com");
|
||||||
expect(exists).to.be.true;
|
expect(exists, "URl without protocol prefix").to.be.false;
|
||||||
|
|
||||||
exists = urlHelper.urlExists("https://www.google/");
|
exists = await urlHelper.urlExists("https://www.google/");
|
||||||
expect(exists).to.be.false;
|
expect(exists, "URL without third level domain").to.be.false;
|
||||||
|
|
||||||
// Now check for more specific URLs (with redirect)...
|
// 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/"
|
"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/",
|
"https://f95zone.to/threads/perverted-education-v0-9601-april-ryan.1854/",
|
||||||
true
|
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 () {
|
it("Check if URL belong to the platform", async function () {
|
||||||
|
|
Loading…
Reference in New Issue