Open History to see the last commit
1import { describe, expect, it, vi } from "vite-plus/test";
2
3import {
4 CloudWaitlistJoinRejectedError,
5 CloudWaitlistJoinRequestError,
6 joinCloudWaitlist,
7} from "./cloudWaitlistJoin";
8
9describe("joinCloudWaitlist", () => {
10 it("submits the provided email address", async () => {
11 const join = vi.fn().mockResolvedValue({ error: null });
12
13 await joinCloudWaitlist({ join }, "person@example.com");
14
15 expect(join).toHaveBeenCalledExactlyOnceWith({ emailAddress: "person@example.com" });
16 });
17
18 it("preserves Clerk rejection details without exposing the email address", async () => {
19 const cause = Object.assign(new Error("The enrollment was rejected."), {
20 code: "form_identifier_invalid",
21 });
22 const join = vi.fn().mockResolvedValue({ error: cause });
23
24 const failure = await joinCloudWaitlist({ join }, "secret@example.com").catch(
25 (error: unknown) => error,
26 );
27
28 expect(failure).toBeInstanceOf(CloudWaitlistJoinRejectedError);
29 expect(failure).toMatchObject({
30 code: "form_identifier_invalid",
31 cause,
32 });
33 expect(String(failure)).not.toContain("secret@example.com");
34 });
35
36 it("distinguishes request failures from rejected enrollments", async () => {
37 const cause = new Error("network unavailable");
38 const join = vi.fn().mockRejectedValue(cause);
39
40 const failure = await joinCloudWaitlist({ join }, "person@example.com").catch(
41 (error: unknown) => error,
42 );
43
44 expect(failure).toBeInstanceOf(CloudWaitlistJoinRequestError);
45 expect(failure).toMatchObject({ cause });
46 expect(failure).not.toBeInstanceOf(CloudWaitlistJoinRejectedError);
47 });
48});