Skip to content

Commit

Permalink
feat(test): add e2e test for timeout on config
Browse files Browse the repository at this point in the history
This PR adds an E2E test to simulate timeout being part of the config

Needs to be merged after
([#11](#11))
  • Loading branch information
barbmarcio authored Aug 13, 2024
1 parent 7b16485 commit e4d858c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
49 changes: 43 additions & 6 deletions e2e/auctions.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, test } from "@playwright/test";
import { delay } from "msw";
import { baseURL, endpoints } from "../src/constants/endpoints.constant";
import { playwrightConstants } from "./config";

Expand Down Expand Up @@ -47,9 +48,6 @@ test.describe("Create Auction via Topsort SDK", () => {
},
],
};
if (typeof window.sdk.createAuction === "undefined") {
throw new Error("Global function `createAuction` is not available.");
}

return window.sdk.createAuction(config, auctionDetails);
});
Expand Down Expand Up @@ -88,13 +86,52 @@ test.describe("Create Auction via Topsort SDK", () => {
},
],
};
if (typeof window.sdk.createAuction === "undefined") {
throw new Error("Global function `createAuction` is not available.");
}

return window.sdk.createAuction(config, auctionDetails);
});

expect(result).toEqual(expectedError);
});

test("should have a delay when being called with timeout parameter", async ({ page }) => {
const errorsList = [
"signal is aborted without reason",
"The operation was aborted. ",
"Fetch is aborted",
];

const hasMatchingError = (actualError: any): boolean => {
return errorsList.some((error) => error === actualError.body);
};

await page.route(`${baseURL}/${endpoints.auctions}`, async (route) => {
await delay(100);
await route.abort();
});

await page.goto(playwrightConstants.host);

const result = await page.evaluate(async () => {
const config = {
apiKey: "rando-api-key",
timeout: 50,
};

const auctionDetails = {
auctions: [
{
type: "listings",
slots: 3,
category: { id: "cat123" },
geoTargeting: { location: "US" },
},
],
};

return window.sdk.createAuction(config, auctionDetails);
});

const isErrorFound = hasMatchingError(result);
expect(isErrorFound).toBeTruthy();
});
});
7 changes: 0 additions & 7 deletions e2e/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ test.describe("Report Events via Topsort SDK", () => {
],
};

if (typeof window.sdk.reportEvent === "undefined") {
throw new Error("Global function `reportEvent` is not available.");
}

return window.sdk.reportEvent(config, event);
});

Expand Down Expand Up @@ -71,9 +67,6 @@ test.describe("Report Events via Topsort SDK", () => {
},
],
};
if (typeof window.sdk.reportEvent === "undefined") {
throw new Error("Global function `reportEvent` is not available.");
}

return window.sdk.reportEvent(config, event);
});
Expand Down

0 comments on commit e4d858c

Please sign in to comment.