Added tests for PrefixParser

pull/57/head
MillenniumEarl 2020-12-03 12:38:46 +01:00
parent fdd452b5db
commit 50d868d96d
3 changed files with 11 additions and 15 deletions

View File

@ -22,7 +22,7 @@
"user data"
],
"scripts": {
"unit-test-mocha": "nyc --reporter=text mocha './test/index-test.js'",
"test": "nyc --reporter=text mocha './test/index-test.js'",
"report-coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov -t 38ad72bf-a29d-4c2e-9827-96cbe037afd2",
"run-example": "node ./app/example.js",
"publish": "npm publish"

View File

@ -7,7 +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;
const prefixParser = require("./suites/prefix-parser-test.js").suite;
describe("Test basic function", function testBasic() {
//#region Set-up
@ -16,7 +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 prefix parser", prefixParser.bind(this));
});
describe("Test F95 modules", function testF95Modules() {

View File

@ -7,7 +7,7 @@ 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 PrefixParser = require("../../app/scripts/classes/prefix-parser.js");
const { authenticate } = require("../../app/scripts/network-helper.js");
// Configure the .env reader
@ -27,21 +27,17 @@ module.exports.suite = function suite() {
});
//#endregion Setup
it("Fetch tags and parse", async function testTagParser() {
it("Parse prefixes", async function testPrefixParser() {
// Create a new parser
const tp = new TagParser();
await tp.fetch();
const parser = new PrefixParser();
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 testPrefixes = ["corruption", "pregnancy", "slave", "VN", "RPGM", "Ren'Py", "Abandoned"];
const ids = parser.prefixesToIDs(testPrefixes);
const tags = parser.idsToPrefixes(ids);
const tagsEquality = isEqual(testTags, tags);
const tagsEquality = isEqual(testPrefixes, tags);
expect(tagsEquality, "The tags must be the same").to.be.true;
const idsEquality = isEqual([44, 103, 225], ids);
const idsEquality = isEqual([103, 225, 44, 13, 2, 7, 22], ids);
expect(idsEquality, "The IDs must be the same").to.be.true;
});
};