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