diff --git a/.gitignore b/.gitignore index ef229ed..aace4f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ coverage/ dist/ node_modules/ +test-results/ +test-results.json diff --git a/bun.lockb b/bun.lockb index 72143bc..70f493a 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/e2e/auctions.test.ts b/e2e/auctions.test.ts new file mode 100644 index 0000000..aba3152 --- /dev/null +++ b/e2e/auctions.test.ts @@ -0,0 +1,54 @@ +import { apis, baseURL } from '../src/constants/apis.constant'; +import { test, expect } from '@playwright/test' + +test.describe('Create Auction via Topsort.js', () => { + test('should create auction successfully', async ({ page }) => { + const mockAPIResponse = { + results: [ + { + resultType: "listings", + winners: [], + error: false, + }, + { + resultType: "banners", + winners: [], + error: false, + }, + ], + } + + await page.route(`${baseURL}/${apis.auctions}`, async route => { + await route.fulfill({ json: mockAPIResponse }); + }); + + 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({ + auctions: [ + { + type: "listings", + slots: 3, + category: { id: "cat123" }, + geoTargeting: { location: "US" }, + }, + { + type: "banners", + slots: 1, + device: "desktop", + slotId: "slot123", + category: { ids: ["cat1", "cat2"] }, + geoTargeting: { location: "UK" }, + }, + ], + })); + + await page.click('button[type="submit"]'); + + const response = await page.locator('#response').textContent(); + const jsonResponse = JSON.parse(response || '{}'); + expect(jsonResponse).toEqual(mockAPIResponse) + expect(jsonResponse).toEqual(mockAPIResponse); + }); +}); \ No newline at end of file diff --git a/e2e/index.html b/e2e/index.html new file mode 100644 index 0000000..55a09d8 --- /dev/null +++ b/e2e/index.html @@ -0,0 +1,46 @@ + + + + + + Topsort SDK Test Application + + + +

Test Topsort.js Integration

+
+ + + +
+

+    
+  
+
diff --git a/package.json b/package.json
index 5ce694e..6ab1394 100644
--- a/package.json
+++ b/package.json
@@ -32,13 +32,16 @@
   ],
   "scripts": {
     "build": "tsup",
+    "test:e2e": "playwright test",
     "format": "biome check",
     "format:fix": "biome check --write",
     "prepare": "lefthook install"
   },
   "devDependencies": {
     "@biomejs/biome": "1.8.3",
+    "@playwright/test": "^1.45.2",
     "@types/bun": "1.1.6",
+    "http-server": "^14.1.1",
     "lefthook": "1.7.2",
     "msw": "2.3.1",
     "tsup": "8.1.0",
diff --git a/playwright.config.ts b/playwright.config.ts
new file mode 100644
index 0000000..0ed5b16
--- /dev/null
+++ b/playwright.config.ts
@@ -0,0 +1,31 @@
+import { defineConfig, devices } from '@playwright/test';
+
+export default defineConfig({
+    testDir: './e2e',
+    timeout: 30000,
+    retries: 1,
+    reporter: [['list'], ['json', { outputFile: 'test-results.json' }]],
+    use: {
+        trace: 'on-first-retry',
+    },
+    projects: [
+        {
+            name: 'chromium',
+            use: { ...devices['Desktop Chrome'] },
+        },
+        {
+            name: 'firefox',
+            use: { ...devices['Desktop Firefox'] },
+        },
+        {
+            name: 'webkit',
+            use: { ...devices['Desktop Safari'] },
+        },
+    ],
+    webServer: {
+        command: 'http-server ./ -p 8080',
+        reuseExistingServer: !process.env.CI,
+        stdout: 'ignore',
+        stderr: 'pipe',
+    }
+})
\ No newline at end of file
diff --git a/tsup.config.ts b/tsup.config.ts
index 0e3f406..d8f1bb2 100644
--- a/tsup.config.ts
+++ b/tsup.config.ts
@@ -2,11 +2,12 @@ import { defineConfig } from "tsup";
 
 export default defineConfig({
   entry: ["src/index.ts"],
-  format: ["cjs", "esm"],
+  format: ["cjs", "esm", "iife"],
   dts: true,
   clean: true,
   minify: true,
   esbuildOptions(options) {
     options.keepNames = true;
+    options.globalName = "Topsort"
   },
 });