mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-01-19 07:20:57 +00:00
remove: Utils.apiFetch
This commit is contained in:
parent
565d80f262
commit
cc7ce0cb5d
@ -1,4 +1,4 @@
|
||||
import { apiFetch } from "#app/utils";
|
||||
// import { apiFetch } from "#app/utils";
|
||||
import GameManager from "#test/utils/gameManager";
|
||||
import { waitUntil } from "#test/utils/gameManagerUtils";
|
||||
import Phaser from "phaser";
|
||||
@ -35,18 +35,18 @@ describe("Test misc", () => {
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.skip("test apifetch mock async", async () => {
|
||||
const spy = vi.fn();
|
||||
await apiFetch("https://localhost:8080/account/info").then(response => {
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.ok).toBe(true);
|
||||
return response.json();
|
||||
}).then(data => {
|
||||
spy(); // Call the spy function
|
||||
expect(data).toEqual({ "username": "greenlamp", "lastSessionSlot": 0 });
|
||||
});
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
// it.skip("test apifetch mock async", async () => {
|
||||
// const spy = vi.fn();
|
||||
// await apiFetch("https://localhost:8080/account/info").then(response => {
|
||||
// expect(response.status).toBe(200);
|
||||
// expect(response.ok).toBe(true);
|
||||
// return response.json();
|
||||
// }).then(data => {
|
||||
// spy(); // Call the spy function
|
||||
// expect(data).toEqual({ "username": "greenlamp", "lastSessionSlot": 0 });
|
||||
// });
|
||||
// expect(spy).toHaveBeenCalled();
|
||||
// });
|
||||
|
||||
it("test fetch mock sync", async () => {
|
||||
const response = await fetch("https://localhost:8080/account/info");
|
||||
|
15
src/utils.ts
15
src/utils.ts
@ -331,21 +331,6 @@ export async function localPing() {
|
||||
}
|
||||
}
|
||||
|
||||
export function apiFetch(path: string, authed: boolean = false): Promise<Response> {
|
||||
return (isLocal && isLocalServerConnected) || !isLocal ? new Promise((resolve, reject) => {
|
||||
const request = {};
|
||||
if (authed) {
|
||||
const sId = getCookie(sessionIdKey);
|
||||
if (sId) {
|
||||
request["headers"] = { "Authorization": sId };
|
||||
}
|
||||
}
|
||||
fetch(`${apiUrl}/${path}`, request)
|
||||
.then(response => resolve(response))
|
||||
.catch(err => reject(err));
|
||||
}) : new Promise(() => {});
|
||||
}
|
||||
|
||||
export function apiPost(path: string, data?: any, contentType: string = "application/json", authed: boolean = false): Promise<Response> {
|
||||
return (isLocal && isLocalServerConnected) || !isLocal ? new Promise((resolve, reject) => {
|
||||
const headers = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user