F95API/test/suites/prefix-parser-test.js

45 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-11-19 21:28:37 +00:00
"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");
2020-12-03 11:38:46 +00:00
const PrefixParser = require("../../app/scripts/classes/prefix-parser.js");
2020-11-19 21:28:37 +00:00
const { authenticate } = require("../../app/scripts/network-helper.js");
2020-12-17 21:44:46 +00:00
const { fetchPlatformData } = require("../../app/scripts/platform-data.js");
2020-11-19 21:28:37 +00:00
// 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);
2020-12-17 21:44:46 +00:00
await fetchPlatformData();
2020-11-19 21:28:37 +00:00
});
//#endregion Setup
2020-12-03 11:38:46 +00:00
it("Parse prefixes", async function testPrefixParser() {
2020-11-19 21:28:37 +00:00
// Create a new parser
2020-12-03 11:38:46 +00:00
const parser = new PrefixParser();
2020-11-19 21:28:37 +00:00
2020-12-03 11:38:46 +00:00
const testPrefixes = ["corruption", "pregnancy", "slave", "VN", "RPGM", "Ren'Py", "Abandoned"];
const ids = parser.prefixesToIDs(testPrefixes);
const tags = parser.idsToPrefixes(ids);
2020-11-19 21:28:37 +00:00
2020-12-03 11:38:46 +00:00
const tagsEquality = isEqual(testPrefixes, tags);
2020-11-19 21:28:37 +00:00
expect(tagsEquality, "The tags must be the same").to.be.true;
2020-12-03 11:38:46 +00:00
const idsEquality = isEqual([103, 225, 44, 13, 2, 7, 22], ids);
2020-11-19 21:28:37 +00:00
expect(idsEquality, "The IDs must be the same").to.be.true;
});
};