From 98e3b6082e16f1d81fee89c58d12035053b848b9 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Fri, 17 Feb 2023 19:58:25 -0900 Subject: [PATCH] fix accessor --- frontend/lib/api/__test__/user/stats.test.ts | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/frontend/lib/api/__test__/user/stats.test.ts b/frontend/lib/api/__test__/user/stats.test.ts index 67a7b00..719f14f 100644 --- a/frontend/lib/api/__test__/user/stats.test.ts +++ b/frontend/lib/api/__test__/user/stats.test.ts @@ -80,6 +80,13 @@ describe("group related statistics tests", () => { let tAPI: UserClient | undefined; const imports = importFileGenerator(TOTAL_ITEMS); + const api = (): UserClient => { + if (!tAPI) { + throw new Error("API not initialized"); + } + return tAPI; + }; + beforeAll(async () => { // -- Setup -- const { client } = await factories.client.singleUse(); @@ -92,17 +99,10 @@ describe("group related statistics tests", () => { expect(setupResp.status).toBe(204); }); - if (!tAPI) { - throw new Error("API is not defined"); - } - - // cast api to concrete type - const api = tAPI; - // Write to file system for debugging // fs.writeFileSync("test.csv", csv); test("Validate Group Statistics", async () => { - const { status, data } = await api.stats.group(); + const { status, data } = await api().stats.group(); expect(status).toBe(200); expect(data.totalItems).toEqual(TOTAL_ITEMS); @@ -124,7 +124,7 @@ describe("group related statistics tests", () => { } test("Validate Labels Statistics", async () => { - const { status, data } = await api.stats.labels(); + const { status, data } = await api().stats.labels(); expect(status).toBe(200); for (const label of data) { @@ -133,7 +133,7 @@ describe("group related statistics tests", () => { }); test("Validate Locations Statistics", async () => { - const { status, data } = await api.stats.locations(); + const { status, data } = await api().stats.locations(); expect(status).toBe(200); for (const location of data) { @@ -142,7 +142,7 @@ describe("group related statistics tests", () => { }); test("Validate Purchase Over Time", async () => { - const { status, data } = await api.stats.totalPriceOverTime(); + const { status, data } = await api().stats.totalPriceOverTime(); expect(status).toBe(200); expect(data.entries.length).toEqual(TOTAL_ITEMS); });