* feat: Cal.diy — community-driven MIT-licensed fork of Cal.com This squashed commit contains all Cal.diy changes applied on top of calcom/cal.com main: - Rebrand Cal.com to Cal.diy across the entire codebase - Remove Enterprise Edition (EE) features, license checks, and AGPL restrictions - Switch license from AGPL-3.0 to MIT - Remove docs/ directory (migrated to Nextra at cal.diy) - Remove dead code: org tests, EE tips, platform nav, premium username, SAML/SSO, etc. - Clean up .env.example for self-hosted Cal.diy - Update Docker image references to calcom/cal.diy - Update README, CONTRIBUTING.md, and issue templates for Cal.diy community fork - Add PR welcome bot for Cal.diy contributors - Fix API v2 breaking changes oasdiff ignore entries - Replace Blacksmith CI runners with default GitHub Actions 3893 files changed, 20789 insertions(+), 411020 deletions(-) Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * refactor: remove org-specific /organizations/:orgId endpoints from API v2 atoms controllers (#1701) Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: revert Cal.diy Inc to Cal.com, Inc. in license files, copyright notices, and package metadata (#1702) Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * rip out org related comments in api v2 --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
186 lines
6.1 KiB
TypeScript
186 lines
6.1 KiB
TypeScript
import type React from "react";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import type { OnboardingState } from "../../store/onboarding-store";
|
|
import { useSubmitOnboarding } from "../useSubmitOnboarding";
|
|
|
|
vi.mock("react", async () => {
|
|
const actual = await vi.importActual<typeof React>("react");
|
|
return {
|
|
...actual,
|
|
useState: vi.fn((initial: boolean | string | null) => [initial, vi.fn()]),
|
|
};
|
|
});
|
|
|
|
vi.mock("@calcom/features/flags/context/provider", () => ({
|
|
useFlagMap: vi.fn(() => ({})),
|
|
}));
|
|
|
|
const mockShowToast = vi.fn();
|
|
vi.mock("@calcom/ui/components/toast", () => ({
|
|
showToast: (...args: unknown[]) => mockShowToast(...args),
|
|
}));
|
|
|
|
vi.mock("@calcom/trpc/react", () => ({
|
|
trpc: {
|
|
viewer: {
|
|
organizations: {
|
|
intentToCreateOrg: {
|
|
useMutation: vi.fn(),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}));
|
|
|
|
describe("useSubmitOnboarding", () => {
|
|
let mockResetOnboarding: ReturnType<typeof vi.fn>;
|
|
|
|
beforeEach(() => {
|
|
mockResetOnboarding = vi.fn();
|
|
mockShowToast.mockClear();
|
|
|
|
global.window = {
|
|
location: {
|
|
href: "",
|
|
},
|
|
} as unknown as Window & typeof globalThis;
|
|
});
|
|
|
|
it("should submit teams with migration data and redirect to event-types for migrated teams", async () => {
|
|
const hook = useSubmitOnboarding();
|
|
const { submitOnboarding } = hook;
|
|
|
|
const store = {
|
|
selectedPlan: "organization",
|
|
organizationDetails: {
|
|
name: "Test Org",
|
|
link: "test-org",
|
|
bio: "Test bio",
|
|
},
|
|
organizationBrand: {
|
|
color: "#000000",
|
|
logo: "logo.png",
|
|
banner: "banner.png",
|
|
},
|
|
teams: [
|
|
{ id: 1, name: "Existing Team", slug: "existing-team", isBeingMigrated: true },
|
|
{ id: -1, name: "New Team", slug: null, isBeingMigrated: false },
|
|
],
|
|
invites: [{ email: "invite@example.com", team: "New Team", role: "MEMBER" }],
|
|
inviteRole: "MEMBER",
|
|
migratedMembers: [{ email: "migrated@example.com", teamId: 1, role: "MEMBER" as const }],
|
|
resetOnboarding: mockResetOnboarding,
|
|
} as unknown as OnboardingState;
|
|
|
|
await submitOnboarding(store, "user@example.com", store.invites);
|
|
|
|
// After EE removal, intentToCreateOrg is a no-op stub returning {}
|
|
// No checkoutUrl → migration flow (has migrated teams) → redirects to event-types
|
|
expect(mockShowToast).toHaveBeenCalledWith("Organization created successfully!", "success");
|
|
expect(mockResetOnboarding).toHaveBeenCalled();
|
|
expect(window.location.href).toBe("/event-types?newOrganizationModal=true");
|
|
});
|
|
|
|
it("should redirect to event-types when migrated teams exist", async () => {
|
|
const hook = useSubmitOnboarding();
|
|
const { submitOnboarding } = hook;
|
|
|
|
const store = {
|
|
selectedPlan: "organization",
|
|
organizationDetails: {
|
|
name: "Test Org",
|
|
link: "test-org",
|
|
bio: "Test bio",
|
|
},
|
|
organizationBrand: {
|
|
color: "#000000",
|
|
logo: "logo.png",
|
|
banner: "banner.png",
|
|
},
|
|
teams: [
|
|
{ id: 1, name: "Existing Team", slug: "existing-team", isBeingMigrated: true },
|
|
{ id: 2, name: "Another Existing Team", slug: "another-existing-team", isBeingMigrated: true },
|
|
{ id: -1, name: "New Team", slug: null, isBeingMigrated: false },
|
|
],
|
|
invites: [
|
|
{ email: "invite1@example.com", team: "Existing Team", role: "MEMBER" },
|
|
{ email: "invite2@example.com", team: "New Team", role: "ADMIN" },
|
|
{ email: "invite3@example.com", team: "another existing team", role: "MEMBER" },
|
|
],
|
|
inviteRole: "MEMBER",
|
|
migratedMembers: [],
|
|
resetOnboarding: mockResetOnboarding,
|
|
} as unknown as OnboardingState;
|
|
|
|
await submitOnboarding(store, "user@example.com", store.invites);
|
|
|
|
expect(mockShowToast).toHaveBeenCalledWith("Organization created successfully!", "success");
|
|
expect(mockResetOnboarding).toHaveBeenCalled();
|
|
expect(window.location.href).toBe("/event-types?newOrganizationModal=true");
|
|
});
|
|
|
|
it("should redirect to event-types when migrated teams exist even with empty team invites", async () => {
|
|
const hook = useSubmitOnboarding();
|
|
const { submitOnboarding } = hook;
|
|
|
|
const store = {
|
|
selectedPlan: "organization",
|
|
organizationDetails: {
|
|
name: "Test Org",
|
|
link: "test-org",
|
|
bio: "Test bio",
|
|
},
|
|
organizationBrand: {
|
|
color: "#000000",
|
|
logo: "logo.png",
|
|
banner: "banner.png",
|
|
},
|
|
teams: [{ id: 1, name: "Existing Team", slug: "existing-team", isBeingMigrated: true }],
|
|
invites: [
|
|
{ email: "invite1@example.com", team: "", role: "MEMBER" },
|
|
{ email: "invite2@example.com", team: " ", role: "ADMIN" },
|
|
],
|
|
inviteRole: "MEMBER",
|
|
migratedMembers: [],
|
|
resetOnboarding: mockResetOnboarding,
|
|
} as unknown as OnboardingState;
|
|
|
|
await submitOnboarding(store, "user@example.com", store.invites);
|
|
|
|
expect(mockShowToast).toHaveBeenCalledWith("Organization created successfully!", "success");
|
|
expect(mockResetOnboarding).toHaveBeenCalled();
|
|
expect(window.location.href).toBe("/event-types?newOrganizationModal=true");
|
|
});
|
|
|
|
it("should redirect to getting-started when no migrated teams exist", async () => {
|
|
const hook = useSubmitOnboarding();
|
|
const { submitOnboarding } = hook;
|
|
|
|
const store = {
|
|
selectedPlan: "organization",
|
|
organizationDetails: {
|
|
name: "Test Org",
|
|
link: "test-org",
|
|
bio: "",
|
|
},
|
|
organizationBrand: {
|
|
color: "#000000",
|
|
logo: null,
|
|
banner: null,
|
|
},
|
|
teams: [{ id: -1, name: "New Team", slug: null, isBeingMigrated: false }],
|
|
invites: [],
|
|
inviteRole: "MEMBER",
|
|
migratedMembers: [],
|
|
resetOnboarding: mockResetOnboarding,
|
|
} as unknown as OnboardingState;
|
|
|
|
await submitOnboarding(store, "user@example.com", []);
|
|
|
|
// Regular flow: no migrated teams → redirects to getting-started
|
|
expect(mockShowToast).toHaveBeenCalledWith("Organization created successfully!", "success");
|
|
expect(mockResetOnboarding).toHaveBeenCalled();
|
|
expect(window.location.href).toBe("/getting-started");
|
|
});
|
|
});
|