diff --git a/e2e/auctions.test.ts b/e2e/auctions.test.ts index 1340a3c..1ed9e87 100644 --- a/e2e/auctions.test.ts +++ b/e2e/auctions.test.ts @@ -1,8 +1,8 @@ -import { expect, test } from "@playwright/test"; +import { test, expect } from '@playwright/test'; import { apis, baseURL } from "../src/constants/apis.constant"; -test.describe("Create Auction via Topsort.js", () => { - test("should create auction successfully", async ({ page }) => { +test.describe("Create Auction via Topsort SDK", () => { + test('should create an auction successfully', async ({ page }) => { const mockAPIResponse = { results: [ { @@ -21,13 +21,14 @@ test.describe("Create Auction via Topsort.js", () => { await page.route(`${baseURL}/${apis.auctions}`, async (route) => { await route.fulfill({ json: mockAPIResponse }); }); + + await page.goto('http://localhost:8080/e2e'); + const result = await page.evaluate(() => { + const config = { + apiKey: 'rando-api-key' + }; - await page.goto("http://localhost:8080/e2e/index.html"); - - await page.fill('input[name="apiKey"]', "your-api-key"); - await page.fill( - 'input[name="auctionDetails"]', - JSON.stringify({ + const auctionDetails = { auctions: [ { type: "listings", @@ -44,14 +45,14 @@ test.describe("Create Auction via Topsort.js", () => { geoTargeting: { location: "UK" }, }, ], - }), - ); + } + if (typeof window.sdk.createAuction === 'undefined') { + throw new Error('Global function `createAuctions` is not available.'); + } - await page.click('button[type="submit"]'); + return window.sdk.createAuction(config, auctionDetails); + }); - const response = await page.locator("#response").textContent(); - const jsonResponse = JSON.parse(response || "{}"); - expect(jsonResponse).toEqual(mockAPIResponse); - expect(jsonResponse).toEqual(mockAPIResponse); + expect(result).toEqual(mockAPIResponse); }); }); diff --git a/e2e/index.html b/e2e/index.html index 55a09d8..52f40ad 100644 --- a/e2e/index.html +++ b/e2e/index.html @@ -8,39 +8,16 @@

Test Topsort.js Integration

-
- - - -
-

     
   
 
diff --git a/global.d.ts b/global.d.ts
new file mode 100644
index 0000000..403b926
--- /dev/null
+++ b/global.d.ts
@@ -0,0 +1,5 @@
+interface Window {
+    sdk: {
+        createAuction: (a, b) => void;
+    };
+}
\ No newline at end of file
diff --git a/package.json b/package.json
index a3dfb3d..926bd26 100644
--- a/package.json
+++ b/package.json
@@ -24,6 +24,7 @@
     "CHANGELOG.md",
     "LICENSE",
     "README.md",
+    "dist/index.global.js",
     "dist/index.d.mts",
     "dist/index.d.ts",
     "dist/index.js",
diff --git a/playwright.config.ts b/playwright.config.ts
index 817ed77..352e5e8 100644
--- a/playwright.config.ts
+++ b/playwright.config.ts
@@ -4,7 +4,6 @@ export default defineConfig({
   testDir: "./e2e",
   timeout: 30000,
   retries: 1,
-  testMatch: "**/*.spec.ts",
   reporter: [["list"], ["json", { outputFile: "test-results.json" }]],
   use: {
     trace: "on-first-retry",