From cc7ce0cb5d4b9b369f5c76ac6d6a1289ace3b3e2 Mon Sep 17 00:00:00 2001 From: flx-sta <50131232+flx-sta@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:12:11 -0700 Subject: [PATCH] remove: Utils.apiFetch --- src/test/misc.test.ts | 26 +++++++++++++------------- src/utils.ts | 15 --------------- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/src/test/misc.test.ts b/src/test/misc.test.ts index e46577b7bc3..149b6ac5930 100644 --- a/src/test/misc.test.ts +++ b/src/test/misc.test.ts @@ -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"); diff --git a/src/utils.ts b/src/utils.ts index 7e5c043c37b..1ea1407c3e8 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -331,21 +331,6 @@ export async function localPing() { } } -export function apiFetch(path: string, authed: boolean = false): Promise { - 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 { return (isLocal && isLocalServerConnected) || !isLocal ? new Promise((resolve, reject) => { const headers = {