-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (47 loc) · 1.25 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const faker = require("faker");
const axios = require("axios");
const IDEA_GENERATOR = "https://appideagenerator.com/call.php";
const IDEA_API = "http://localhost:4000";
const randomInt = () => Math.floor(Math.random() * 10);
const generateIdea = async () => {
const {
data
} = await axios.get(IDEA_GENERATOR);
return data.replace(/\n/g, "");
};
const generateUser = async () => {
const {
data
} = await axios.post(`${IDEA_API}/register`, {
username: faker.internet.userName(),
password: "password"
});
return data.token;
};
const postNewIdea = async token => {
const idea = await generateIdea();
const {
data
} = await axios.post(
`${IDEA_API}/api/ideas`, {
idea,
description: faker.lorem.paragraph()
}, {
headers: {
authorization: `Bearer ${token}`
}
}
);
console.log(data);
return idea;
};
(async () => {
const randUsersNum = randomInt();
const randIdeaNum = randomInt();
for (let i = 0; i < randUsersNum; i++) {
const token = await generateUser();
for (let j = 0; j < randIdeaNum; j++) {
const idea = await postNewIdea(token);
}
}
})();