@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,179 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
3
|
+
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
4
|
+
import { communityDowngradeTiers, communityMembershipBilling, useCommunityMembership } from "../communities/useCommunityMembership";
|
|
5
|
+
import { account, calls, detailRoute, installAdapter, meRoute, post, restoreAdapter, tier, viewer, wrapper } from "./communityHarness";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The Membership menu: cancel keeps the paid period and is two-step, a
|
|
9
|
+
* downgrade waits for period end and can be withdrawn, and every action is
|
|
10
|
+
* addressed to THIS community.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
afterEach(restoreAdapter);
|
|
14
|
+
|
|
15
|
+
const free = tier({ id: "tier-free", name: "Free" });
|
|
16
|
+
const basic = tier({ id: "tier-basic", name: "Basic", priceMonthly: 5 });
|
|
17
|
+
const gold = tier({ id: "tier-gold", name: "Gold", priceMonthly: 20 });
|
|
18
|
+
const yearlyCheap = tier({ id: "tier-yearly", name: "Yearly", priceYearly: 60 });
|
|
19
|
+
const apply = tier({ id: "tier-apply", name: "Apply", priceMonthly: 1, joinMode: "application" });
|
|
20
|
+
|
|
21
|
+
let state = viewer();
|
|
22
|
+
const onGold = (patch: Record<string, unknown> = {}) =>
|
|
23
|
+
viewer({
|
|
24
|
+
state: "member",
|
|
25
|
+
membership: {
|
|
26
|
+
id: "m-1",
|
|
27
|
+
tierId: "tier-gold",
|
|
28
|
+
tierName: "Gold",
|
|
29
|
+
status: "active",
|
|
30
|
+
cancelAtPeriodEnd: false,
|
|
31
|
+
currentPeriodEnd: "2026-10-27T00:00:00.000Z",
|
|
32
|
+
pendingDowngradeTierId: null,
|
|
33
|
+
...patch,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
function install() {
|
|
38
|
+
installAdapter([
|
|
39
|
+
post("/public/communities/fan-club/membership/cancel", () => {
|
|
40
|
+
state = onGold({ cancelAtPeriodEnd: true });
|
|
41
|
+
return {};
|
|
42
|
+
}),
|
|
43
|
+
post("/public/communities/fan-club/membership/downgrade", (req) => {
|
|
44
|
+
state = onGold({ pendingDowngradeTierId: req.body?.membershipTierId });
|
|
45
|
+
return {};
|
|
46
|
+
}),
|
|
47
|
+
post("/public/communities/fan-club/membership/undo-downgrade", () => {
|
|
48
|
+
state = onGold();
|
|
49
|
+
return {};
|
|
50
|
+
}),
|
|
51
|
+
meRoute(() => state),
|
|
52
|
+
detailRoute(() => ({ tiers: [free, basic, gold, yearlyCheap, apply] })),
|
|
53
|
+
]);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
describe("communityDowngradeTiers", () => {
|
|
57
|
+
it("lists cheaper tiers of this community, on a monthly footing, never an application tier or an upgrade", () => {
|
|
58
|
+
const tiers = [free, basic, gold, yearlyCheap, apply];
|
|
59
|
+
expect(communityDowngradeTiers(tiers, "tier-gold", []).map((t) => t.id)).toEqual(["tier-free", "tier-basic", "tier-yearly"]);
|
|
60
|
+
expect(communityDowngradeTiers(tiers, "tier-gold", ["tier-basic"]).map((t) => t.id)).toEqual(["tier-free", "tier-yearly"]);
|
|
61
|
+
expect(communityDowngradeTiers(tiers, "tier-free", [])).toEqual([]);
|
|
62
|
+
expect(communityDowngradeTiers(tiers, null, [])).toEqual([]);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("communityMembershipBilling", () => {
|
|
67
|
+
it("reads the member's own subscription: amount, currency and cycle", () => {
|
|
68
|
+
expect(communityMembershipBilling({ amount: 12.5, currency: "EUR", billingCycle: "year" }, basic)).toEqual({
|
|
69
|
+
isPaid: true,
|
|
70
|
+
amount: 12.5,
|
|
71
|
+
currency: "EUR",
|
|
72
|
+
cycle: "year",
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("no price on the row is a free membership, whatever the tier says", () => {
|
|
77
|
+
expect(communityMembershipBilling({ amount: null, currency: null, billingCycle: null }, gold)).toEqual({
|
|
78
|
+
isPaid: false,
|
|
79
|
+
amount: null,
|
|
80
|
+
currency: null,
|
|
81
|
+
cycle: null,
|
|
82
|
+
});
|
|
83
|
+
expect(communityMembershipBilling({ amount: 0, currency: "USD", billingCycle: "month" }, gold).isPaid).toBe(false);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("until the row arrives, the tier's own price decides paid or free, with no amount shown", () => {
|
|
87
|
+
expect(communityMembershipBilling(null, gold)).toEqual({ isPaid: true, amount: null, currency: null, cycle: null });
|
|
88
|
+
expect(communityMembershipBilling(null, free).isPaid).toBe(false);
|
|
89
|
+
expect(communityMembershipBilling(null, yearlyCheap).isPaid).toBe(true);
|
|
90
|
+
expect(communityMembershipBilling(undefined, null).isPaid).toBe(false);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("useCommunityMembership", () => {
|
|
95
|
+
it("shows the tier, the renewal date and what it can move down to", async () => {
|
|
96
|
+
state = onGold();
|
|
97
|
+
install();
|
|
98
|
+
const { result } = renderHook(() => useCommunityMembership(), { wrapper: wrapper({ user: account() }) });
|
|
99
|
+
await waitFor(() => expect(result.current.hasMembership).toBe(true));
|
|
100
|
+
expect(result.current.membership?.tierName).toBe("Gold");
|
|
101
|
+
expect(result.current.periodEnd).toBe("2026-10-27T00:00:00.000Z");
|
|
102
|
+
await waitFor(() => expect(result.current.downgradeTiers.map((t) => t.id)).toEqual(["tier-free", "tier-basic", "tier-yearly"]));
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("cancel asks first, then cancels in this community and keeps the period", async () => {
|
|
106
|
+
state = onGold();
|
|
107
|
+
install();
|
|
108
|
+
const { result } = renderHook(() => useCommunityMembership(), { wrapper: wrapper({ user: account() }) });
|
|
109
|
+
await waitFor(() => expect(result.current.hasMembership).toBe(true));
|
|
110
|
+
act(() => result.current.requestCancel());
|
|
111
|
+
expect(result.current.cancelRequested).toBe(true);
|
|
112
|
+
expect(calls("post", /cancel$/)).toHaveLength(0);
|
|
113
|
+
|
|
114
|
+
await act(async () => {
|
|
115
|
+
await result.current.confirmCancel();
|
|
116
|
+
});
|
|
117
|
+
expect(calls("post", "/public/communities/fan-club/membership/cancel")[0].body).toEqual({ profileId: "profile-1" });
|
|
118
|
+
await waitFor(() => expect(result.current.isCancelling).toBe(true));
|
|
119
|
+
expect(result.current.cancelRequested).toBe(false);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("abort leaves the membership alone", async () => {
|
|
123
|
+
state = onGold();
|
|
124
|
+
install();
|
|
125
|
+
const { result } = renderHook(() => useCommunityMembership(), { wrapper: wrapper({ user: account() }) });
|
|
126
|
+
await waitFor(() => expect(result.current.hasMembership).toBe(true));
|
|
127
|
+
act(() => result.current.requestCancel());
|
|
128
|
+
act(() => result.current.abortCancel());
|
|
129
|
+
expect(result.current.cancelRequested).toBe(false);
|
|
130
|
+
expect(calls("post", /cancel$/)).toHaveLength(0);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("downgrade waits for period end and shows as pending; undo withdraws it", async () => {
|
|
134
|
+
state = onGold();
|
|
135
|
+
install();
|
|
136
|
+
const { result } = renderHook(() => useCommunityMembership(), { wrapper: wrapper({ user: account() }) });
|
|
137
|
+
await waitFor(() => expect(result.current.hasMembership).toBe(true));
|
|
138
|
+
|
|
139
|
+
await act(async () => {
|
|
140
|
+
await result.current.downgrade("tier-basic");
|
|
141
|
+
});
|
|
142
|
+
expect(calls("post", "/public/communities/fan-club/membership/downgrade")[0].body).toEqual({
|
|
143
|
+
profileId: "profile-1",
|
|
144
|
+
membershipTierId: "tier-basic",
|
|
145
|
+
});
|
|
146
|
+
await waitFor(() => expect(result.current.pendingDowngradeTier?.name).toBe("Basic"));
|
|
147
|
+
|
|
148
|
+
await act(async () => {
|
|
149
|
+
await result.current.undoDowngrade();
|
|
150
|
+
});
|
|
151
|
+
expect(calls("post", "/public/communities/fan-club/membership/undo-downgrade")).toHaveLength(1);
|
|
152
|
+
await waitFor(() => expect(result.current.pendingDowngradeTier).toBeNull());
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("a refused action is reported, not swallowed", async () => {
|
|
156
|
+
state = onGold();
|
|
157
|
+
installAdapter([
|
|
158
|
+
post("/public/communities/fan-club/membership/cancel", () => {
|
|
159
|
+
throw { status: 400, message: "Already cancelled." };
|
|
160
|
+
}),
|
|
161
|
+
meRoute(() => state),
|
|
162
|
+
detailRoute(() => ({ tiers: [gold] })),
|
|
163
|
+
]);
|
|
164
|
+
const { result } = renderHook(() => useCommunityMembership(), { wrapper: wrapper({ user: account() }) });
|
|
165
|
+
await waitFor(() => expect(result.current.hasMembership).toBe(true));
|
|
166
|
+
await act(async () => {
|
|
167
|
+
await result.current.cancel();
|
|
168
|
+
});
|
|
169
|
+
expect(result.current.error).toBe("Already cancelled.");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("has nothing to manage for a non-member", async () => {
|
|
173
|
+
state = viewer();
|
|
174
|
+
install();
|
|
175
|
+
const { result } = renderHook(() => useCommunityMembership(), { wrapper: wrapper({ user: account() }) });
|
|
176
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
177
|
+
expect(result.current.hasMembership).toBe(false);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
3
|
+
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
4
|
+
import {
|
|
5
|
+
communityMuteUntil,
|
|
6
|
+
describeHoldReason,
|
|
7
|
+
describeModerationNotification,
|
|
8
|
+
moderationErrorMessage,
|
|
9
|
+
restorableLogEntries,
|
|
10
|
+
useCommunityModeration,
|
|
11
|
+
useCommunityModeratorActions,
|
|
12
|
+
} from "../community/useCommunityModeration";
|
|
13
|
+
import { useMemberHomeNav } from "../memberHome/useMemberHomeNav";
|
|
14
|
+
import type { CommunityModerationLogEntry } from "../../../data/queries/useCommunityModeration";
|
|
15
|
+
import {
|
|
16
|
+
COMMUNITY,
|
|
17
|
+
PROFILE_ID,
|
|
18
|
+
account,
|
|
19
|
+
calls,
|
|
20
|
+
get,
|
|
21
|
+
installAdapter,
|
|
22
|
+
post,
|
|
23
|
+
restoreAdapter,
|
|
24
|
+
wrapper,
|
|
25
|
+
} from "./communityHarness";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Moderation from the site. The server decides who may moderate; these pin
|
|
29
|
+
* what the site SENDS (every body names the profile, a mute names the
|
|
30
|
+
* community), that nothing is asked for until the viewer is known to moderate
|
|
31
|
+
* this community, and the small readings a renderer depends on: hold reasons
|
|
32
|
+
* in words, which log entries can still be undone, and which notifications
|
|
33
|
+
* carry a moderation outcome.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
afterEach(restoreAdapter);
|
|
37
|
+
|
|
38
|
+
const me = (canModerate: boolean) =>
|
|
39
|
+
get("/public/community/me", () => ({
|
|
40
|
+
accountId: "account-1",
|
|
41
|
+
role: canModerate ? "moderator" : "member",
|
|
42
|
+
canModerate,
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
const QUEUE = {
|
|
46
|
+
reports: {
|
|
47
|
+
data: [
|
|
48
|
+
{
|
|
49
|
+
id: "rep-1",
|
|
50
|
+
entityType: "community_post",
|
|
51
|
+
entityId: "post-9",
|
|
52
|
+
reason: "spam",
|
|
53
|
+
reporterFirstName: "Ada",
|
|
54
|
+
reporterLastName: "L",
|
|
55
|
+
contentPreview: "buy now",
|
|
56
|
+
contentHidden: false,
|
|
57
|
+
createdAt: "2026-09-01T00:00:00.000Z",
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
total: 1,
|
|
61
|
+
},
|
|
62
|
+
pending: {
|
|
63
|
+
posts: [
|
|
64
|
+
{
|
|
65
|
+
id: "post-1",
|
|
66
|
+
spaceId: "space-1",
|
|
67
|
+
spaceName: "General",
|
|
68
|
+
title: "Hello",
|
|
69
|
+
bodyText: "first post",
|
|
70
|
+
authorAccountId: "account-2",
|
|
71
|
+
authorName: "New Fan",
|
|
72
|
+
moderationReason: "approval_new_member",
|
|
73
|
+
createdAt: "2026-09-01T00:00:00.000Z",
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
replies: [
|
|
77
|
+
{
|
|
78
|
+
id: "reply-1",
|
|
79
|
+
postId: "post-5",
|
|
80
|
+
postTitle: "Tour",
|
|
81
|
+
bodyText: "a reply",
|
|
82
|
+
authorAccountId: "account-3",
|
|
83
|
+
authorName: "Other Fan",
|
|
84
|
+
moderationReason: "keyword:spoiler",
|
|
85
|
+
createdAt: "2026-09-01T00:00:00.000Z",
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const logEntry = (overrides: Partial<CommunityModerationLogEntry>): CommunityModerationLogEntry => ({
|
|
92
|
+
id: "log-x",
|
|
93
|
+
action: "remove",
|
|
94
|
+
entityType: "community_post",
|
|
95
|
+
entityId: "post-1",
|
|
96
|
+
actorAccountId: "account-1",
|
|
97
|
+
targetAccountId: "account-2",
|
|
98
|
+
reason: null,
|
|
99
|
+
createdAt: "2026-09-01T00:00:00.000Z",
|
|
100
|
+
actorName: "Mod",
|
|
101
|
+
targetName: "Fan",
|
|
102
|
+
...overrides,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe("describeHoldReason", () => {
|
|
106
|
+
it("reads the three reasons the server writes", () => {
|
|
107
|
+
expect(describeHoldReason("approval_new_member")).toEqual({ kind: "new_member" });
|
|
108
|
+
expect(describeHoldReason("approval_all")).toEqual({ kind: "all_posts" });
|
|
109
|
+
expect(describeHoldReason("keyword:spoiler alert")).toEqual({ kind: "keyword", word: "spoiler alert" });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("passes an unknown reason through, and nothing for none", () => {
|
|
113
|
+
expect(describeHoldReason("something_new")).toEqual({ kind: "other", raw: "something_new" });
|
|
114
|
+
expect(describeHoldReason(null)).toBeNull();
|
|
115
|
+
expect(describeHoldReason("")).toBeNull();
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe("communityMuteUntil", () => {
|
|
120
|
+
it("adds whole days to now", () => {
|
|
121
|
+
const now = new Date("2026-09-29T12:00:00.000Z");
|
|
122
|
+
expect(communityMuteUntil(1, now)).toBe("2026-09-30T12:00:00.000Z");
|
|
123
|
+
expect(communityMuteUntil(7, now)).toBe("2026-10-06T12:00:00.000Z");
|
|
124
|
+
expect(communityMuteUntil(30, now)).toBe("2026-10-29T12:00:00.000Z");
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe("moderationErrorMessage", () => {
|
|
129
|
+
it("returns the server's message, or null", () => {
|
|
130
|
+
const banned = { response: { status: 403, data: { message: "You can no longer take part in this community." } } };
|
|
131
|
+
expect(moderationErrorMessage(banned)).toBe("You can no longer take part in this community.");
|
|
132
|
+
expect(moderationErrorMessage(new Error("network"))).toBeNull();
|
|
133
|
+
expect(moderationErrorMessage({ response: { data: { message: " " } } })).toBeNull();
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe("describeModerationNotification", () => {
|
|
138
|
+
it("reads an outcome on a post or reply", () => {
|
|
139
|
+
expect(
|
|
140
|
+
describeModerationNotification({
|
|
141
|
+
type: "mod",
|
|
142
|
+
entityType: "community_post",
|
|
143
|
+
data: { outcome: "approved", reason: null },
|
|
144
|
+
}),
|
|
145
|
+
).toEqual({ outcome: "approved", subject: "post", reason: null });
|
|
146
|
+
expect(
|
|
147
|
+
describeModerationNotification({
|
|
148
|
+
type: "mod",
|
|
149
|
+
entityType: "community_reply",
|
|
150
|
+
data: { outcome: "rejected", reason: " off topic " },
|
|
151
|
+
}),
|
|
152
|
+
).toEqual({ outcome: "rejected", subject: "reply", reason: "off topic" });
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("leaves the mute notice (about the community, no data) and other types alone", () => {
|
|
156
|
+
expect(describeModerationNotification({ type: "mod", entityType: "community", data: null })).toBeNull();
|
|
157
|
+
expect(describeModerationNotification({ type: "mod", entityType: "community", entityId: "c" } as never)).toBeNull();
|
|
158
|
+
expect(
|
|
159
|
+
describeModerationNotification({ type: "reply", entityType: "community_post", data: { outcome: "approved" } }),
|
|
160
|
+
).toBeNull();
|
|
161
|
+
expect(
|
|
162
|
+
describeModerationNotification({ type: "mod", entityType: "community_post", data: { outcome: "maybe" } }),
|
|
163
|
+
).toBeNull();
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
describe("restorableLogEntries", () => {
|
|
168
|
+
it("offers restore on a removal nothing newer has restored", () => {
|
|
169
|
+
const entries = [
|
|
170
|
+
logEntry({ id: "log-3", action: "remove", entityId: "post-2" }),
|
|
171
|
+
logEntry({ id: "log-2", action: "restore", entityId: "post-1" }),
|
|
172
|
+
logEntry({ id: "log-1", action: "remove", entityId: "post-1" }),
|
|
173
|
+
];
|
|
174
|
+
const restorable = restorableLogEntries(entries);
|
|
175
|
+
expect([...restorable.keys()]).toEqual(["log-3"]);
|
|
176
|
+
expect(restorable.get("log-3")).toEqual({ type: "post", id: "post-2" });
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("covers a report resolved by hiding, and replies, and only the newest removal of one thing", () => {
|
|
180
|
+
const entries = [
|
|
181
|
+
logEntry({ id: "log-3", action: "report_resolved_hidden", entityType: "community_reply", entityId: "reply-1" }),
|
|
182
|
+
logEntry({ id: "log-2", action: "remove", entityType: "community_reply", entityId: "reply-1" }),
|
|
183
|
+
logEntry({ id: "log-1", action: "pin", entityId: "post-1" }),
|
|
184
|
+
logEntry({ id: "log-0", action: "mute", entityType: null, entityId: null }),
|
|
185
|
+
];
|
|
186
|
+
const restorable = restorableLogEntries(entries);
|
|
187
|
+
expect([...restorable.keys()]).toEqual(["log-3"]);
|
|
188
|
+
expect(restorable.get("log-3")).toEqual({ type: "reply", id: "reply-1" });
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe("useCommunityModeration", () => {
|
|
193
|
+
it("asks for nothing and says so when the viewer does not moderate", async () => {
|
|
194
|
+
installAdapter([me(false)]);
|
|
195
|
+
const { result } = renderHook(() => useCommunityModeration(), { wrapper: wrapper({ user: account() }) });
|
|
196
|
+
await waitFor(() => expect(result.current.isChecking).toBe(false));
|
|
197
|
+
expect(result.current.canModerate).toBe(false);
|
|
198
|
+
expect(calls("get", "/public/community-moderation/queue")).toHaveLength(0);
|
|
199
|
+
expect(calls("get", "/public/community-moderation/log")).toHaveLength(0);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("asks for nothing when signed out", async () => {
|
|
203
|
+
installAdapter([me(true)]);
|
|
204
|
+
const { result } = renderHook(() => useCommunityModeration(), { wrapper: wrapper() });
|
|
205
|
+
expect(result.current.canModerate).toBe(false);
|
|
206
|
+
expect(calls("get", "/public/community/me")).toHaveLength(0);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("loads the queue and the log for THIS community", async () => {
|
|
210
|
+
installAdapter([
|
|
211
|
+
me(true),
|
|
212
|
+
get("/public/community-moderation/queue", () => QUEUE),
|
|
213
|
+
get("/public/community-moderation/log", () => ({
|
|
214
|
+
data: [logEntry({ id: "log-1" })],
|
|
215
|
+
total: 21,
|
|
216
|
+
page: 1,
|
|
217
|
+
pageSize: 20,
|
|
218
|
+
hasNextPage: true,
|
|
219
|
+
})),
|
|
220
|
+
]);
|
|
221
|
+
const { result } = renderHook(() => useCommunityModeration(), { wrapper: wrapper({ user: account() }) });
|
|
222
|
+
await waitFor(() => expect(result.current.reports).toHaveLength(1));
|
|
223
|
+
expect(result.current.pendingPosts[0].id).toBe("post-1");
|
|
224
|
+
expect(result.current.pendingReplies[0].id).toBe("reply-1");
|
|
225
|
+
expect(calls("get", "/public/community-moderation/queue")[0].params).toEqual({
|
|
226
|
+
profileId: PROFILE_ID,
|
|
227
|
+
communityId: COMMUNITY.id,
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
await waitFor(() => expect(result.current.log.entries).toHaveLength(1));
|
|
231
|
+
expect(result.current.log.hasNextPage).toBe(true);
|
|
232
|
+
expect(result.current.log.restorable.has("log-1")).toBe(true);
|
|
233
|
+
expect(calls("get", "/public/community-moderation/log")[0].params).toEqual({
|
|
234
|
+
profileId: PROFILE_ID,
|
|
235
|
+
communityId: COMMUNITY.id,
|
|
236
|
+
page: 1,
|
|
237
|
+
limit: 20,
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
act(() => result.current.log.nextPage());
|
|
241
|
+
await waitFor(() =>
|
|
242
|
+
expect(calls("get", "/public/community-moderation/log").some((r) => r.params?.page === 2)).toBe(true),
|
|
243
|
+
);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("sends each queue action with the profile, and the reason where one is given", async () => {
|
|
247
|
+
installAdapter([
|
|
248
|
+
me(true),
|
|
249
|
+
get("/public/community-moderation/queue", () => QUEUE),
|
|
250
|
+
get("/public/community-moderation/log", () => ({
|
|
251
|
+
data: [],
|
|
252
|
+
total: 0,
|
|
253
|
+
page: 1,
|
|
254
|
+
pageSize: 20,
|
|
255
|
+
hasNextPage: false,
|
|
256
|
+
})),
|
|
257
|
+
post("/public/community-moderation/reports/rep-1/resolve", () => ({ success: true })),
|
|
258
|
+
post("/public/community-moderation/posts/post-1/approve", () => ({ id: "post-1" })),
|
|
259
|
+
post("/public/community-moderation/posts/post-1/reject", () => ({ success: true })),
|
|
260
|
+
post("/public/community-moderation/replies/reply-1/reject", () => ({ success: true })),
|
|
261
|
+
]);
|
|
262
|
+
const { result } = renderHook(() => useCommunityModeration(), { wrapper: wrapper({ user: account() }) });
|
|
263
|
+
await waitFor(() => expect(result.current.reports).toHaveLength(1));
|
|
264
|
+
|
|
265
|
+
await act(async () => {
|
|
266
|
+
expect(await result.current.resolveReport("rep-1", "resolve_and_hide")).toBe(true);
|
|
267
|
+
});
|
|
268
|
+
expect(calls("post", "/public/community-moderation/reports/rep-1/resolve")[0].body).toEqual({
|
|
269
|
+
profileId: PROFILE_ID,
|
|
270
|
+
action: "resolved",
|
|
271
|
+
hideContent: true,
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
await act(async () => {
|
|
275
|
+
await result.current.resolveReport("rep-1", "dismiss");
|
|
276
|
+
});
|
|
277
|
+
expect(calls("post", "/public/community-moderation/reports/rep-1/resolve")[1].body).toMatchObject({
|
|
278
|
+
action: "dismissed",
|
|
279
|
+
hideContent: false,
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
await act(async () => {
|
|
283
|
+
await result.current.approvePost({ id: "post-1" });
|
|
284
|
+
await result.current.rejectPost({ id: "post-1" }, " off topic ");
|
|
285
|
+
await result.current.rejectReply({ id: "reply-1", postId: "post-5" }, "");
|
|
286
|
+
});
|
|
287
|
+
expect(calls("post", "/public/community-moderation/posts/post-1/approve")[0].body).toEqual({
|
|
288
|
+
profileId: PROFILE_ID,
|
|
289
|
+
});
|
|
290
|
+
expect(calls("post", "/public/community-moderation/posts/post-1/reject")[0].body).toEqual({
|
|
291
|
+
profileId: PROFILE_ID,
|
|
292
|
+
reason: "off topic",
|
|
293
|
+
});
|
|
294
|
+
// A blank reason is not sent at all.
|
|
295
|
+
expect(calls("post", "/public/community-moderation/replies/reply-1/reject")[0].body).toEqual({
|
|
296
|
+
profileId: PROFILE_ID,
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it("keeps the server's refusal on the row it happened to (approving twice is a 409)", async () => {
|
|
301
|
+
installAdapter([
|
|
302
|
+
me(true),
|
|
303
|
+
get("/public/community-moderation/queue", () => QUEUE),
|
|
304
|
+
get("/public/community-moderation/log", () => ({
|
|
305
|
+
data: [],
|
|
306
|
+
total: 0,
|
|
307
|
+
page: 1,
|
|
308
|
+
pageSize: 20,
|
|
309
|
+
hasNextPage: false,
|
|
310
|
+
})),
|
|
311
|
+
post("/public/community-moderation/posts/post-1/approve", () => {
|
|
312
|
+
throw { status: 409, message: "This is not waiting for approval." };
|
|
313
|
+
}),
|
|
314
|
+
]);
|
|
315
|
+
const { result } = renderHook(() => useCommunityModeration(), { wrapper: wrapper({ user: account() }) });
|
|
316
|
+
await waitFor(() => expect(result.current.pendingPosts).toHaveLength(1));
|
|
317
|
+
await act(async () => {
|
|
318
|
+
expect(await result.current.approvePost({ id: "post-1" })).toBe(false);
|
|
319
|
+
});
|
|
320
|
+
expect(result.current.error).toEqual({ id: "post-1", message: "This is not waiting for approval." });
|
|
321
|
+
expect(result.current.busyId).toBeNull();
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
describe("useCommunityModeratorActions", () => {
|
|
326
|
+
it("is not a moderator until /me says so", async () => {
|
|
327
|
+
installAdapter([me(false)]);
|
|
328
|
+
const { result } = renderHook(() => useCommunityModeratorActions(), { wrapper: wrapper({ user: account() }) });
|
|
329
|
+
await waitFor(() => expect(calls("get", "/public/community/me")).toHaveLength(1));
|
|
330
|
+
expect(result.current.canModerate).toBe(false);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it("pins, removes with a reason, and mutes the author in THIS community", async () => {
|
|
334
|
+
installAdapter([
|
|
335
|
+
me(true),
|
|
336
|
+
post("/public/community-moderation/posts/post-1/pin", () => ({ id: "post-1", isPinned: true })),
|
|
337
|
+
post("/public/community-moderation/posts/post-1/remove", () => ({ success: true })),
|
|
338
|
+
post("/public/community-moderation/replies/reply-1/remove", () => ({ success: true })),
|
|
339
|
+
post("/public/community-moderation/members/account-2/mute", () => ({ success: true })),
|
|
340
|
+
]);
|
|
341
|
+
const { result } = renderHook(() => useCommunityModeratorActions(), { wrapper: wrapper({ user: account() }) });
|
|
342
|
+
await waitFor(() => expect(result.current.canModerate).toBe(true));
|
|
343
|
+
expect(result.current.currentAccountId).toBe("account-1");
|
|
344
|
+
|
|
345
|
+
const before = Date.now();
|
|
346
|
+
await act(async () => {
|
|
347
|
+
await result.current.pinPost({ id: "post-1" });
|
|
348
|
+
await result.current.removePost({ id: "post-1" }, "spam");
|
|
349
|
+
await result.current.removeReply({ id: "reply-1", postId: "post-1" });
|
|
350
|
+
await result.current.muteMember("account-2", 7);
|
|
351
|
+
});
|
|
352
|
+
expect(calls("post", "/public/community-moderation/posts/post-1/pin")[0].body).toEqual({ profileId: PROFILE_ID });
|
|
353
|
+
expect(calls("post", "/public/community-moderation/posts/post-1/remove")[0].body).toEqual({
|
|
354
|
+
profileId: PROFILE_ID,
|
|
355
|
+
reason: "spam",
|
|
356
|
+
});
|
|
357
|
+
expect(calls("post", "/public/community-moderation/replies/reply-1/remove")[0].body).toEqual({
|
|
358
|
+
profileId: PROFILE_ID,
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
const mute = calls("post", "/public/community-moderation/members/account-2/mute")[0].body!;
|
|
362
|
+
expect(mute.profileId).toBe(PROFILE_ID);
|
|
363
|
+
expect(mute.communityId).toBe(COMMUNITY.id);
|
|
364
|
+
const until = new Date(mute.mutedUntil as string).getTime();
|
|
365
|
+
expect(until - before).toBeGreaterThanOrEqual(7 * 24 * 3600 * 1000 - 1000);
|
|
366
|
+
expect(until - before).toBeLessThan(7 * 24 * 3600 * 1000 + 60_000);
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it("unmutes with a null time", async () => {
|
|
370
|
+
installAdapter([me(true), post("/public/community-moderation/members/account-2/mute", () => ({ success: true }))]);
|
|
371
|
+
const { result } = renderHook(() => useCommunityModeratorActions(), { wrapper: wrapper({ user: account() }) });
|
|
372
|
+
await waitFor(() => expect(result.current.canModerate).toBe(true));
|
|
373
|
+
await act(async () => {
|
|
374
|
+
await result.current.unmuteMember("account-2");
|
|
375
|
+
});
|
|
376
|
+
expect(calls("post", "/public/community-moderation/members/account-2/mute")[0].body).toEqual({
|
|
377
|
+
profileId: PROFILE_ID,
|
|
378
|
+
communityId: COMMUNITY.id,
|
|
379
|
+
mutedUntil: null,
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it("surfaces a refusal as the server worded it", async () => {
|
|
384
|
+
installAdapter([
|
|
385
|
+
me(true),
|
|
386
|
+
post("/public/community-moderation/posts/post-1/lock", () => {
|
|
387
|
+
throw { status: 404, message: "Post not found" };
|
|
388
|
+
}),
|
|
389
|
+
]);
|
|
390
|
+
const { result } = renderHook(() => useCommunityModeratorActions(), { wrapper: wrapper({ user: account() }) });
|
|
391
|
+
await waitFor(() => expect(result.current.canModerate).toBe(true));
|
|
392
|
+
await act(async () => {
|
|
393
|
+
expect(await result.current.lockPost({ id: "post-1" })).toBe(false);
|
|
394
|
+
});
|
|
395
|
+
expect(result.current.failed).toBe(true);
|
|
396
|
+
expect(result.current.error).toBe("Post not found");
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
describe("the Moderation tab in the member home nav", () => {
|
|
401
|
+
it("shows only to a moderator of this community", async () => {
|
|
402
|
+
installAdapter([me(true)]);
|
|
403
|
+
const { result } = renderHook(() => useMemberHomeNav({ currentPath: "/i/communities/fan-club/home/moderation" }), {
|
|
404
|
+
wrapper: wrapper({ user: account() }),
|
|
405
|
+
});
|
|
406
|
+
await waitFor(() => expect(result.current.visibleItems.map((i) => i.key)).toContain("moderation"));
|
|
407
|
+
expect(result.current.activeKey).toBe("moderation");
|
|
408
|
+
expect(result.current.items.find((i) => i.key === "moderation")?.href).toBe(
|
|
409
|
+
"/i/communities/fan-club/home/moderation",
|
|
410
|
+
);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it("stays hidden for a member who does not moderate", async () => {
|
|
414
|
+
installAdapter([me(false)]);
|
|
415
|
+
const { result } = renderHook(() => useMemberHomeNav({}), { wrapper: wrapper({ user: account() }) });
|
|
416
|
+
await waitFor(() => expect(calls("get", "/public/community/me")).toHaveLength(1));
|
|
417
|
+
await waitFor(() => expect(result.current.isReady).toBe(true));
|
|
418
|
+
expect(result.current.visibleItems.map((i) => i.key)).not.toContain("moderation");
|
|
419
|
+
});
|
|
420
|
+
});
|