-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
44 lines (36 loc) · 1.08 KB
/
test.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
const dotenv = require('dotenv');
const httpsRequest = require('./index.js');
dotenv.config();
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;
Promise.resolve()
.then(() => {
return httpsRequest({
headers: { 'Accept': 'application/json' },
host: process.env.BASE_HOST,
method: 'POST',
path: process.env.BASE_PATH
}, { test: 'test' }).then(({ response: { statusCode }, data }) => {
if (statusCode !== 201) {
throw data;
}
const json = JSON.parse(data);
console.table(Object.keys(json).map((key) => ({ key, value: json[key] })));
});
})
.then(() => {
return httpsRequest({
headers: { 'Accept': 'application/json' },
host: process.env.BASE_HOST,
method: 'GET',
path: process.env.BASE_PATH
}).then(({ response: { statusCode }, data }) => {
if (statusCode !== 200) {
throw data;
}
const json = JSON.parse(data);
console.table(json.value.map(({ __CreatedOn, __ModifiedOn, __Owner, __Status, id, test }) => {
return { __CreatedOn, __ModifiedOn, __Owner, __Status, id, test };
}));
});
})
.catch((error) => console.error(error));