fix: Use origin as provided in HeadSeo. origin would be different for Domain cases (#14935)

* fix: Use origin as provided in HeadSeo. origin would be different for Domain cases

* Add a test

* add more test

* Add tests

* Cleanup tests

* Add an e2e as well

* fix-test

* Reset mocks
This commit is contained in:
Hariom Balhara authored and GitHub committed 2024-05-23 11:47:46 +01:00
1 parent 29ccc58806
commit 5f5cf92456
16 files changed
+730 -27

No files matched your search

+5
View File
@@ -1,6 +1,7 @@
import { expect } from "@playwright/test";
import { JSDOM } from "jsdom";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { randomString } from "@calcom/lib/random";
import { SchedulingType } from "@calcom/prisma/client";
import type { Schedule, TimeRange } from "@calcom/types/schedule";
@@ -42,7 +43,11 @@ test("check SSR and OG - User Event Type", async ({ page, users }) => {
const titleText = document.querySelector("title")?.textContent;
const ogImage = document.querySelector('meta[property="og:image"]')?.getAttribute("content");
const ogUrl = document.querySelector('meta[property="og:url"]')?.getAttribute("content");
const canonicalLink = document.querySelector('link[rel="canonical"]')?.getAttribute("href");
expect(titleText).toContain(name);
expect(ogUrl).toEqual(`${WEBAPP_URL}/${user.username}/30-min`);
expect(canonicalLink).toEqual(`${WEBAPP_URL}/${user.username}/30-min`);
// Verify that there is correct URL that would generate the awesome OG image
expect(ogImage).toContain(
"/_next/image?w=1200&q=100&url=%2Fapi%2Fsocial%2Fog%2Fimage%3Ftype%3Dmeeting%26title%3D"
@@ -1,7 +1,9 @@
import type { Page } from "@playwright/test";
import { expect } from "@playwright/test";
import { JSDOM } from "jsdom";
import { getOrgUsernameFromEmail } from "@calcom/features/auth/signup/utils/getOrgUsernameFromEmail";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { MembershipRole, SchedulingType } from "@calcom/prisma/enums";
import { test } from "../lib/fixtures";
@@ -16,6 +18,16 @@ import { expectExistingUserToBeInvitedToOrganization } from "../team/expects";
import { gotoPathAndExpectRedirectToOrgDomain } from "./lib/gotoPathAndExpectRedirectToOrgDomain";
import { acceptTeamOrOrgInvite, inviteExistingUserToOrganization } from "./lib/inviteUser";
function getOrgOrigin(orgSlug: string | null) {
if (!orgSlug) {
throw new Error("orgSlug is required");
}
let orgOrigin = WEBAPP_URL.replace("://app", `://${orgSlug}`);
orgOrigin = orgOrigin.includes(orgSlug) ? orgOrigin : WEBAPP_URL.replace("://", `://${orgSlug}.`);
return orgOrigin;
}
test.describe("Bookings", () => {
test.afterEach(({ orgs, users }) => {
orgs.deleteAll();
@@ -187,6 +199,7 @@ test.describe("Bookings", () => {
}
);
});
test.describe("User Event with same slug as another user's", () => {
test("booking is created for first user when first user is booked", async ({ page, users, orgs }) => {
const org = await orgs.create({
@@ -251,6 +264,55 @@ test.describe("Bookings", () => {
);
});
});
test("check SSR and OG ", async ({ page, users, orgs }) => {
const name = "Test User";
const org = await orgs.create({
name: "TestOrg",
});
const user = await users.create({
name,
organizationId: org.id,
roleInOrganization: MembershipRole.MEMBER,
});
const firstEventType = await user.getFirstEventAsOwner();
const calLink = `/${user.username}/${firstEventType.slug}`;
await doOnOrgDomain(
{
orgSlug: org.slug,
page,
},
async () => {
const [response] = await Promise.all([
// This promise resolves to the main resource response
page.waitForResponse(
(response) => response.url().includes(`${calLink}`) && response.status() === 200
),
// Trigger the page navigation
page.goto(`${calLink}`),
]);
const ssrResponse = await response.text();
const document = new JSDOM(ssrResponse).window.document;
const orgOrigin = getOrgOrigin(org.slug);
const titleText = document.querySelector("title")?.textContent;
const ogImage = document.querySelector('meta[property="og:image"]')?.getAttribute("content");
const ogUrl = document.querySelector('meta[property="og:url"]')?.getAttribute("content");
const canonicalLink = document.querySelector('link[rel="canonical"]')?.getAttribute("href");
expect(titleText).toContain(name);
expect(ogUrl).toEqual(`${orgOrigin}${calLink}`);
expect(canonicalLink).toEqual(`${orgOrigin}${calLink}`);
// Verify that there is correct URL that would generate the awesome OG image
expect(ogImage).toContain(
"/_next/image?w=1200&q=100&url=%2Fapi%2Fsocial%2Fog%2Fimage%3Ftype%3Dmeeting%26title%3D"
);
// Verify Organizer Name in the URL
expect(ogImage).toContain("meetingProfileName%3DTest%2520User%26");
}
);
});
});
test.describe("Scenario with same username in and outside organization", () => {