Add user and auth tests
This commit is contained in:
parent
72d7b22891
commit
4bc3be87b4
15 changed files with 288 additions and 26 deletions
56
tests/api.js
Normal file
56
tests/api.js
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import config from "../src/config.json" with { type: "json" };
|
||||
|
||||
const url = `http://localhost:${config.port}/api/v1`;
|
||||
|
||||
const apiGet = async (endpoint, token) => {
|
||||
const response = await fetch(`${url}/${endpoint}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
return await response.json();
|
||||
};
|
||||
|
||||
const apiPost = async (endpoint, request, token) => {
|
||||
const response = await fetch(`${url}/${endpoint}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
|
||||
return await response.json();
|
||||
};
|
||||
|
||||
const apiPatch = async (endpoint, request, token) => {
|
||||
const response = await fetch(`${url}/${endpoint}`, {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
|
||||
return await response.json();
|
||||
};
|
||||
|
||||
const apiDelete = async (endpoint, request, token) => {
|
||||
const response = await fetch(`${url}/${endpoint}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
|
||||
return await response.json();
|
||||
};
|
||||
|
||||
export { apiGet, apiPost, apiPatch, apiDelete };
|
||||
Loading…
Add table
Add a link
Reference in a new issue