Add test for platform-data

pull/62/head
MillenniumEarl 2020-12-26 15:40:17 +01:00
parent 711f1852f3
commit fe7569b16f
2 changed files with 67 additions and 0 deletions

View File

@ -4,6 +4,7 @@
const api = require("./suites/api-test.js").suite;
const credentials = require("./suites/credentials-test.js").suite;
const network = require("./suites/network-helper-test.js").suite;
const platform = require("./suites/platform-data-test.js").suite;
const scraper = require("./suites/scraper-test.js").suite;
const searcher = require("./suites/searcher-test.js").suite;
const uScraper = require("./suites/user-scraper-test.js").suite;
@ -24,6 +25,7 @@ describe("Test F95 modules", function testF95Modules() {
this.timeout(15000); // All tests in this suite get 15 seconds before timeout
//#endregion Set-up
describe("Test platform data fetch", platform.bind(this));
describe("Test scraper methods", scraper.bind(this));
describe("Test searcher methods", searcher.bind(this));
describe("Test user scraper methods", uScraper.bind(this));

View File

@ -0,0 +1,65 @@
"use strict";
// Public module from npm
const expect = require("chai").expect;
const dotenv = require("dotenv");
const { isEqual } = require("lodash");
// Core modules
const fs = require("fs");
// Modules from file
const shared = require("../../app/scripts/shared.js");
const platform = require("../../app/scripts/platform-data.js");
const Credentials = require("../../app/scripts/classes/credentials.js");
const { authenticate } = require("../../app/scripts/network-helper.js");
// Configure the .env reader
dotenv.config();
// Global variables
const USERNAME = process.env.F95_USERNAME;
const PASSWORD = process.env.F95_PASSWORD;
module.exports.suite = function suite() {
//#region Setup
before(async function beforeAll() {
// Authenticate
const creds = new Credentials(USERNAME, PASSWORD);
await creds.fetchToken();
await authenticate(creds);
});
//#endregion Setup
it("Fetch new platform data", async function fetchNewPlatformData() {
// Delete the current platform data (if exists)
if(fs.existsSync(shared.cachePath)) fs.unlinkSync(shared.cachePath);
// Fetch data
await platform.fetchPlatformData();
// Check data
const enginesEquality = isEqual({}, shared.engines);
const statusEquality = isEqual({}, shared.statuses);
const tagsEquality = isEqual({}, shared.tags);
expect(enginesEquality, "Should not be empty").to.be.false;
expect(statusEquality, "Should not be empty").to.be.false;
expect(tagsEquality, "Should not be empty").to.be.false;
// Check if the file exists
expect(fs.existsSync(shared.cachePath)).to.be.true;
});
it("Fetch cached platform data", async function fetchCachedPlatformData() {
// Fetch data
await platform.fetchPlatformData();
// Check data
const enginesEquality = isEqual({}, shared.engines);
const statusEquality = isEqual({}, shared.statuses);
const tagsEquality = isEqual({}, shared.tags);
expect(enginesEquality, "Should not be empty").to.be.false;
expect(statusEquality, "Should not be empty").to.be.false;
expect(tagsEquality, "Should not be empty").to.be.false;
});
};