Skip to content
18 changes: 17 additions & 1 deletion packages/embeds/embed-core/playwright/tests/preview.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect } from "@playwright/test";
import { test } from "@calcom/web/playwright/lib/fixtures";

test.describe("Preview", () => {
test("Preview - embed-core should load", async ({ page }) => {
test("Preview - embed-core should load if correct embedLibUrl is provided", async ({ page }) => {
await page.goto(
"http://localhost:3000/embed/preview.html?embedLibUrl=http://localhost:3000/embed/embed.js&bookerUrl=http://localhost:3000&calLink=pro/30min"
);
Expand All @@ -26,4 +26,20 @@ test.describe("Preview", () => {
});
expect(libraryLoaded).toBe(true);
});

test("Preview - embed-core should load from embedLibUrl", async ({ page }) => {
// Intentionally pass a URL that will not load to be able to easily test that the embed was loaded from there
page.goto(
"http://localhost:3000/embed/preview.html?embedLibUrl=http://wronglocalhost:3000/embed/embed.js&bookerUrl=http://localhost:3000&calLink=pro/30min"
);

const failedRequestUrl = await new Promise<string>((resolve) =>
page.on("requestfailed", (request) => {
console.log("request failed");
resolve(request.url());
})
);

expect(failedRequestUrl).toBe("http://wronglocalhost:3000/embed/embed.js");
});
});
2 changes: 1 addition & 1 deletion packages/embeds/embed-core/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if (!bookerUrl || !embedLibUrl) {
}
p(cal, ar);
};
})(window, "//localhost:3000/embed/embed.js", "init");
})(window, embedLibUrl, "init");
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was an accidental change that got committed.
https://github.com/calcom/cal.com/pull/13386/files#r1586013449

const previewWindow = window;
previewWindow.Cal.fingerprint = process.env.EMBED_PUBLIC_EMBED_FINGER_PRINT as string;

Expand Down