Files
sean-brydonGitHubDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
9424649d6f fix: add isCompanyEmail check to organization upgrade path (#27813)
Users with personal emails (e.g. Gmail) could enter the org creation flow
at /settings/organizations/new but only hit the company email error at
checkout, with no way to fix it from the form. After changing their email
in settings, the cached store email was still used.

- Add server-side isCompanyEmail check in page.tsx to redirect early
- Add client-side check in CreateANewOrganizationForm with clear messaging
- Always use current session email for non-admin users (not cached store)
- Add tests for isCompanyEmail utility

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-02-10 06:15:28 +00:00

118 lines
3.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { extractDomainFromEmail, isCompanyEmail } from "./utils";
describe("utils", () => {
describe("isCompanyEmail", () => {
it("should return false for gmail.com email", () => {
expect(isCompanyEmail("[email protected]")).toBe(false);
});
it("should return false for yahoo.com email", () => {
expect(isCompanyEmail("[email protected]")).toBe(false);
});
it("should return false for outlook.com email", () => {
expect(isCompanyEmail("[email protected]")).toBe(false);
});
it("should return false for hotmail.com email", () => {
expect(isCompanyEmail("[email protected]")).toBe(false);
});
it("should return false for protonmail.com email", () => {
expect(isCompanyEmail("[email protected]")).toBe(false);
});
it("should return false for icloud.com email", () => {
expect(isCompanyEmail("[email protected]")).toBe(false);
});
it("should return true for company email", () => {
expect(isCompanyEmail("[email protected]")).toBe(true);
});
it("should return true for cal.com email", () => {
expect(isCompanyEmail("[email protected]")).toBe(true);
});
it("should return false for email without @", () => {
expect(isCompanyEmail("invalidemail")).toBe(false);
});
it("should return false for empty email", () => {
expect(isCompanyEmail("")).toBe(false);
});
it("should return false for all popular personal email providers", () => {
const personalProviders = [
"gmail.com",
"googlemail.com",
"yahoo.com",
"ymail.com",
"rocketmail.com",
"sbcglobal.net",
"att.net",
"outlook.com",
"hotmail.com",
"live.com",
"msn.com",
"outlook.co",
"hotmail.co.uk",
"aol.com",
"icloud.com",
"me.com",
"mac.com",
"mail.com",
"email.com",
"protonmail.com",
"proton.me",
"zoho.com",
"yandex.com",
"gmx.com",
"fastmail.com",
"tutanota.com",
"mail.ru",
"qq.com",
];
for (const provider of personalProviders) {
expect(isCompanyEmail(`user@${provider}`)).toBe(false);
}
});
it("should return true for various company domains", () => {
const companyDomains = [
"acme.com",
"techcorp.io",
"business.co",
"startup.ai",
"enterprise.net",
"cal.com",
];
for (const domain of companyDomains) {
expect(isCompanyEmail(`user@${domain}`)).toBe(true);
}
});
it("should be case-insensitive for domain matching", () => {
expect(isCompanyEmail("[email protected]")).toBe(false);
expect(isCompanyEmail("[email protected]")).toBe(false);
});
});
describe("extractDomainFromEmail", () => {
it("should extract domain from a standard email", () => {
expect(extractDomainFromEmail("[email protected]")).toBe("acme");
});
it("should return empty string for invalid input", () => {
expect(extractDomainFromEmail("invalid")).toBe("");
});
it("should return empty string for empty input", () => {
expect(extractDomainFromEmail("")).toBe("");
});
});
});