Add helper functions

pull/77/head
MillenniumEarl 2021-03-10 15:12:47 +01:00
parent 0924cedbb1
commit b3db3fa659
1 changed files with 38 additions and 0 deletions

38
test/helpers.ts Normal file
View File

@ -0,0 +1,38 @@
"use strict";
// Public modules from npm
import dotenv from "dotenv";
import inquirer from "inquirer";
// Modulee from files
import { login } from "../src/index";
import LoginResult from "../src/scripts/classes/login-result";
// Configure the .env reader
dotenv.config();
export async function auth(): Promise<LoginResult> {
return login(process.env.F95_USERNAME, process.env.F95_PASSWORD, insert2faCode);
}
//#region Private methods
/**
* Ask the user to enter the OTP code
* necessary to authenticate on the server.
*/
async function insert2faCode(): Promise<number> {
const questions = [
{
type: "input",
name: "code",
message: "Insert 2FA code:"
}
];
// Prompt the user to insert the code
const answers = await inquirer.prompt(questions);
return answers.code as number;
}
//#endregion Private methods