Added test for tag parser
parent
aae153caa7
commit
0b73bef720
|
@ -7,6 +7,7 @@ const network = require("./suites/network-helper-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;
|
||||
const tags = require("./suites/tag-parser-test.js").suite;
|
||||
|
||||
describe("Test basic function", function testBasic() {
|
||||
//#region Set-up
|
||||
|
@ -15,6 +16,7 @@ describe("Test basic function", function testBasic() {
|
|||
|
||||
describe("Test credentials class", credentials.bind(this));
|
||||
describe("Test network helper", network.bind(this));
|
||||
describe("Test tag parser", tags.bind(this));
|
||||
});
|
||||
|
||||
describe("Test F95 modules", function testF95Modules() {
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
"use strict";
|
||||
|
||||
// Public module from npm
|
||||
const expect = require("chai").expect;
|
||||
const dotenv = require("dotenv");
|
||||
const { isEqual } = require("lodash");
|
||||
|
||||
// Modules from file
|
||||
const Credentials = require("../../app/scripts/classes/credentials.js");
|
||||
const TagParser = require("../../app/scripts/classes/tag-parser.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 tags and parse", async function testTagParser() {
|
||||
// Create a new parser
|
||||
const tp = new TagParser();
|
||||
await tp.fetch();
|
||||
|
||||
const dictEquality = isEqual(tp._tagsDict, {});
|
||||
expect(dictEquality, "The dictionary should be filled with values").to.be.false;
|
||||
|
||||
const testTags = ["corruption", "pregnancy", "slave"];
|
||||
const ids = tp.tagsToIDs(testTags);
|
||||
const tags = tp.idsToTags(ids);
|
||||
|
||||
const tagsEquality = isEqual(testTags, tags);
|
||||
expect(tagsEquality, "The tags must be the same").to.be.true;
|
||||
const idsEquality = isEqual([44, 103, 225], ids);
|
||||
expect(idsEquality, "The IDs must be the same").to.be.true;
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue