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 @@