From e4d858ce22c2f160657b067ac4ee9b950355a0fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Barbosa?= <52362496+barbmarcio@users.noreply.github.com> Date: Tue, 13 Aug 2024 17:54:40 +0100 Subject: [PATCH] feat(test): add e2e test for timeout on config This PR adds an E2E test to simulate timeout being part of the config Needs to be merged after ([#11](https://github.com/Topsort/topsort.js/pull/11)) --- e2e/auctions.test.ts | 49 ++++++++++++++++++++++++++++++++++++++------ e2e/events.test.ts | 7 ------- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/e2e/auctions.test.ts b/e2e/auctions.test.ts index 116853f..4170d45 100644 --- a/e2e/auctions.test.ts +++ b/e2e/auctions.test.ts @@ -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"; @@ -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); }); @@ -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(); + }); }); diff --git a/e2e/events.test.ts b/e2e/events.test.ts index 4960cdf..f76a485 100644 --- a/e2e/events.test.ts +++ b/e2e/events.test.ts @@ -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); }); @@ -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); });