-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetchMock.js
33 lines (28 loc) · 915 Bytes
/
fetchMock.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
const { writeFileSync, mkdirSync } = require("fs");
const { resolve } = require("path");
const baseUrl = process.env.API_BASE_URL || "https://api.nature.global/";
const headers = {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.ACCESS_TOKEN}`,
};
try {
mkdirSync(resolve(__dirname, "mocks/1/users"), { recursive: true });
} catch (e) {
console.warn(e);
}
fetch(`${baseUrl}1/users/me`, { headers })
.then((res) => res.text())
.then((body) => {
writeFileSync(resolve(__dirname, "mocks/1/users/me"), body);
});
fetch(`${baseUrl}1/appliances`, { headers })
.then((res) => res.text())
.then((body) => {
writeFileSync(resolve(__dirname, "mocks/1/appliances"), body);
});
fetch(`${baseUrl}1/devices`, { headers })
.then((res) => res.text())
.then((body) => {
writeFileSync(resolve(__dirname, "mocks/1/devices"), body);
});