Merge pull request #32 from MillenniumEarl/deepsource-transform-bae9a28c

Format code with prettier
pull/33/head
Millennium Earl 2020-10-16 10:23:00 +02:00 committed by GitHub
commit be2e65e665
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 58 deletions

View File

@ -1,19 +1,19 @@
'use strict'; "use strict";
const expect = require('chai').expect; const expect = require("chai").expect;
const F95API = require('../app/index'); const F95API = require("../app/index");
const fs = require('fs'); const fs = require("fs");
const sleep = require('sleep'); const sleep = require("sleep");
const dotenv = require('dotenv'); const dotenv = require("dotenv");
dotenv.config(); dotenv.config();
const COOKIES_SAVE_PATH = './f95cache/cookies.json'; const COOKIES_SAVE_PATH = "./f95cache/cookies.json";
const ENGINES_SAVE_PATH = './f95cache/engines.json'; const ENGINES_SAVE_PATH = "./f95cache/engines.json";
const STATUSES_SAVE_PATH = './f95cache/statuses.json'; const STATUSES_SAVE_PATH = "./f95cache/statuses.json";
const USERNAME = process.env.F95_USERNAME; const USERNAME = process.env.F95_USERNAME;
const PASSWORD = process.env.F95_PASSWORD; 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);
@ -22,15 +22,15 @@ function randomSleep() {
sleep.msleep(500 + random); sleep.msleep(500 + random);
} }
describe('Login without cookies', function () { describe("Login without cookies", function () {
//#region Set-up //#region Set-up
this.timeout(30000); // All tests in this suite get 30 seconds before timeout this.timeout(30000); // All tests in this suite get 30 seconds before timeout
before('Set isolation', function () { before("Set isolation", function () {
F95API.setIsolation(true); F95API.setIsolation(true);
}); });
beforeEach('Remove all cookies', function () { beforeEach("Remove all cookies", function () {
// Runs before each test in this block // Runs before each test in this block
if (fs.existsSync(COOKIES_SAVE_PATH)) fs.unlinkSync(COOKIES_SAVE_PATH); if (fs.existsSync(COOKIES_SAVE_PATH)) fs.unlinkSync(COOKIES_SAVE_PATH);
if (F95API.isLogged()) F95API.logout(); if (F95API.isLogged()) F95API.logout();
@ -39,53 +39,53 @@ describe('Login without cookies', function () {
let testOrder = 0; let testOrder = 0;
it('Test with valid credentials', async function () { it("Test with valid credentials", async function () {
// Gain exclusive use of the cookies // Gain exclusive use of the cookies
while (testOrder !== 0) randomSleep(); while (testOrder !== 0) randomSleep();
const result = await F95API.login(USERNAME, PASSWORD); const result = await F95API.login(USERNAME, PASSWORD);
expect(result.success).to.be.true; expect(result.success).to.be.true;
expect(result.message).equal('Authentication successful'); expect(result.message).equal("Authentication successful");
testOrder = 1; testOrder = 1;
}); });
it('Test with invalid username', async function () { it("Test with invalid username", async function () {
// Gain exclusive use of the cookies // Gain exclusive use of the cookies
while (testOrder !== 1) randomSleep(); while (testOrder !== 1) randomSleep();
const result = await F95API.login(FAKE_USERNAME, FAKE_PASSWORD); const result = await F95API.login(FAKE_USERNAME, FAKE_PASSWORD);
expect(result.success).to.be.false; expect(result.success).to.be.false;
expect(result.message).to.equal('Incorrect username'); expect(result.message).to.equal("Incorrect username");
testOrder = 2; testOrder = 2;
}); });
it('Test with invalid password', async function () { it("Test with invalid password", async function () {
// Gain exclusive use of the cookies // Gain exclusive use of the cookies
while (testOrder !== 2) randomSleep(); while (testOrder !== 2) randomSleep();
const result = await F95API.login(USERNAME, FAKE_PASSWORD); const result = await F95API.login(USERNAME, FAKE_PASSWORD);
expect(result.success).to.be.false; expect(result.success).to.be.false;
expect(result.message).to.equal('Incorrect password'); expect(result.message).to.equal("Incorrect password");
testOrder = 3; testOrder = 3;
}); });
it('Test with invalid credentials', async function () { it("Test with invalid credentials", async function () {
// Gain exclusive use of the cookies // Gain exclusive use of the cookies
while (testOrder !== 3) randomSleep(); while (testOrder !== 3) randomSleep();
const result = await F95API.login(FAKE_USERNAME, FAKE_PASSWORD); const result = await F95API.login(FAKE_USERNAME, FAKE_PASSWORD);
expect(result.success).to.be.false; expect(result.success).to.be.false;
expect(result.message).to.equal('Incorrect username'); // It should first check the username expect(result.message).to.equal("Incorrect username"); // It should first check the username
testOrder = 4; testOrder = 4;
}); });
}); });
describe('Login with cookies', function () { describe("Login with cookies", function () {
//#region Set-up //#region Set-up
this.timeout(30000); // All tests in this suite get 30 seconds before timeout this.timeout(30000); // All tests in this suite get 30 seconds before timeout
before('Log in to create cookies then logout', async function () { before("Log in to create cookies then logout", async function () {
// Runs once before the first test in this block // Runs once before the first test in this block
if (!fs.existsSync(COOKIES_SAVE_PATH)) if (!fs.existsSync(COOKIES_SAVE_PATH))
await F95API.login(USERNAME, PASSWORD); // Download cookies await F95API.login(USERNAME, PASSWORD); // Download cookies
@ -93,25 +93,25 @@ describe('Login with cookies', function () {
}); });
//#endregion Set-up //#endregion Set-up
it('Test with valid credentials', async function () { it("Test with valid credentials", async function () {
const result = await F95API.login(USERNAME, PASSWORD); const result = await F95API.login(USERNAME, PASSWORD);
expect(result.success).to.be.true; expect(result.success).to.be.true;
expect(result.message).equal('Logged with cookies'); expect(result.message).equal("Logged with cookies");
}); });
}); });
describe('Load base data without cookies', function () { describe("Load base data without cookies", function () {
//#region Set-up //#region Set-up
this.timeout(30000); // All tests in this suite get 30 seconds before timeout this.timeout(30000); // All tests in this suite get 30 seconds before timeout
before('Delete cache if exists', function () { before("Delete cache if exists", function () {
// Runs once before the first test in this block // Runs once before the first test in this block
if (fs.existsSync(ENGINES_SAVE_PATH)) fs.unlinkSync(ENGINES_SAVE_PATH); if (fs.existsSync(ENGINES_SAVE_PATH)) fs.unlinkSync(ENGINES_SAVE_PATH);
if (fs.existsSync(STATUSES_SAVE_PATH)) fs.unlinkSync(STATUSES_SAVE_PATH); if (fs.existsSync(STATUSES_SAVE_PATH)) fs.unlinkSync(STATUSES_SAVE_PATH);
}); });
//#endregion Set-up //#endregion Set-up
it('With login', async function () { it("With login", async function () {
const loginResult = await F95API.login(USERNAME, PASSWORD); const loginResult = await F95API.login(USERNAME, PASSWORD);
expect(loginResult.success).to.be.true; expect(loginResult.success).to.be.true;
@ -125,24 +125,24 @@ describe('Load base data without cookies', function () {
expect(statusesCacheExists).to.be.true; expect(statusesCacheExists).to.be.true;
}); });
it('Without login', async function () { it("Without login", async function () {
if (F95API.isLogged()) F95API.logout(); if (F95API.isLogged()) F95API.logout();
const result = await F95API.loadF95BaseData(); const result = await F95API.loadF95BaseData();
expect(result).to.be.false; expect(result).to.be.false;
}); });
}); });
describe('Search game data', function () { describe("Search game data", function () {
//#region Set-up //#region Set-up
this.timeout(60000); // All tests in this suite get 60 seconds before timeout this.timeout(60000); // All tests in this suite get 60 seconds before timeout
beforeEach('Prepare API', function () { beforeEach("Prepare API", function () {
// Runs once before the first test in this block // Runs once before the first test in this block
if (F95API.isLogged()) F95API.logout(); if (F95API.isLogged()) F95API.logout();
}); });
//#endregion Set-up //#endregion Set-up
it('Search game when logged', async function () { it("Search game when logged", async function () {
const loginResult = await F95API.login(USERNAME, PASSWORD); const loginResult = await F95API.login(USERNAME, PASSWORD);
expect(loginResult.success).to.be.true; expect(loginResult.success).to.be.true;
@ -151,30 +151,30 @@ describe('Search game data', function () {
// This test depend on the data on F95Zone at // This test depend on the data on F95Zone at
// https://f95zone.to/threads/kingdom-of-deception-v0-10-8-hreinn-games.2733/ // https://f95zone.to/threads/kingdom-of-deception-v0-10-8-hreinn-games.2733/
const gamesList = await F95API.getGameData('Kingdom of Deception', false); const gamesList = await F95API.getGameData("Kingdom of Deception", false);
expect(gamesList.length, 'Should find only the game').to.equal(1); expect(gamesList.length, "Should find only the game").to.equal(1);
const result = gamesList[0]; const result = gamesList[0];
const src = 'https://attachments.f95zone.to/2018/09/162821_f9nXfwF.png'; const src = "https://attachments.f95zone.to/2018/09/162821_f9nXfwF.png";
// Test only the main information // Test only the main information
expect(result.name).to.equal('Kingdom of Deception'); expect(result.name).to.equal("Kingdom of Deception");
expect(result.author).to.equal('Hreinn Games'); expect(result.author).to.equal("Hreinn Games");
expect(result.isMod, 'Should be false').to.be.false; expect(result.isMod, "Should be false").to.be.false;
expect(result.engine).to.equal('REN\'PY'); expect(result.engine).to.equal("REN'PY");
expect(result.previewSource).to.equal(src); // Could be null -> Why sometimes doesn't get the image? expect(result.previewSource).to.equal(src); // Could be null -> Why sometimes doesn't get the image?
}); });
it('Search game when not logged', async function () { it("Search game when not logged", async function () {
const result = await F95API.getGameData('Kingdom of Deception', false); const result = await F95API.getGameData("Kingdom of Deception", false);
expect(result, 'Without being logged should return null').to.be.null; expect(result, "Without being logged should return null").to.be.null;
}); });
}); });
describe('Load user data', function () { describe("Load user data", function () {
//#region Set-up //#region Set-up
this.timeout(30000); // All tests in this suite get 30 seconds before timeout this.timeout(30000); // All tests in this suite get 30 seconds before timeout
//#endregion Set-up //#endregion Set-up
it('Retrieve when logged', async function () { it("Retrieve when logged", async function () {
// Login // Login
await F95API.login(USERNAME, PASSWORD); await F95API.login(USERNAME, PASSWORD);
@ -184,7 +184,7 @@ describe('Load user data', function () {
expect(data).to.exist; expect(data).to.exist;
expect(data.username).to.equal(USERNAME); expect(data.username).to.equal(USERNAME);
}); });
it('Retrieve when not logged', async function () { it("Retrieve when not logged", async function () {
// Logout // Logout
if (F95API.isLogged()) F95API.logout(); if (F95API.isLogged()) F95API.logout();
@ -195,12 +195,12 @@ describe('Load user data', function () {
}); });
}); });
describe('Check game update', function () { describe("Check game update", function () {
//#region Set-up //#region Set-up
this.timeout(30000); // All tests in this suite get 30 seconds before timeout this.timeout(30000); // All tests in this suite get 30 seconds before timeout
//#endregion Set-up //#endregion Set-up
it('Get online game and verify that no update exists', async function () { it("Get online game and verify that no update exists", async function () {
const loginResult = await F95API.login(USERNAME, PASSWORD); const loginResult = await F95API.login(USERNAME, PASSWORD);
expect(loginResult.success).to.be.true; expect(loginResult.success).to.be.true;
@ -209,22 +209,22 @@ describe('Check game update', function () {
// This test depend on the data on F95Zone at // This test depend on the data on F95Zone at
// https://f95zone.to/threads/kingdom-of-deception-v0-10-8-hreinn-games.2733/ // https://f95zone.to/threads/kingdom-of-deception-v0-10-8-hreinn-games.2733/
const result = (await F95API.getGameData('Kingdom of Deception', false))[0]; const result = (await F95API.getGameData("Kingdom of Deception", false))[0];
const update = await F95API.chekIfGameHasUpdate(result); const update = await F95API.chekIfGameHasUpdate(result);
expect(update).to.be.false; expect(update).to.be.false;
}); });
it('Verify that update exists from old URL', async function () { it("Verify that update exists from old URL", async function () {
const loginResult = await F95API.login(USERNAME, PASSWORD); const loginResult = await F95API.login(USERNAME, PASSWORD);
expect(loginResult.success).to.be.true; expect(loginResult.success).to.be.true;
// This test depend on the data on F95Zone at // This test depend on the data on F95Zone at
// https://f95zone.to/threads/perverted-education-v0-9701-april-ryan.1854/ // https://f95zone.to/threads/perverted-education-v0-9701-april-ryan.1854/
const url = const url =
'https://f95zone.to/threads/perverted-education-v0-9701-april-ryan.1854/'; "https://f95zone.to/threads/perverted-education-v0-9701-april-ryan.1854/";
const result = await F95API.getGameDataFromURL(url); const result = await F95API.getGameDataFromURL(url);
result.version = '0.9600'; result.version = "0.9600";
const update = await F95API.chekIfGameHasUpdate(result); const update = await F95API.chekIfGameHasUpdate(result);
expect(update).to.be.true; expect(update).to.be.true;

View File

@ -1,4 +1,4 @@
const { join } = require('path'); const { join } = require("path");
const { const {
debug, debug,
login, login,
@ -14,11 +14,11 @@ main();
//downloadGameMEGA(); //downloadGameMEGA();
async function main() { async function main() {
const loginResult = await login('MillenniumEarl', 'f9vTcRNuvxj4YpK'); const loginResult = await login("MillenniumEarl", "f9vTcRNuvxj4YpK");
if (loginResult.success) { if (loginResult.success) {
await loadF95BaseData(); await loadF95BaseData();
const gameData = await getGameData('queen\'s brothel', false); const gameData = await getGameData("queen's brothel", false);
console.log(gameData); console.log(gameData);
// let userData = await getUserData(); // let userData = await getUserData();
@ -29,10 +29,10 @@ async function main() {
async function downloadGameMEGA() { async function downloadGameMEGA() {
const gd = new GameDownload(); const gd = new GameDownload();
gd.hosting = 'NOPY'; gd.hosting = "NOPY";
gd.link = gd.link =
'https://f95zone.to/masked/mega.nz/2733/1470797/4O5LKwMx4ZSlw0QYTVMP0uDK660/hoobTb44f0IKx7Yio2SE2w/loX_px2vLRyNRQCnkNn5U7nnQe7jGmpEVERvH1tk7RjAFkQbs2kH_vCK6zVmRDuqiypPoIx358MNHHCd3QCdVvEsClSiAq4rwjK0r_ruXIs'; "https://f95zone.to/masked/mega.nz/2733/1470797/4O5LKwMx4ZSlw0QYTVMP0uDK660/hoobTb44f0IKx7Yio2SE2w/loX_px2vLRyNRQCnkNn5U7nnQe7jGmpEVERvH1tk7RjAFkQbs2kH_vCK6zVmRDuqiypPoIx358MNHHCd3QCdVvEsClSiAq4rwjK0r_ruXIs";
const savepath = join(__dirname, 'Kingdom_of_Deception-pc0.10.8.zip'); const savepath = join(__dirname, "Kingdom_of_Deception-pc0.10.8.zip");
const result = await gd.download(savepath); const result = await gd.download(savepath);
console.log(result); console.log(result);
} }