fix accessor

This commit is contained in:
Hayden 2023-02-17 19:58:25 -09:00
parent 82179cb397
commit 98e3b6082e
No known key found for this signature in database
GPG key ID: 17CF79474E257545

View file

@ -80,6 +80,13 @@ describe("group related statistics tests", () => {
let tAPI: UserClient | undefined; let tAPI: UserClient | undefined;
const imports = importFileGenerator(TOTAL_ITEMS); const imports = importFileGenerator(TOTAL_ITEMS);
const api = (): UserClient => {
if (!tAPI) {
throw new Error("API not initialized");
}
return tAPI;
};
beforeAll(async () => { beforeAll(async () => {
// -- Setup -- // -- Setup --
const { client } = await factories.client.singleUse(); const { client } = await factories.client.singleUse();
@ -92,17 +99,10 @@ describe("group related statistics tests", () => {
expect(setupResp.status).toBe(204); 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 // Write to file system for debugging
// fs.writeFileSync("test.csv", csv); // fs.writeFileSync("test.csv", csv);
test("Validate Group Statistics", async () => { test("Validate Group Statistics", async () => {
const { status, data } = await api.stats.group(); const { status, data } = await api().stats.group();
expect(status).toBe(200); expect(status).toBe(200);
expect(data.totalItems).toEqual(TOTAL_ITEMS); expect(data.totalItems).toEqual(TOTAL_ITEMS);
@ -124,7 +124,7 @@ describe("group related statistics tests", () => {
} }
test("Validate Labels Statistics", async () => { test("Validate Labels Statistics", async () => {
const { status, data } = await api.stats.labels(); const { status, data } = await api().stats.labels();
expect(status).toBe(200); expect(status).toBe(200);
for (const label of data) { for (const label of data) {
@ -133,7 +133,7 @@ describe("group related statistics tests", () => {
}); });
test("Validate Locations Statistics", async () => { test("Validate Locations Statistics", async () => {
const { status, data } = await api.stats.locations(); const { status, data } = await api().stats.locations();
expect(status).toBe(200); expect(status).toBe(200);
for (const location of data) { for (const location of data) {
@ -142,7 +142,7 @@ describe("group related statistics tests", () => {
}); });
test("Validate Purchase Over Time", async () => { 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(status).toBe(200);
expect(data.entries.length).toEqual(TOTAL_ITEMS); expect(data.entries.length).toEqual(TOTAL_ITEMS);
}); });