F95API/test/suites/user-scraper-test.js

55 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-11-02 14:06:09 +00:00
"use strict";
// Public module from npm
const expect = require("chai").expect;
const dotenv = require("dotenv");
// Modules from file
const Credentials = require("../../app/scripts/classes/credentials.js");
const uScraper = require("../../app/scripts/user-scraper.js");
2020-12-17 21:44:46 +00:00
const { authenticate } = require("../../app/scripts/network-helper.js");
const { fetchPlatformData } = require("../../app/scripts/platform-data.js");
2020-11-02 14:06:09 +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() {
// TODO:
// This method should delete the store F95Zone cookies,
// but what if the other tests require them?
// it("Fetch data when not logged", async function fetchUserDataWhenLogged() {
// const data = await uScraper.getUserData();
// expect(data.username).to.be.equal("");
// expect(data.avatarSrc).to.be.equal("");
// expect(data.watchedThreads.length).to.be.equal(0);
// });
it("Fetch data when logged", async function fetchUserDataWhenNotLogged() {
// Authenticate
const result = await auth();
expect(result.success, "Authentication should be successful").to.be.true;
// We test only for the username, the other test data depends on the user logged
const data = await uScraper.getUserData();
expect(data.username).to.be.equal(USERNAME);
});
};
//#region Private methods
/**
* @private
* Simple wrapper for authentication.
*/
async function auth() {
const creds = new Credentials(USERNAME, PASSWORD);
await creds.fetchToken();
2020-12-17 21:44:46 +00:00
const result = await authenticate(creds);
if (result.success) await fetchPlatformData();
return result;
2020-11-02 14:06:09 +00:00
}
//#endregion Private methods