remove: Utils.apiFetch

This commit is contained in:
flx-sta 2024-10-03 17:12:11 -07:00
parent 565d80f262
commit cc7ce0cb5d
2 changed files with 13 additions and 28 deletions

View File

@ -1,4 +1,4 @@
import { apiFetch } from "#app/utils"; // import { apiFetch } from "#app/utils";
import GameManager from "#test/utils/gameManager"; import GameManager from "#test/utils/gameManager";
import { waitUntil } from "#test/utils/gameManagerUtils"; import { waitUntil } from "#test/utils/gameManagerUtils";
import Phaser from "phaser"; import Phaser from "phaser";
@ -35,18 +35,18 @@ describe("Test misc", () => {
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
}); });
it.skip("test apifetch mock async", async () => { // it.skip("test apifetch mock async", async () => {
const spy = vi.fn(); // const spy = vi.fn();
await apiFetch("https://localhost:8080/account/info").then(response => { // await apiFetch("https://localhost:8080/account/info").then(response => {
expect(response.status).toBe(200); // expect(response.status).toBe(200);
expect(response.ok).toBe(true); // expect(response.ok).toBe(true);
return response.json(); // return response.json();
}).then(data => { // }).then(data => {
spy(); // Call the spy function // spy(); // Call the spy function
expect(data).toEqual({ "username": "greenlamp", "lastSessionSlot": 0 }); // expect(data).toEqual({ "username": "greenlamp", "lastSessionSlot": 0 });
}); // });
expect(spy).toHaveBeenCalled(); // expect(spy).toHaveBeenCalled();
}); // });
it("test fetch mock sync", async () => { it("test fetch mock sync", async () => {
const response = await fetch("https://localhost:8080/account/info"); const response = await fetch("https://localhost:8080/account/info");

View File

@ -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> { export function apiPost(path: string, data?: any, contentType: string = "application/json", authed: boolean = false): Promise<Response> {
return (isLocal && isLocalServerConnected) || !isLocal ? new Promise((resolve, reject) => { return (isLocal && isLocalServerConnected) || !isLocal ? new Promise((resolve, reject) => {
const headers = { const headers = {