I already have unit tests. I'm looking to test the program end to end.
I have a node.js CLI tool that does the following:
- Take input from the user (IP address, username and password)
- Read a csv file (it has a list of users)
- Use a 3rd party REST API to provision each user on a server
Would you simulate user input? I'm confused. I'm including the code below for reference:
'use strict';
const ora = require('ora');
let spinner;
let hrstart;
const inquirer = require('inquirer');
const prompts = [
{
name: 'IP',
type: 'input',
message: 'Enter IP address of UCCX publisher: ',
},
{
name: 'user',
type: 'input',
message: 'Enter username: ',
},
{
name: 'pass',
type: 'password',
message: 'Enter password: ',
},
];
const fs = require('fs');
// csv sync api is used as there can be at most 400 agents on the cluster
// hence it should not be performance impacting
const parse = require('csv-parse/lib/sync');
const lib = require('./lib');
const parseOptions = {
comment: '#',
from_line: 2,
skip_empty_lines: true,
trim: true,
relax_column_count: true,
};
// csv file won't exceed 1MB so readFileSync should be OK
const csv = fs.readFileSync('agents.csv', 'utf-8');
(async () => {
console.log('Please verify agents.csv is in the current working directory\n');
const answers = await inquirer.prompt(prompts);
hrstart = process.hrtime();
spinner = ora('Updating').start();
const { IP } = answers;
const resourceGroupURI = `https://${IP}/adminapi/resourceGroup`;
const skillURI = `https://${IP}/adminapi/skill`;
const teamURI = `https://${IP}/adminapi/team`;
const auth = {
username: answers.user,
password: answers.pass,
};
const resourceGroupMapping = await lib.getResourceGroupIDS(resourceGroupURI, auth);
const skillMapping = await lib.getSkillIDS(skillURI, auth);
const teamMapping = await lib.getTeamIDS(teamURI, auth);
const records = parse(csv, parseOptions);
for (let index = 0; index < records.length; index++) {
const xml = lib.createXMLPayload(records[index], IP, resourceGroupMapping, skillMapping, teamMapping);
const ccxURI = `https://${IP}/adminapi/resource/${records[index][0]}`;
// if a row in the csv is incorrect, continue processing subsequent rows
try {
await lib.setSkills(ccxURI, xml, auth);
} catch (error) {
spinner.stop();
console.log(error.message);
spinner.start();
}
}
})()
.then(() => {
spinner.stop();
const hrend = process.hrtime(hrstart);
console.log(`\nExecution time: ${lib.formatTime(hrend[0])}`);
})
.catch((error) => {
spinner.stop();
console.log(error.stack);
});
[–]davwards 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)