-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial revision for e2e tests
- Loading branch information
1 parent
7321da8
commit 9aebba0
Showing
7 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
coverage/ | ||
dist/ | ||
node_modules/ | ||
test-results/ | ||
test-results.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Topsort SDK Test Application</title> | ||
<script src="../dist/index.global.js"></script> | ||
</head> | ||
<body> | ||
<h1>Test Topsort.js Integration</h1> | ||
<form id="auction-form"> | ||
<input type="text" name="apiKey" placeholder="API Key" required /> | ||
<input | ||
type="text" | ||
name="auctionDetails" | ||
placeholder="Auction Details" | ||
required | ||
/> | ||
<button type="submit">Create Auction</button> | ||
</form> | ||
<pre id="response"></pre> | ||
<script> | ||
document | ||
.getElementById("auction-form") | ||
.addEventListener("submit", async (event) => { | ||
event.preventDefault(); | ||
const apiKey = event.target.apiKey.value; | ||
const auctionDetails = JSON.parse(event.target.auctionDetails.value); | ||
const config = { apiKey }; | ||
try { | ||
const result = await Topsort.createAuction( | ||
config, | ||
auctionDetails | ||
); | ||
document.getElementById("response").textContent = JSON.stringify( | ||
result, | ||
null, | ||
2 | ||
); | ||
} catch (error) { | ||
document.getElementById("response").textContent = error.toString(); | ||
} | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters