-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrandom.js
71 lines (61 loc) · 1.97 KB
/
random.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const axios = require('axios');
const BASE_URL = 'https://localhost:8080';
const randomMethod = () => {
const METHODS = ['GET', 'POST', 'DELETE', 'PUT'];
const randIndex = Math.floor(Math.random() * (METHODS.length - 1));
return METHODS[randIndex];
};
const randomFaang = () => {
const FAANG = ['google', 'facebook', 'twitter', 'apple'];
const randIndex = Math.floor(Math.random() * (FAANG.length - 1));
return FAANG[randIndex];
};
const randomDevice = () => {
const DEVICES = ['iphone', 'motorola', 'nokia', 'pixel', 'samsung'];
const randIndex = Math.floor(Math.random() * (DEVICES.length - 1));
return DEVICES[randIndex];
};
const randomBody = () => {
return {
[randomFaang()]: Math.floor(Math.random() * 100),
[randomFaang()]: Math.floor(Math.random() * 100),
[randomFaang()]: Math.floor(Math.random() * 100),
[randomFaang()]: Math.floor(Math.random() * 100),
};
};
const fillTodos = async (max) => {
for (let i = 0; i <= max; i++) {
const url = i % 2 === 0 ? `${BASE_URL}/todo/${i}` : `${BASE_URL}/todos`;
try {
await axios(url, { method: randomMethod(), data: randomBody() });
} catch (e) {
console.error(url, e.message);
}
}
};
const fillCustomer = async (max) => {
for (let i = 0; i <= max; i++) {
const url = `${BASE_URL}/customer/${i}?device=${randomDevice()}`;
try {
await axios(url, {
method: randomMethod(),
headers: {
cookie: `Token=${Math.random() * 100};Marketing=true;`,
'x-customer': randomFaang(),
},
data: randomBody(),
});
} catch (e) {
console.error(url, e.message);
}
}
};
const github = async () => {
const url = `${BASE_URL}/users/sayjava`;
await axios(url, {
headers: { host: 'api.github.com' }
});
}
fillTodos(5);
fillCustomer(2);
github();