Added tests and ignored not useful code

pull/47/head
MillenniumEarl 2020-11-22 10:42:43 +01:00
parent 8bde0bd1b4
commit 8468269fd3
3 changed files with 41 additions and 1 deletions

View File

@ -54,6 +54,7 @@ const USER_NOT_LOGGED = "User not authenticated, unable to continue";
* @returns {Promise<LoginResult>} Result of the operation
*/
module.exports.login = async function (username, password) {
/* istanbul ignore next */
if (shared.isLogged) {
shared.logger.info(`${username} already authenticated`);
return new LoginResult(true, `${username} already authenticated`);
@ -81,6 +82,7 @@ module.exports.login = async function (username, password) {
* @returns {Promise<Boolean>} true if an update is available, false otherwise
*/
module.exports.checkIfGameHasUpdate = async function (info) {
/* istanbul ignore next */
if (!shared.isLogged) {
shared.logger.warn(USER_NOT_LOGGED);
return false;
@ -109,6 +111,7 @@ module.exports.checkIfGameHasUpdate = async function (info) {
* an identified game (in the case of homonymy of titles)
*/
module.exports.getGameData = async function (name, mod) {
/* istanbul ignore next */
if (!shared.isLogged) {
shared.logger.warn(USER_NOT_LOGGED);
return null;
@ -138,6 +141,7 @@ module.exports.getGameData = async function (name, mod) {
* @returns {Promise<GameInfo>} Information about the game. If no game was found, null is returned
*/
module.exports.getGameDataFromURL = async function (url) {
/* istanbul ignore next */
if (!shared.isLogged) {
shared.logger.warn(USER_NOT_LOGGED);
return null;
@ -159,6 +163,7 @@ module.exports.getGameDataFromURL = async function (url) {
* @returns {Promise<UserData>} Data of the user currently logged in
*/
module.exports.getUserData = async function () {
/* istanbul ignore next */
if (!shared.isLogged) {
shared.logger.warn(USER_NOT_LOGGED);
return null;

View File

@ -63,6 +63,7 @@ class TagParser {
for(const tag of tags) {
// Extract the key from the value
const key = this._getKeyByValue(this._tagsDict, tag);
/* istanbul ignore next */
if(key) ids.push(parseInt(key));
}
return ids.sort((a, b) => a - b); // JS sort alphabetically, same old problem
@ -78,6 +79,7 @@ class TagParser {
for(const id of ids) {
// Check if the key exists in the dict
const exist = id in this._tagsDict;
/* istanbul ignore next */
if (!exist) continue;
// Save the value

View File

@ -20,6 +20,7 @@ const PASSWORD = process.env.F95_PASSWORD;
module.exports.suite = function suite() {
// Global suite variables
const gameURL = "https://f95zone.to/threads/perverted-education-v0-9601-april-ryan.1854/";
const updatedGameURL = "https://f95zone.to/threads/noxian-nights-v1-2-4-hreinn-games.2/";
it("Test login", async function testLogin() {
const result = await F95API.login(USERNAME, PASSWORD);
@ -32,7 +33,7 @@ module.exports.suite = function suite() {
expect(userdata.username).to.be.equal(USERNAME);
});
it("Test game update checking", async function testGameUpdateCheck() {
it("Test game for existing update", async function checkUpdateByURL() {
// We force the creation of a GameInfo object,
// knowing that the checkIfGameHasUpdate() function
// only needs the game URL
@ -46,6 +47,38 @@ module.exports.suite = function suite() {
expect(update).to.be.true;
});
it("Test game for non existing update", async function checkUpdateByVersion() {
// We force the creation of a GameInfo object,
// knowing that the checkIfGameHasUpdate() function
// only needs the game URL
const info = new F95API.GameInfo();
// The updatedGameURL identifies a game for which
// we know there is **not** an update
info.url = updatedGameURL;
info.version = "1.2.4"; // The hame is marked as "Completed" so it shouldn't change it's version
// Check for updates
const update = await F95API.checkIfGameHasUpdate(info);
expect(update).to.be.false;
});
it("Test game for fake update", async function checkFakeUpdateByVersion() {
// We force the creation of a GameInfo object,
// knowing that the checkIfGameHasUpdate() function
// only needs the game URL
const info = new F95API.GameInfo();
// The updatedGameURL identifies a game for which
// we know there is **not** an update
info.url = updatedGameURL;
info.version = "ThisIsAFakeVersion"; // The real version is "1.2.4"
// Check for updates
const update = await F95API.checkIfGameHasUpdate(info);
expect(update).to.be.true;
});
it("Test game data fetching", async function testGameDataFetch() {
// Search a game by name
const gameList = await F95API.getGameData("perverted education", false);