@tribe-nest/forge 3.59.0 → 3.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/src/_tests/testCommunity.tsx +28 -0
- package/src/contexts/CartContext.tsx +34 -1
- package/src/contexts/CommunityContext.tsx +192 -0
- package/src/contexts/PublicAuthContext.tsx +15 -3
- package/src/data/queries/_tests/metaSignals.spec.tsx +130 -0
- package/src/data/queries/useAccount.ts +33 -2
- package/src/data/queries/useAnalytics.ts +6 -6
- package/src/data/queries/useCallChat.ts +2 -2
- package/src/data/queries/useChat.ts +52 -40
- package/src/data/queries/useCheckouts.ts +2 -1
- package/src/data/queries/useCoachingAvailability.ts +10 -1
- package/src/data/queries/useCommunities.ts +345 -0
- package/src/data/queries/useCommunity.ts +450 -102
- package/src/data/queries/useCommunityAgent.ts +247 -0
- package/src/data/queries/useCommunityCalendar.ts +150 -0
- package/src/data/queries/useCommunityClassroom.ts +75 -0
- package/src/data/queries/useCommunityMembers.ts +108 -0
- package/src/data/queries/useCommunityModeration.ts +327 -0
- package/src/data/queries/useCommunityWiki.ts +137 -0
- package/src/data/queries/useCourses.ts +2 -0
- package/src/data/queries/useEmailSignIn.ts +79 -0
- package/src/data/queries/useEvents.ts +6 -1
- package/src/data/queries/useForms.ts +5 -1
- package/src/data/queries/useLeadMagnet.ts +6 -2
- package/src/data/queries/useMembership.ts +32 -7
- package/src/data/queries/useMembershipCalls.ts +116 -7
- package/src/data/queries/useMyBookings.ts +24 -1
- package/src/data/queries/useMyTickets.ts +24 -1
- package/src/data/queries/useNotifications.ts +6 -2
- package/src/data/queries/useOrders.ts +2 -1
- package/src/data/queries/usePWA.ts +111 -35
- package/src/data/queries/usePostCollections.ts +28 -16
- package/src/data/queries/usePosts.ts +16 -14
- package/src/data/queries/useSiteApp.ts +130 -0
- package/src/data/queries/useSubscriptions.ts +28 -9
- package/src/i18n/de.json +891 -2
- package/src/i18n/en.json +891 -2
- package/src/index.ts +36 -7
- package/src/runtime/pages.spec.ts +36 -0
- package/src/runtime/pages.ts +52 -27
- package/src/server/_tests/buildWebManifest.spec.ts +1 -1
- package/src/server/_tests/forgeServiceWorkerScript.spec.ts +4 -4
- package/src/types/models.ts +11 -0
- package/src/ui/analytics/ForgeAnalytics.tsx +64 -34
- package/src/ui/analytics/PageMetaPixel.tsx +23 -8
- package/src/ui/analytics/_tests/ForgeAnalytics.meta.spec.tsx +129 -0
- package/src/ui/analytics/_tests/metaCommerceEvents.spec.tsx +159 -0
- package/src/ui/analytics/useMetaEvents.ts +78 -0
- package/src/ui/format/_tests/membershipGate.spec.ts +6 -6
- package/src/ui/format/membershipGate.ts +19 -15
- package/src/ui/headless/_tests/communityAgent.spec.tsx +519 -0
- package/src/ui/headless/_tests/communityCalendar.spec.tsx +195 -0
- package/src/ui/headless/_tests/communityClassroom.spec.tsx +120 -0
- package/src/ui/headless/_tests/communityGate.spec.tsx +80 -0
- package/src/ui/headless/_tests/communityHarness.tsx +212 -0
- package/src/ui/headless/_tests/communityMembers.spec.tsx +316 -0
- package/src/ui/headless/_tests/communityPoll.spec.tsx +389 -0
- package/src/ui/headless/_tests/communityProvider.spec.tsx +151 -0
- package/src/ui/headless/_tests/memberHomeBar.spec.ts +84 -0
- package/src/ui/headless/_tests/siteAppBar.spec.ts +83 -0
- package/src/ui/headless/_tests/siteAppHarness.ts +19 -0
- package/src/ui/headless/_tests/siteAppHome.spec.ts +226 -0
- package/src/ui/headless/_tests/siteAppPrompts.spec.ts +185 -0
- package/src/ui/headless/_tests/useCommunityInvite.spec.tsx +104 -0
- package/src/ui/headless/_tests/useCommunityJoin.spec.tsx +596 -0
- package/src/ui/headless/_tests/useCommunityMembership.spec.tsx +179 -0
- package/src/ui/headless/_tests/useCommunityModeration.spec.tsx +420 -0
- package/src/ui/headless/_tests/useCommunityReads.spec.tsx +295 -0
- package/src/ui/headless/_tests/useCommunityUpgrade.spec.tsx +157 -0
- package/src/ui/headless/_tests/useCommunityWiki.spec.tsx +224 -0
- package/src/ui/headless/_tests/useSiteApp.spec.tsx +52 -0
- package/src/ui/headless/_tests/wikiMediaImage.spec.tsx +132 -0
- package/src/ui/headless/auth/useEmailCodeSignIn.ts +186 -0
- package/src/ui/headless/auth/useSignupForm.ts +30 -3
- package/src/ui/headless/chat/useChatAttachmentUpload.ts +9 -6
- package/src/ui/headless/chat/useChatRoom.ts +35 -1
- package/src/ui/headless/communities/CommunityGate.tsx +67 -0
- package/src/ui/headless/communities/index.ts +96 -0
- package/src/ui/headless/communities/paths.ts +36 -0
- package/src/ui/headless/communities/useCommunity.ts +140 -0
- package/src/ui/headless/communities/useCommunityAbout.ts +71 -0
- package/src/ui/headless/communities/useCommunityCalendar.ts +156 -0
- package/src/ui/headless/communities/useCommunityClassroom.ts +84 -0
- package/src/ui/headless/communities/useCommunityHome.ts +91 -0
- package/src/ui/headless/communities/useCommunityInvite.ts +116 -0
- package/src/ui/headless/communities/useCommunityJoin.ts +494 -0
- package/src/ui/headless/communities/useCommunityMembership.ts +182 -0
- package/src/ui/headless/communities/useCommunityUpgrade.ts +213 -0
- package/src/ui/headless/communities/useCommunityWiki.ts +266 -0
- package/src/ui/headless/communities/useMyMemberships.ts +59 -0
- package/src/ui/headless/community/communityPoll.ts +297 -0
- package/src/ui/headless/community/countries.ts +123 -0
- package/src/ui/headless/community/index.ts +81 -1
- package/src/ui/headless/community/linkPreview.ts +71 -0
- package/src/ui/headless/community/richLexical.ts +27 -2
- package/src/ui/headless/community/useCommunityAgent.ts +285 -0
- package/src/ui/headless/community/useCommunityAttachmentUpload.ts +7 -3
- package/src/ui/headless/community/useCommunityMembers.ts +175 -0
- package/src/ui/headless/community/useCommunityModeration.ts +300 -0
- package/src/ui/headless/community/useCommunitySpaceFeed.ts +22 -4
- package/src/ui/headless/community/useCommunityThread.ts +16 -3
- package/src/ui/headless/community/useMentionComposer.ts +17 -9
- package/src/ui/headless/community/useRichMentionComposer.ts +21 -5
- package/src/ui/headless/downloads/index.ts +8 -0
- package/src/ui/headless/downloads/useDownloadPage.ts +134 -0
- package/src/ui/headless/index.ts +21 -4
- package/src/ui/headless/memberHome/index.ts +11 -1
- package/src/ui/headless/memberHome/memberHomeBar.ts +91 -0
- package/src/ui/headless/memberHome/useMemberHomeNav.ts +84 -44
- package/src/ui/headless/membership/_tests/membershipCheckoutRefetch.spec.tsx +8 -0
- package/src/ui/headless/membership/_tests/useMembershipCheckoutApplication.spec.tsx +5 -4
- package/src/ui/headless/membership/_tests/useMembershipCheckoutQuestionnaire.spec.tsx +1 -1
- package/src/ui/headless/membership/_tests/useMembershipCheckoutTrial.spec.tsx +1 -1
- package/src/ui/headless/membership/useMembershipCheckout.ts +89 -22
- package/src/ui/headless/membership/useMembershipGateNotice.ts +25 -7
- package/src/ui/headless/portal/index.ts +57 -0
- package/src/ui/headless/portal/usePortal.ts +274 -0
- package/src/ui/headless/portal/usePortalFiles.ts +68 -0
- package/src/ui/headless/portal/usePortalMessages.ts +189 -0
- package/src/ui/headless/portal/usePortalPreview.ts +142 -0
- package/src/ui/headless/posts/upsell.ts +54 -8
- package/src/ui/headless/posts/useMemberPostsFeed.ts +6 -5
- package/src/ui/headless/posts/usePostCollectionDetail.ts +7 -4
- package/src/ui/headless/posts/usePostCollectionsList.ts +6 -5
- package/src/ui/headless/posts/usePostItem.ts +6 -5
- package/src/ui/headless/siteApp/appBar.ts +102 -0
- package/src/ui/headless/siteApp/appHome.ts +344 -0
- package/src/ui/headless/siteApp/appPrompts.ts +229 -0
- package/src/ui/headless/siteApp/index.ts +58 -0
- package/src/ui/headless/siteApp/useAppHome.ts +210 -0
- package/src/ui/headless/siteApp/useAppInstallRequest.ts +16 -0
- package/src/ui/headless/work/index.ts +2 -0
- package/src/ui/headless/work/useWorkPortal.ts +37 -26
- package/src/ui/index.ts +28 -12
- package/src/ui/styled/AccountDashboard.tsx +754 -602
- package/src/ui/styled/AiAgentWidget.tsx +13 -1
- package/src/ui/styled/ChatRoom.tsx +126 -16
- package/src/ui/styled/Checkout.tsx +8 -0
- package/src/ui/styled/CheckoutConfirmation.tsx +8 -0
- package/src/ui/styled/CoachingConfirmation.tsx +8 -0
- package/src/ui/styled/CoachingDetail.tsx +2 -0
- package/src/ui/styled/CourseConfirmation.tsx +5 -0
- package/src/ui/styled/CourseDetail.tsx +2 -0
- package/src/ui/styled/DownloadPage.tsx +263 -0
- package/src/ui/styled/EventConfirmation.tsx +10 -0
- package/src/ui/styled/EventDetail.tsx +10 -0
- package/src/ui/styled/FilmLibrary.tsx +22 -9
- package/src/ui/styled/MembershipCheckout.tsx +37 -17
- package/src/ui/styled/MembershipTierCallout.tsx +20 -1
- package/src/ui/styled/MembershipTiers.tsx +49 -11
- package/src/ui/styled/MusicLinkPage.tsx +5 -5
- package/src/ui/styled/Paywall.tsx +1 -1
- package/src/ui/styled/ProductDetail.tsx +12 -0
- package/src/ui/styled/PwaRegistration.tsx +5 -1
- package/src/ui/styled/SignupForm.tsx +18 -3
- package/src/ui/styled/_tests/AccountDashboardBookingCall.spec.tsx +6 -6
- package/src/ui/styled/_tests/AccountDashboardMemberships.spec.tsx +151 -0
- package/src/ui/styled/_tests/AccountDashboardRentals.spec.tsx +1 -1
- package/src/ui/styled/_tests/AccountNotifications.spec.tsx +135 -0
- package/src/ui/styled/_tests/CourseCallsSection.spec.tsx +7 -1
- package/src/ui/styled/_tests/DownloadPage.spec.tsx +68 -0
- package/src/ui/styled/_tests/MembershipCheckout.spec.tsx +54 -11
- package/src/ui/styled/_tests/membershipTierCallout.spec.tsx +1 -1
- package/src/ui/styled/_tests/membershipTiersCuratedAccess.spec.tsx +1 -1
- package/src/ui/styled/app/AppBar.tsx +298 -0
- package/src/ui/styled/app/AppHome.tsx +1139 -0
- package/src/ui/styled/app/AppHomeMark.tsx +66 -0
- package/src/ui/styled/app/AppPrompts.tsx +464 -0
- package/src/ui/styled/app/_tests/AppBar.spec.tsx +96 -0
- package/src/ui/styled/app/_tests/AppHome.spec.tsx +209 -0
- package/src/ui/styled/app/_tests/AppPrompts.spec.tsx +232 -0
- package/src/ui/styled/app/index.ts +7 -0
- package/src/ui/styled/chat/ChatThreadPanel.tsx +29 -4
- package/src/ui/styled/chat/MessageBubble.tsx +43 -6
- package/src/ui/styled/communities/CommunitiesList.tsx +88 -0
- package/src/ui/styled/communities/CommunityAbout.tsx +145 -0
- package/src/ui/styled/communities/CommunityCalendar.tsx +484 -0
- package/src/ui/styled/communities/CommunityClassroom.tsx +302 -0
- package/src/ui/styled/communities/CommunityHome.tsx +298 -0
- package/src/ui/styled/communities/CommunityJoinSheet.tsx +544 -0
- package/src/ui/styled/communities/CommunityMembershipMenu.tsx +249 -0
- package/src/ui/styled/communities/CommunityPending.tsx +49 -0
- package/src/ui/styled/communities/CommunityPublicWiki.tsx +75 -0
- package/src/ui/styled/communities/CommunityUpgradeSheet.tsx +137 -0
- package/src/ui/styled/communities/CommunityWiki.tsx +289 -0
- package/src/ui/styled/communities/MyMembershipsList.tsx +115 -0
- package/src/ui/styled/communities/_tests/CommunityAppHome.spec.tsx +92 -0
- package/src/ui/styled/communities/_tests/CommunityClassroomCalendar.spec.tsx +453 -0
- package/src/ui/styled/communities/_tests/CommunityMobile.spec.tsx +399 -0
- package/src/ui/styled/communities/_tests/CommunityPages.spec.tsx +102 -0
- package/src/ui/styled/communities/_tests/CommunityWiki.spec.tsx +223 -0
- package/src/ui/styled/communities/index.ts +19 -0
- package/src/ui/styled/communities/shared.tsx +177 -0
- package/src/ui/styled/community/CommunityAgent.tsx +286 -0
- package/src/ui/styled/community/CommunityComposer.tsx +266 -15
- package/src/ui/styled/community/CommunityFeed.tsx +50 -1
- package/src/ui/styled/community/CommunityLinkPreview.tsx +159 -0
- package/src/ui/styled/community/CommunityMemberGlobe.tsx +171 -0
- package/src/ui/styled/community/CommunityMemberProfile.tsx +137 -4
- package/src/ui/styled/community/CommunityMembers.tsx +387 -0
- package/src/ui/styled/community/CommunityModeration.tsx +587 -0
- package/src/ui/styled/community/CommunityModerationState.tsx +127 -0
- package/src/ui/styled/community/CommunityModeratorMenu.tsx +317 -0
- package/src/ui/styled/community/CommunityNotifications.tsx +52 -6
- package/src/ui/styled/community/CommunityPollCard.tsx +250 -0
- package/src/ui/styled/community/CommunityPostCard.tsx +110 -34
- package/src/ui/styled/community/CommunityPostDetail.tsx +157 -71
- package/src/ui/styled/community/CommunityRichText.tsx +177 -32
- package/src/ui/styled/community/CommunitySpaces.tsx +49 -14
- package/src/ui/styled/community/_tests/CommunityAgent.spec.tsx +571 -0
- package/src/ui/styled/community/_tests/CommunityComposer.spec.tsx +4 -1
- package/src/ui/styled/community/_tests/CommunityLinkPreview.spec.tsx +167 -0
- package/src/ui/styled/community/_tests/CommunityMembers.spec.tsx +137 -0
- package/src/ui/styled/community/_tests/CommunityModeration.spec.tsx +291 -0
- package/src/ui/styled/community/_tests/CommunityPoll.spec.tsx +386 -0
- package/src/ui/styled/community/_tests/CommunityPostDetail.spec.tsx +4 -1
- package/src/ui/styled/community/index.ts +37 -2
- package/src/ui/styled/forge-utilities.css +253 -0
- package/src/ui/styled/members/CallRecordingActions.tsx +182 -0
- package/src/ui/styled/members/CallTranscriptViewer.tsx +424 -0
- package/src/ui/styled/members/MemberCallsCalendar.tsx +41 -54
- package/src/ui/styled/members/MemberHomeLayout.tsx +327 -29
- package/src/ui/styled/members/MemberPostCard.tsx +9 -5
- package/src/ui/styled/members/MemberPostsFeed.tsx +3 -2
- package/src/ui/styled/members/PostCollectionDetail.tsx +18 -10
- package/src/ui/styled/members/PostCollectionsGrid.tsx +24 -10
- package/src/ui/styled/members/_tests/MemberCallsCalendar.spec.tsx +167 -8
- package/src/ui/styled/members/callTranscriptText.ts +67 -0
- package/src/ui/styled/members/index.ts +8 -0
- package/src/ui/styled/portal/PortalAccountSection.tsx +61 -0
- package/src/ui/styled/portal/PortalActivity.tsx +167 -0
- package/src/ui/styled/portal/PortalBilling.tsx +197 -0
- package/src/ui/styled/portal/PortalFiles.tsx +279 -0
- package/src/ui/styled/portal/PortalHome.tsx +401 -0
- package/src/ui/styled/portal/PortalMessages.tsx +300 -0
- package/src/ui/styled/portal/PortalPreviewBanner.tsx +75 -0
- package/src/ui/styled/portal/PortalProjects.tsx +407 -0
- package/src/ui/styled/portal/PortalShell.tsx +397 -0
- package/src/ui/styled/portal/_tests/PortalAppHome.spec.tsx +90 -0
- package/src/ui/styled/portal/_tests/PortalFiles.spec.tsx +159 -0
- package/src/ui/styled/portal/_tests/PortalHome.spec.tsx +148 -0
- package/src/ui/styled/portal/_tests/PortalMessages.spec.tsx +168 -0
- package/src/ui/styled/portal/_tests/PortalPreviewBanner.spec.tsx +132 -0
- package/src/ui/styled/portal/_tests/portalNav.spec.ts +123 -0
- package/src/ui/styled/portal/index.ts +13 -0
- package/src/ui/styled/portal/portalNav.ts +260 -0
- package/src/ui/styled/portal/shared.tsx +206 -0
- package/src/ui/styled/work/WorkInviteAccept.tsx +228 -168
- package/src/ui/styled/work/WorkPortalProjects.tsx +68 -120
- package/src/ui/styled/work/WorkProjectDocuments.tsx +99 -128
- package/src/ui/styled/work/WorkProjectInvoices.tsx +91 -86
- package/src/ui/styled/work/WorkProjectReport.tsx +11 -17
- package/src/ui/styled/work/WorkReportBody.tsx +223 -248
- package/src/ui/styled/work/WorkTaskAttachments.tsx +23 -29
- package/src/ui/styled/work/WorkTaskComments.tsx +75 -102
- package/src/ui/styled/work/WorkTaskDetail.tsx +48 -59
- package/src/ui/styled/work/WorkTokenReport.tsx +8 -16
- package/src/ui/styled/work/index.ts +1 -1
- package/src/utils/_tests/metaEvents.spec.ts +264 -0
- package/src/utils/_tests/safeRedirect.spec.ts +2 -2
- package/src/utils/landing.ts +19 -6
- package/src/utils/metaEvents.ts +302 -0
- package/src/ui/headless/membership/MembershipGate.tsx +0 -44
- package/src/ui/styled/_tests/AccountDashboardCommunity.spec.tsx +0 -149
- package/src/ui/styled/_tests/AccountDashboardTrial.spec.tsx +0 -105
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
4
|
+
import { communityJoinStep, tierHasChoice, useCommunityJoin, type CommunityJoinStepInput } from "../communities/useCommunityJoin";
|
|
5
|
+
import type { CommunityInviteState } from "../../../data/queries/useCommunities";
|
|
6
|
+
import {
|
|
7
|
+
account,
|
|
8
|
+
calls,
|
|
9
|
+
detailRoute,
|
|
10
|
+
get,
|
|
11
|
+
installAdapter,
|
|
12
|
+
meRoute,
|
|
13
|
+
post,
|
|
14
|
+
restoreAdapter,
|
|
15
|
+
tier,
|
|
16
|
+
viewer,
|
|
17
|
+
wrapper,
|
|
18
|
+
type Route,
|
|
19
|
+
} from "./communityHarness";
|
|
20
|
+
|
|
21
|
+
const paystack = vi.hoisted(() => ({ open: vi.fn(async () => "opened" as const) }));
|
|
22
|
+
vi.mock("../../../utils/paystackCheckout", async (importOriginal) => ({
|
|
23
|
+
...(await importOriginal<typeof import("../../../utils/paystackCheckout")>()),
|
|
24
|
+
openPaystackCheckout: paystack.open,
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The join sheet's step machine, driven with no markup.
|
|
29
|
+
*
|
|
30
|
+
* email -> code -> (profile) -> tier -> questions -> payment -> inside
|
|
31
|
+
*
|
|
32
|
+
* Every step that does not apply is skipped, every success lands INSIDE the
|
|
33
|
+
* community (never `/i/account`), invites preset their tier and lock their
|
|
34
|
+
* email, and a dead invite falls back to the normal join without its token.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
const HOME = "/i/communities/fan-club/home";
|
|
38
|
+
let onJoined: ReturnType<typeof vi.fn>;
|
|
39
|
+
/** Whether the email-first verify finds an account for the address. */
|
|
40
|
+
let existingAccount = false;
|
|
41
|
+
const TICKET = "ab".repeat(32);
|
|
42
|
+
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
onJoined = vi.fn();
|
|
45
|
+
existingAccount = false;
|
|
46
|
+
paystack.open.mockClear();
|
|
47
|
+
window.history.replaceState(null, "", "/i/communities/fan-club");
|
|
48
|
+
});
|
|
49
|
+
afterEach(restoreAdapter);
|
|
50
|
+
|
|
51
|
+
const free = tier({ id: "tier-free", name: "Free" });
|
|
52
|
+
const paid = tier({ id: "tier-paid", name: "Paid", priceMonthly: 10 });
|
|
53
|
+
const both = tier({ id: "tier-both", name: "Both", priceMonthly: 10, priceYearly: 100 });
|
|
54
|
+
const apply = tier({ id: "tier-apply", name: "Apply", joinMode: "application" });
|
|
55
|
+
const invited = tier({ id: "tier-vip", name: "VIP", joinMode: "invite" });
|
|
56
|
+
|
|
57
|
+
function routes({
|
|
58
|
+
tiers,
|
|
59
|
+
me = () => viewer(),
|
|
60
|
+
invite,
|
|
61
|
+
extra = [],
|
|
62
|
+
}: {
|
|
63
|
+
tiers: ReturnType<typeof tier>[];
|
|
64
|
+
me?: () => ReturnType<typeof viewer>;
|
|
65
|
+
invite?: CommunityInviteState;
|
|
66
|
+
extra?: Route[];
|
|
67
|
+
}): Route[] {
|
|
68
|
+
return [
|
|
69
|
+
...extra,
|
|
70
|
+
...emailRoutes(),
|
|
71
|
+
get(/^\/public\/communities\/fan-club\/invite$/, () => invite),
|
|
72
|
+
meRoute(me),
|
|
73
|
+
detailRoute((req) => ({
|
|
74
|
+
// The invite-only tier is listed only with a valid token, as on the server.
|
|
75
|
+
tiers: req.params?.invite || req.params?.join ? [...tiers, invited] : tiers,
|
|
76
|
+
})),
|
|
77
|
+
post("/public/payments/subscriptions/free", () => ({ membershipId: "m-1", communitySlug: "fan-club" })),
|
|
78
|
+
post("/public/payments/subscriptions", () => ({
|
|
79
|
+
membershipId: "m-1",
|
|
80
|
+
subscriptionId: "s-1",
|
|
81
|
+
clientSecret: "pi_1_secret_2",
|
|
82
|
+
requiresPayment: true,
|
|
83
|
+
})),
|
|
84
|
+
get("/public/websites/site-config", () => ({ currency: "USD" })),
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** A session as `/public/sessions/email/verify` and `/complete` answer it. */
|
|
89
|
+
const signedIn = (email: string) => ({
|
|
90
|
+
status: "signed_in",
|
|
91
|
+
account: account(email),
|
|
92
|
+
token: "access-1",
|
|
93
|
+
refreshToken: "refresh-1",
|
|
94
|
+
associationId: "assoc-1",
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
/** The email-first endpoints. A code of `000000` is wrong; `existingAccount` decides the verify answer. */
|
|
98
|
+
function emailRoutes(): Route[] {
|
|
99
|
+
return [
|
|
100
|
+
post("/public/sessions/email/start", (req) => ({ status: "code_sent", email: req.body?.email })),
|
|
101
|
+
post("/public/sessions/email/verify", (req) => {
|
|
102
|
+
if (req.body?.code === "000000") throw { status: 400, message: "Invalid or expired code." };
|
|
103
|
+
return existingAccount ? signedIn(String(req.body?.email)) : { status: "needs_profile", ticket: TICKET };
|
|
104
|
+
}),
|
|
105
|
+
post("/public/sessions/email/complete", (req) => signedIn(String(req.body?.email))),
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const press = async (result: { current: ReturnType<typeof useCommunityJoin> }) => {
|
|
110
|
+
await act(async () => {
|
|
111
|
+
await result.current.next();
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/** Email first, for someone new: email, code, then a name and the terms. */
|
|
116
|
+
async function signUp(result: { current: ReturnType<typeof useCommunityJoin> }, email = "fan@example.com") {
|
|
117
|
+
if (!result.current.emailLocked) act(() => result.current.emailFlow.setEmail(email));
|
|
118
|
+
await press(result);
|
|
119
|
+
expect(result.current.step).toBe("code");
|
|
120
|
+
act(() => result.current.setCode("123456"));
|
|
121
|
+
await press(result);
|
|
122
|
+
expect(result.current.step).toBe("profile");
|
|
123
|
+
act(() => {
|
|
124
|
+
result.current.emailFlow.setFirstName("Fan");
|
|
125
|
+
result.current.emailFlow.setLastName("Person");
|
|
126
|
+
result.current.emailFlow.setAcceptedTerms(true);
|
|
127
|
+
});
|
|
128
|
+
await press(result);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
describe("the step order", () => {
|
|
132
|
+
const base: CommunityJoinStepInput = {
|
|
133
|
+
isAuthenticated: true,
|
|
134
|
+
awaitingCode: false,
|
|
135
|
+
emailMismatch: false,
|
|
136
|
+
joined: false,
|
|
137
|
+
pending: false,
|
|
138
|
+
alreadyMember: false,
|
|
139
|
+
isProcessing: false,
|
|
140
|
+
hasPaymentStep: false,
|
|
141
|
+
hasSelectedTier: true,
|
|
142
|
+
tierStepOpen: false,
|
|
143
|
+
questionsOpen: false,
|
|
144
|
+
};
|
|
145
|
+
it.each<[string, Partial<CommunityJoinStepInput>, string]>([
|
|
146
|
+
["anonymous asks who the fan is", { isAuthenticated: false }, "email"],
|
|
147
|
+
["then the emailed code", { isAuthenticated: false, awaitingCode: true }, "code"],
|
|
148
|
+
["then a name, for someone new", { isAuthenticated: false, awaitingCode: true, needsProfile: true }, "profile"],
|
|
149
|
+
["a mismatched invite stays on identity even when signed in", { emailMismatch: true }, "email"],
|
|
150
|
+
["no tier chosen yet", { hasSelectedTier: false }, "tier"],
|
|
151
|
+
["a tier with a choice to make", { tierStepOpen: true }, "tier"],
|
|
152
|
+
["questions after the tier", { questionsOpen: true }, "questions"],
|
|
153
|
+
["the card once a paid join started", { hasPaymentStep: true, questionsOpen: true }, "payment"],
|
|
154
|
+
["in flight", { isProcessing: true }, "submitting"],
|
|
155
|
+
["nothing left to ask submits", {}, "submitting"],
|
|
156
|
+
["an application lodged", { pending: true }, "pending"],
|
|
157
|
+
["joined", { joined: true }, "joined"],
|
|
158
|
+
["already a member goes inside", { alreadyMember: true }, "joined"],
|
|
159
|
+
])("%s", (_label, patch, step) => {
|
|
160
|
+
expect(communityJoinStep({ ...base, ...patch })).toBe(step);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("a tier asks for a choice only with two cycles or a pay-what-you-want amount", () => {
|
|
164
|
+
expect(tierHasChoice(free)).toBe(false);
|
|
165
|
+
expect(tierHasChoice(paid)).toBe(false);
|
|
166
|
+
expect(tierHasChoice(both)).toBe(true);
|
|
167
|
+
expect(tierHasChoice(tier({ payWhatYouWant: true, payWhatYouWantMinimum: 5 }))).toBe(true);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe("signed out, one free tier: the code is the last step", () => {
|
|
172
|
+
it("email -> code -> joined free, landing inside with welcome", async () => {
|
|
173
|
+
installAdapter(routes({ tiers: [free] }));
|
|
174
|
+
const { result } = renderHook(() => useCommunityJoin({ onJoined }), { wrapper: wrapper() });
|
|
175
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
176
|
+
expect(result.current.step).toBe("email");
|
|
177
|
+
|
|
178
|
+
await signUp(result);
|
|
179
|
+
|
|
180
|
+
await waitFor(() => expect(calls("post", "/public/payments/subscriptions/free")).toHaveLength(1));
|
|
181
|
+
expect(calls("post", "/public/payments/subscriptions/free")[0].body).toMatchObject({
|
|
182
|
+
membershipTierId: "tier-free",
|
|
183
|
+
profileId: "profile-1",
|
|
184
|
+
});
|
|
185
|
+
await waitFor(() => expect(result.current.step).toBe("joined"));
|
|
186
|
+
expect(onJoined).toHaveBeenCalledWith({ pending: false, requiresConfirmation: false, path: `${HOME}?welcome=1` });
|
|
187
|
+
expect(JSON.stringify(onJoined.mock.calls)).not.toContain("/i/account");
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
describe("signed in", () => {
|
|
192
|
+
it("several tiers: asks which, then joins the chosen one", async () => {
|
|
193
|
+
installAdapter(routes({ tiers: [free, paid] }));
|
|
194
|
+
const { result } = renderHook(() => useCommunityJoin({ onJoined }), { wrapper: wrapper({ user: account() }) });
|
|
195
|
+
await waitFor(() => expect(result.current.step).toBe("tier"));
|
|
196
|
+
expect(result.current.hasTierChoice).toBe(true);
|
|
197
|
+
act(() => result.current.selectTier(free));
|
|
198
|
+
await act(async () => {
|
|
199
|
+
await result.current.next();
|
|
200
|
+
});
|
|
201
|
+
await waitFor(() => expect(result.current.step).toBe("joined"));
|
|
202
|
+
expect(calls("post", "/public/payments/subscriptions/free")[0].body).toMatchObject({ membershipTierId: "tier-free" });
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("?tier= preselects a tier; a tier with a cycle choice still asks", async () => {
|
|
206
|
+
installAdapter(routes({ tiers: [free, both] }));
|
|
207
|
+
const { result } = renderHook(() => useCommunityJoin({ tierId: "tier-both", onJoined }), { wrapper: wrapper({ user: account() }) });
|
|
208
|
+
await waitFor(() => expect(result.current.selectedTier?.id).toBe("tier-both"));
|
|
209
|
+
expect(result.current.step).toBe("tier");
|
|
210
|
+
act(() => result.current.setBillingCycle("year"));
|
|
211
|
+
await act(async () => {
|
|
212
|
+
await result.current.next();
|
|
213
|
+
});
|
|
214
|
+
await waitFor(() => expect(result.current.step).toBe("payment"));
|
|
215
|
+
expect(calls("post", "/public/payments/subscriptions")[0].body).toMatchObject({
|
|
216
|
+
membershipTierId: "tier-both",
|
|
217
|
+
billingCycle: "year",
|
|
218
|
+
amount: 100,
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("questions: a blank required answer is refused before anything is sent, then the answers go with the join", async () => {
|
|
223
|
+
const withQuestions = tier({
|
|
224
|
+
id: "tier-q",
|
|
225
|
+
questionnaire: [{ id: "q-why", question: "Why?", type: "text", optional: false }] as never,
|
|
226
|
+
});
|
|
227
|
+
installAdapter(routes({ tiers: [withQuestions] }));
|
|
228
|
+
const { result } = renderHook(() => useCommunityJoin({ onJoined }), { wrapper: wrapper({ user: account() }) });
|
|
229
|
+
await waitFor(() => expect(result.current.step).toBe("questions"));
|
|
230
|
+
|
|
231
|
+
await act(async () => {
|
|
232
|
+
await result.current.next();
|
|
233
|
+
});
|
|
234
|
+
expect(result.current.questionnaireRefusal?.id).toBe("q-why");
|
|
235
|
+
expect(result.current.step).toBe("questions");
|
|
236
|
+
expect(calls("post", "/public/payments/subscriptions/free")).toHaveLength(0);
|
|
237
|
+
|
|
238
|
+
act(() => result.current.setQuestionnaireAnswer("q-why", "Big fan"));
|
|
239
|
+
await act(async () => {
|
|
240
|
+
await result.current.next();
|
|
241
|
+
});
|
|
242
|
+
await waitFor(() => expect(result.current.step).toBe("joined"));
|
|
243
|
+
expect(calls("post", "/public/payments/subscriptions/free")[0].body?.questionnaire).toEqual([
|
|
244
|
+
expect.objectContaining({ id: "q-why", answer: "Big fan" }),
|
|
245
|
+
]);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it("paid on Stripe: the card step, returning to the community home to reconcile", async () => {
|
|
249
|
+
installAdapter(routes({ tiers: [paid] }));
|
|
250
|
+
const { result } = renderHook(() => useCommunityJoin({ onJoined }), { wrapper: wrapper({ user: account() }) });
|
|
251
|
+
await waitFor(() => expect(result.current.step).toBe("payment"));
|
|
252
|
+
expect(result.current.clientSecret).toBe("pi_1_secret_2");
|
|
253
|
+
expect(result.current.paymentKind).toBe("payment");
|
|
254
|
+
expect(result.current.returnUrl).toBe(`${window.location.origin}${HOME}?confirmSubscription=1`);
|
|
255
|
+
expect(calls("post", "/public/payments/subscriptions")[0].body?.returnUrl).toBe(
|
|
256
|
+
`${window.location.origin}${HOME}?confirmSubscription=1`,
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
await act(async () => {
|
|
260
|
+
await result.current.onPaymentSucceeded();
|
|
261
|
+
});
|
|
262
|
+
expect(onJoined).toHaveBeenCalledWith({ pending: false, requiresConfirmation: true, path: `${HOME}?confirmSubscription=1` });
|
|
263
|
+
expect(result.current.step).toBe("joined");
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("paid on Paystack: the card step opens the provider's checkout", async () => {
|
|
267
|
+
installAdapter(
|
|
268
|
+
routes({
|
|
269
|
+
tiers: [paid],
|
|
270
|
+
extra: [
|
|
271
|
+
post("/public/payments/subscriptions", () => ({
|
|
272
|
+
membershipId: "m-1",
|
|
273
|
+
subscriptionId: "s-1",
|
|
274
|
+
accessCode: "ac_1",
|
|
275
|
+
checkoutUrl: "https://paystack.test/ac_1",
|
|
276
|
+
requiresPayment: true,
|
|
277
|
+
})),
|
|
278
|
+
],
|
|
279
|
+
}),
|
|
280
|
+
);
|
|
281
|
+
const { result } = renderHook(() => useCommunityJoin({ onJoined }), { wrapper: wrapper({ user: account() }) });
|
|
282
|
+
await waitFor(() => expect(result.current.step).toBe("payment"));
|
|
283
|
+
expect(result.current.isPaystack).toBe(true);
|
|
284
|
+
expect(result.current.clientSecret).toBeUndefined();
|
|
285
|
+
expect(paystack.open).toHaveBeenCalledWith(
|
|
286
|
+
expect.objectContaining({ accessCode: "ac_1", returnUrl: `${window.location.origin}${HOME}?confirmSubscription=1` }),
|
|
287
|
+
expect.anything(),
|
|
288
|
+
);
|
|
289
|
+
expect(onJoined).not.toHaveBeenCalled();
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it("apply-to-join lands inside, pending", async () => {
|
|
293
|
+
installAdapter(
|
|
294
|
+
routes({
|
|
295
|
+
tiers: [apply],
|
|
296
|
+
extra: [
|
|
297
|
+
post("/public/membership-applications", () => ({
|
|
298
|
+
application: { id: "app-1", membershipTierId: "tier-apply", status: "pending", createdAt: "2026-09-27T00:00:00.000Z" },
|
|
299
|
+
requiresCard: false,
|
|
300
|
+
clientSecret: null,
|
|
301
|
+
})),
|
|
302
|
+
],
|
|
303
|
+
}),
|
|
304
|
+
);
|
|
305
|
+
const { result } = renderHook(() => useCommunityJoin({ onJoined }), { wrapper: wrapper({ user: account() }) });
|
|
306
|
+
await waitFor(() => expect(result.current.step).toBe("pending"));
|
|
307
|
+
expect(calls("post", "/public/membership-applications")[0].body).toMatchObject({ membershipTierId: "tier-apply" });
|
|
308
|
+
expect(onJoined).toHaveBeenCalledWith({ pending: true, requiresConfirmation: false, path: HOME });
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("a member of THIS community is taken straight inside, and nothing is sent", async () => {
|
|
312
|
+
installAdapter(
|
|
313
|
+
routes({
|
|
314
|
+
tiers: [free],
|
|
315
|
+
me: () =>
|
|
316
|
+
viewer({
|
|
317
|
+
state: "member",
|
|
318
|
+
membership: {
|
|
319
|
+
id: "m-1",
|
|
320
|
+
tierId: "tier-free",
|
|
321
|
+
tierName: "Free",
|
|
322
|
+
status: "active",
|
|
323
|
+
cancelAtPeriodEnd: false,
|
|
324
|
+
currentPeriodEnd: null,
|
|
325
|
+
pendingDowngradeTierId: null,
|
|
326
|
+
},
|
|
327
|
+
}),
|
|
328
|
+
}),
|
|
329
|
+
);
|
|
330
|
+
const { result } = renderHook(() => useCommunityJoin({ onJoined }), { wrapper: wrapper({ user: account() }) });
|
|
331
|
+
await waitFor(() => expect(result.current.step).toBe("joined"));
|
|
332
|
+
expect(result.current.alreadyMember).toBe(true);
|
|
333
|
+
await waitFor(() => expect(onJoined).toHaveBeenCalledWith({ pending: false, requiresConfirmation: false, path: HOME }));
|
|
334
|
+
expect(calls("post", /\/public\/payments\/subscriptions/)).toHaveLength(0);
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
describe("invites", () => {
|
|
339
|
+
const emailInvite = (state: CommunityInviteState["state"], invitedEmail = "invited@example.com"): CommunityInviteState => ({
|
|
340
|
+
kind: "email",
|
|
341
|
+
state,
|
|
342
|
+
invitedEmail,
|
|
343
|
+
tier: state === "valid" || state === "email_mismatch" ? invited : null,
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it("a per-email invite presets its (invite-only) tier, prefills and locks the email, and forwards the token", async () => {
|
|
347
|
+
installAdapter(routes({ tiers: [free], invite: emailInvite("valid") }));
|
|
348
|
+
const { result } = renderHook(() => useCommunityJoin({ invite: "tok-1", onJoined }), { wrapper: wrapper() });
|
|
349
|
+
await waitFor(() => expect(result.current.emailLocked).toBe(true));
|
|
350
|
+
expect(result.current.emailFlow.email).toBe("invited@example.com");
|
|
351
|
+
expect(result.current.lockedEmail).toBe("invited@example.com");
|
|
352
|
+
|
|
353
|
+
await signUp(result);
|
|
354
|
+
|
|
355
|
+
await waitFor(() => expect(result.current.step).toBe("joined"));
|
|
356
|
+
const [join] = calls("post", "/public/payments/subscriptions/free");
|
|
357
|
+
expect(join.body).toMatchObject({ membershipTierId: "tier-vip", inviteToken: "tok-1" });
|
|
358
|
+
expect(join.body).not.toHaveProperty("joinToken");
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it("signed in as someone else: the mismatch is shown with Sign in as, which signs out into a locked sign-in", async () => {
|
|
362
|
+
const logout = vi.fn();
|
|
363
|
+
installAdapter(routes({ tiers: [free], invite: emailInvite("valid") }));
|
|
364
|
+
const { result } = renderHook(() => useCommunityJoin({ invite: "tok-1", onJoined }), {
|
|
365
|
+
wrapper: wrapper({ user: account("other@example.com"), controls: { logout } }),
|
|
366
|
+
});
|
|
367
|
+
await waitFor(() => expect(result.current.emailMismatch).not.toBeNull());
|
|
368
|
+
expect(result.current.step).toBe("email");
|
|
369
|
+
expect(result.current.emailMismatch).toEqual({ invitedEmail: "invited@example.com", signedInEmail: "other@example.com" });
|
|
370
|
+
expect(calls("post", /\/public\/payments\/subscriptions/)).toHaveLength(0);
|
|
371
|
+
|
|
372
|
+
await act(async () => {
|
|
373
|
+
await result.current.signInAsInvited();
|
|
374
|
+
});
|
|
375
|
+
expect(logout).toHaveBeenCalledTimes(1);
|
|
376
|
+
expect(result.current.mode).toBe("email");
|
|
377
|
+
expect(result.current.emailMismatch).toBeNull();
|
|
378
|
+
await waitFor(() => expect(result.current.emailFlow.email).toBe("invited@example.com"));
|
|
379
|
+
expect(result.current.emailLocked).toBe(true);
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it.each(["expired", "revoked", "used", "not_found"] as const)(
|
|
383
|
+
"a %s invite says why and falls back to the normal join, without the token",
|
|
384
|
+
async (state) => {
|
|
385
|
+
installAdapter(routes({ tiers: [free], invite: emailInvite(state) }));
|
|
386
|
+
const { result } = renderHook(() => useCommunityJoin({ invite: "tok-dead", onJoined }), { wrapper: wrapper({ user: account() }) });
|
|
387
|
+
await waitFor(() => expect(result.current.inviteProblem).toBe(state));
|
|
388
|
+
expect(result.current.emailLocked).toBe(false);
|
|
389
|
+
await waitFor(() => expect(result.current.step).toBe("joined"));
|
|
390
|
+
const [join] = calls("post", "/public/payments/subscriptions/free");
|
|
391
|
+
expect(join.body).toMatchObject({ membershipTierId: "tier-free" });
|
|
392
|
+
expect(join.body).not.toHaveProperty("inviteToken");
|
|
393
|
+
},
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
it("a shareable link presets its tier with no email lock and forwards the join token", async () => {
|
|
397
|
+
installAdapter(routes({ tiers: [free], invite: { kind: "link", state: "valid", invitedEmail: null, tier: invited } }));
|
|
398
|
+
const { result } = renderHook(() => useCommunityJoin({ join: "link-1", onJoined }), { wrapper: wrapper({ user: account() }) });
|
|
399
|
+
await waitFor(() => expect(result.current.step).toBe("joined"));
|
|
400
|
+
expect(result.current.emailLocked).toBe(false);
|
|
401
|
+
const [join] = calls("post", "/public/payments/subscriptions/free");
|
|
402
|
+
expect(join.body).toMatchObject({ membershipTierId: "tier-vip", joinToken: "link-1" });
|
|
403
|
+
expect(join.body).not.toHaveProperty("inviteToken");
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it("a used-up shareable link falls back without its token", async () => {
|
|
407
|
+
installAdapter(routes({ tiers: [free], invite: { kind: "link", state: "used_up", invitedEmail: null, tier: null } }));
|
|
408
|
+
const { result } = renderHook(() => useCommunityJoin({ join: "link-1", onJoined }), { wrapper: wrapper({ user: account() }) });
|
|
409
|
+
await waitFor(() => expect(result.current.inviteProblem).toBe("used_up"));
|
|
410
|
+
await waitFor(() => expect(result.current.step).toBe("joined"));
|
|
411
|
+
expect(calls("post", "/public/payments/subscriptions/free")[0].body).not.toHaveProperty("joinToken");
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
describe("email first", () => {
|
|
416
|
+
it("an address with an account: start, code, signed in by the code alone, then joined", async () => {
|
|
417
|
+
existingAccount = true;
|
|
418
|
+
const adopted = vi.fn();
|
|
419
|
+
installAdapter(routes({ tiers: [free] }));
|
|
420
|
+
const { result } = renderHook(() => useCommunityJoin({ onJoined }), { wrapper: wrapper({ controls: { adopted } }) });
|
|
421
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
422
|
+
expect(result.current.step).toBe("email");
|
|
423
|
+
expect(result.current.mode).toBe("email");
|
|
424
|
+
|
|
425
|
+
act(() => result.current.emailFlow.setEmail(" known@example.com "));
|
|
426
|
+
await press(result);
|
|
427
|
+
expect(result.current.step).toBe("code");
|
|
428
|
+
expect(result.current.codeEmail).toBe(" known@example.com ");
|
|
429
|
+
expect(calls("post", "/public/sessions/email/start").map((r) => r.body)).toEqual([
|
|
430
|
+
{ profileId: "profile-1", email: "known@example.com" },
|
|
431
|
+
]);
|
|
432
|
+
|
|
433
|
+
act(() => result.current.setCode("123456"));
|
|
434
|
+
await press(result);
|
|
435
|
+
expect(calls("post", "/public/sessions/email/verify").map((r) => r.body)).toEqual([
|
|
436
|
+
{ profileId: "profile-1", email: "known@example.com", code: "123456" },
|
|
437
|
+
]);
|
|
438
|
+
// The session went through the context's one storage path, untouched.
|
|
439
|
+
expect(adopted).toHaveBeenCalledWith({ token: "access-1", refreshToken: "refresh-1", account: account("known@example.com") });
|
|
440
|
+
expect(calls("post", "/public/sessions/email/complete")).toHaveLength(0);
|
|
441
|
+
|
|
442
|
+
await waitFor(() => expect(result.current.step).toBe("joined"));
|
|
443
|
+
expect(calls("post", "/public/payments/subscriptions/free")[0].body).toMatchObject({ membershipTierId: "tier-free" });
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it("a new address: the code is right, then a name and the terms, then signed in and joined", async () => {
|
|
447
|
+
const adopted = vi.fn();
|
|
448
|
+
installAdapter(routes({ tiers: [free] }));
|
|
449
|
+
const { result } = renderHook(() => useCommunityJoin({ onJoined }), { wrapper: wrapper({ controls: { adopted } }) });
|
|
450
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
451
|
+
|
|
452
|
+
act(() => result.current.emailFlow.setEmail("new@example.com"));
|
|
453
|
+
await press(result);
|
|
454
|
+
act(() => result.current.setCode("654321"));
|
|
455
|
+
await press(result);
|
|
456
|
+
expect(result.current.step).toBe("profile");
|
|
457
|
+
expect(adopted).not.toHaveBeenCalled();
|
|
458
|
+
|
|
459
|
+
// The terms are required before anything is sent.
|
|
460
|
+
act(() => {
|
|
461
|
+
result.current.emailFlow.setFirstName(" New ");
|
|
462
|
+
result.current.emailFlow.setLastName(" Person ");
|
|
463
|
+
});
|
|
464
|
+
await press(result);
|
|
465
|
+
expect(result.current.error).toBe("You must accept the Terms and Privacy Policy.");
|
|
466
|
+
expect(calls("post", "/public/sessions/email/complete")).toHaveLength(0);
|
|
467
|
+
|
|
468
|
+
act(() => result.current.emailFlow.setAcceptedTerms(true));
|
|
469
|
+
await press(result);
|
|
470
|
+
expect(calls("post", "/public/sessions/email/complete").map((r) => r.body)).toEqual([
|
|
471
|
+
{
|
|
472
|
+
profileId: "profile-1",
|
|
473
|
+
email: "new@example.com",
|
|
474
|
+
ticket: TICKET,
|
|
475
|
+
firstName: "New",
|
|
476
|
+
lastName: "Person",
|
|
477
|
+
acceptedTerms: true,
|
|
478
|
+
acceptedPrivacy: true,
|
|
479
|
+
},
|
|
480
|
+
]);
|
|
481
|
+
expect(adopted).toHaveBeenCalledWith({ token: "access-1", refreshToken: "refresh-1", account: account("new@example.com") });
|
|
482
|
+
await waitFor(() => expect(result.current.step).toBe("joined"));
|
|
483
|
+
expect(onJoined).toHaveBeenCalledWith({ pending: false, requiresConfirmation: false, path: `${HOME}?welcome=1` });
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
it("a wrong code says so and stays on the code step", async () => {
|
|
487
|
+
installAdapter(routes({ tiers: [free] }));
|
|
488
|
+
const { result } = renderHook(() => useCommunityJoin({ onJoined }), { wrapper: wrapper() });
|
|
489
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
490
|
+
act(() => result.current.emailFlow.setEmail("fan@example.com"));
|
|
491
|
+
await press(result);
|
|
492
|
+
act(() => result.current.setCode("000000"));
|
|
493
|
+
await press(result);
|
|
494
|
+
expect(result.current.step).toBe("code");
|
|
495
|
+
expect(result.current.error).toBe("Invalid or expired code.");
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
it("a code that is not six digits is refused before anything is sent", async () => {
|
|
499
|
+
installAdapter(routes({ tiers: [free] }));
|
|
500
|
+
const { result } = renderHook(() => useCommunityJoin({ onJoined }), { wrapper: wrapper() });
|
|
501
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
502
|
+
act(() => result.current.emailFlow.setEmail("fan@example.com"));
|
|
503
|
+
await press(result);
|
|
504
|
+
act(() => result.current.setCode("123"));
|
|
505
|
+
await press(result);
|
|
506
|
+
expect(result.current.error).toBe("Enter the 6-digit code we emailed you.");
|
|
507
|
+
expect(calls("post", "/public/sessions/email/verify")).toHaveLength(0);
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
it("an invalid email is refused before a code is asked for", async () => {
|
|
511
|
+
installAdapter(routes({ tiers: [free] }));
|
|
512
|
+
const { result } = renderHook(() => useCommunityJoin({ onJoined }), { wrapper: wrapper() });
|
|
513
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
514
|
+
act(() => result.current.emailFlow.setEmail("not-an-email"));
|
|
515
|
+
await press(result);
|
|
516
|
+
expect(result.current.step).toBe("email");
|
|
517
|
+
expect(result.current.error).toBe("Please enter a valid email.");
|
|
518
|
+
expect(calls("post", "/public/sessions/email/start")).toHaveLength(0);
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
it("resend asks for another code; a throttled resend shows the server's message", async () => {
|
|
522
|
+
let throttle = false;
|
|
523
|
+
installAdapter(
|
|
524
|
+
routes({
|
|
525
|
+
tiers: [free],
|
|
526
|
+
extra: [
|
|
527
|
+
post("/public/sessions/email/start", (req) => {
|
|
528
|
+
if (throttle) throw { status: 400, message: "A code was already sent. Please wait a minute." };
|
|
529
|
+
return { status: "code_sent", email: req.body?.email };
|
|
530
|
+
}),
|
|
531
|
+
],
|
|
532
|
+
}),
|
|
533
|
+
);
|
|
534
|
+
const { result } = renderHook(() => useCommunityJoin({ onJoined }), { wrapper: wrapper() });
|
|
535
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
536
|
+
act(() => result.current.emailFlow.setEmail("fan@example.com"));
|
|
537
|
+
await press(result);
|
|
538
|
+
await act(async () => {
|
|
539
|
+
await result.current.resendCode();
|
|
540
|
+
});
|
|
541
|
+
expect(calls("post", "/public/sessions/email/start")).toHaveLength(2);
|
|
542
|
+
expect(calls("post", "/public/sessions/email/start")[1].body).toEqual({ profileId: "profile-1", email: "fan@example.com" });
|
|
543
|
+
expect(result.current.emailFlow.resent).toBe(true);
|
|
544
|
+
|
|
545
|
+
throttle = true;
|
|
546
|
+
await act(async () => {
|
|
547
|
+
await result.current.resendCode();
|
|
548
|
+
});
|
|
549
|
+
expect(result.current.error).toBe("A code was already sent. Please wait a minute.");
|
|
550
|
+
expect(result.current.step).toBe("code");
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
it("use a different email goes back to the email step, keeping the address to correct", async () => {
|
|
554
|
+
installAdapter(routes({ tiers: [free] }));
|
|
555
|
+
const { result } = renderHook(() => useCommunityJoin({ onJoined }), { wrapper: wrapper() });
|
|
556
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
557
|
+
act(() => result.current.emailFlow.setEmail("typo@example.con"));
|
|
558
|
+
await press(result);
|
|
559
|
+
act(() => result.current.setCode("12"));
|
|
560
|
+
act(() => result.current.back());
|
|
561
|
+
expect(result.current.step).toBe("email");
|
|
562
|
+
expect(result.current.emailFlow.email).toBe("typo@example.con");
|
|
563
|
+
expect(result.current.code).toBe("");
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
it("use your password instead: the email and password sign-in, with the address carried over", async () => {
|
|
567
|
+
installAdapter(routes({ tiers: [free] }));
|
|
568
|
+
const { result } = renderHook(() => useCommunityJoin({ onJoined }), { wrapper: wrapper() });
|
|
569
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
570
|
+
act(() => result.current.emailFlow.setEmail("pw@example.com"));
|
|
571
|
+
act(() => result.current.switchToPassword());
|
|
572
|
+
expect(result.current.mode).toBe("signin");
|
|
573
|
+
expect(result.current.login.email).toBe("pw@example.com");
|
|
574
|
+
act(() => result.current.login.setPassword("password123"));
|
|
575
|
+
await press(result);
|
|
576
|
+
expect(result.current.step).toBe("code");
|
|
577
|
+
expect(result.current.codeEmail).toBe("pw@example.com");
|
|
578
|
+
act(() => result.current.setCode("123456"));
|
|
579
|
+
await press(result);
|
|
580
|
+
await waitFor(() => expect(result.current.step).toBe("joined"));
|
|
581
|
+
expect(calls("post", "/public/sessions/email/start")).toHaveLength(0);
|
|
582
|
+
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
it("switching back from the password sign-in returns to email first", async () => {
|
|
586
|
+
installAdapter(routes({ tiers: [free] }));
|
|
587
|
+
const { result } = renderHook(() => useCommunityJoin({ onJoined }), { wrapper: wrapper() });
|
|
588
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
589
|
+
act(() => result.current.switchToPassword());
|
|
590
|
+
act(() => result.current.login.setEmail("back@example.com"));
|
|
591
|
+
act(() => result.current.switchToEmailCode());
|
|
592
|
+
expect(result.current.mode).toBe("email");
|
|
593
|
+
expect(result.current.step).toBe("email");
|
|
594
|
+
expect(result.current.emailFlow.email).toBe("back@example.com");
|
|
595
|
+
});
|
|
596
|
+
});
|