Implemented runner generation using fakerjs

ref #19
This commit is contained in:
Nicolai Ort 2021-02-08 18:08:01 +01:00
parent e3a45a61ac
commit 0894446085
2 changed files with 19 additions and 1 deletions

View File

@ -64,6 +64,7 @@
"@types/node": "^14.14.22",
"@types/puppeteer": "^5.4.3",
"cp-cli": "^2.0.0",
"faker": "^5.3.1",
"nodemon": "^2.0.7",
"release-it": "^14.2.2",
"rimraf": "^3.0.2",

View File

@ -1,5 +1,7 @@
import axios from "axios"
import faker from "faker"
import { Runner } from '../models/Runner'
import { RunnerGroup } from '../models/RunnerGroup'
const baseurl = "http://localhost:4010"
@ -16,6 +18,21 @@ axios.interceptors.response.use((response) => {
return response
})
function generateRunners(amount: number): Runner[] {
let runners: Runner[] = new Array<Runner>();
let group = new RunnerGroup();
let runner = new Runner();
for (var i = 0; i < amount; i++) {
group.name = faker.company.bsBuzz();
group.id = Math.floor(Math.random() * (9999999 - 1) + 1);
runner.firstname = faker.name.firstName();
runner.lastname = faker.name.lastName();
runner.id = Math.floor(Math.random() * (9999999 - 1) + 1);
runners.push(runner);
}
return runners;
}
async function postContracts(runners: Runner[]): Promise<Measurement> {
const res = await axios.post(`${baseurl}/contracts`, runners);
return new Measurement("contract", runners.length, parseInt(res.headers['request-duration']))
@ -23,7 +40,7 @@ async function postContracts(runners: Runner[]): Promise<Measurement> {
async function main() {
console.log((await axios.get("http://localhost:4010/version")).data)
console.log((await postContracts([])).toString())
console.log((await postContracts(generateRunners(100))).toString());
}
main();