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