Skip to content

Commit

Permalink
fix: adding new skel using only function in script
Browse files Browse the repository at this point in the history
  • Loading branch information
barbmarcio committed Jul 19, 2024
1 parent 1abb288 commit 2a05eb9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 49 deletions.
33 changes: 17 additions & 16 deletions e2e/auctions.test.ts
Original file line number Diff line number Diff line change
@@ -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: [
{
Expand All @@ -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",
Expand All @@ -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);
});
});
41 changes: 9 additions & 32 deletions e2e/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,16 @@
</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();
}
});
window.sdk = {
createAuction: async (config, auctionDetails) => {
const result = await Topsort.createAuction(
config,
auctionDetails
).catch((error) => error);
return result;
},
};
</script>
</body>
</html>
5 changes: 5 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface Window {
sdk: {
createAuction: (a, b) => void;
};
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"CHANGELOG.md",
"LICENSE",
"README.md",
"dist/index.global.js",
"dist/index.d.mts",
"dist/index.d.ts",
"dist/index.js",
Expand Down
1 change: 0 additions & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 2a05eb9

Please sign in to comment.