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" "user data"
], ],
"scripts": { "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", "report-coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov -t 38ad72bf-a29d-4c2e-9827-96cbe037afd2",
"run-example": "node ./app/example.js", "run-example": "node ./app/example.js",
"publish": "npm publish" "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 scraper = require("./suites/scraper-test.js").suite;
const searcher = require("./suites/searcher-test.js").suite; const searcher = require("./suites/searcher-test.js").suite;
const uScraper = require("./suites/user-scraper-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() { describe("Test basic function", function testBasic() {
//#region Set-up //#region Set-up
@ -16,7 +16,7 @@ describe("Test basic function", function testBasic() {
describe("Test credentials class", credentials.bind(this)); describe("Test credentials class", credentials.bind(this));
describe("Test network helper", network.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() { describe("Test F95 modules", function testF95Modules() {

View File

@ -7,7 +7,7 @@ const { isEqual } = require("lodash");
// Modules from file // Modules from file
const Credentials = require("../../app/scripts/classes/credentials.js"); 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"); const { authenticate } = require("../../app/scripts/network-helper.js");
// Configure the .env reader // Configure the .env reader
@ -27,21 +27,17 @@ module.exports.suite = function suite() {
}); });
//#endregion Setup //#endregion Setup
it("Fetch tags and parse", async function testTagParser() { it("Parse prefixes", async function testPrefixParser() {
// Create a new parser // Create a new parser
const tp = new TagParser(); const parser = new PrefixParser();
await tp.fetch();
const dictEquality = isEqual(tp._tagsDict, {}); const testPrefixes = ["corruption", "pregnancy", "slave", "VN", "RPGM", "Ren'Py", "Abandoned"];
expect(dictEquality, "The dictionary should be filled with values").to.be.false; const ids = parser.prefixesToIDs(testPrefixes);
const tags = parser.idsToPrefixes(ids);
const testTags = ["corruption", "pregnancy", "slave"];
const ids = tp.tagsToIDs(testTags);
const tags = tp.idsToTags(ids);
const tagsEquality = isEqual(testTags, tags); const tagsEquality = isEqual(testPrefixes, tags);
expect(tagsEquality, "The tags must be the same").to.be.true; 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; expect(idsEquality, "The IDs must be the same").to.be.true;
}); });
}; };