feat(activation): wire autoFlagPreExistingSlackAccess into self-serve paths

Replaces the per-file inviteToSlack helpers with a single auto-flag
call. Self-serve activation paths now check for pre-existing workspace
membership (silent on miss) instead of attempting an admin-only invite.

- helcim/subscription.post.js: removed local inviteToSlack; both
  free- and paid-tier activation branches now call the helper, then
  notifyNewMember with the canonical 'manual_invitation_required' arg.
- members/create.post.js: same shape — helper + canonical notify arg.
- invite/accept.post.js (free-tier branch): added the helper call after
  member creation. Free-tier had no prior Slack call (audit confirmed);
  paid-tier remains untouched and activates via the Helcim webhook.

Admin-created and CSV-imported members intentionally do NOT call the
helper — admins flip the flag manually after sending the invite.

Test stub for autoFlagPreExistingSlackAccess added to server setup.
This commit is contained in:
Jennie Robinson Faber 2026-04-29 12:21:12 +01:00
parent b1d8cb1966
commit 55029e7eb7
5 changed files with 262 additions and 152 deletions

View file

@ -15,6 +15,9 @@ import {
sendRedirect
} from 'h3'
// Real server/utils that are safe to use as-is in tests
import { escapeRegex } from '../../server/utils/escapeRegex.js'
// Register real h3 functions as globals so server code that relies on
// Nitro auto-imports can find them in the test environment.
vi.stubGlobal('getCookie', getCookie)
@ -42,7 +45,5 @@ vi.stubGlobal('requireAdmin', vi.fn())
vi.stubGlobal('validateBody', vi.fn(async (event) => readBody(event)))
vi.stubGlobal('logActivity', vi.fn())
vi.stubGlobal('validateTagSlugs', vi.fn())
// Real server/utils that are safe to use as-is in tests
import { escapeRegex } from '../../server/utils/escapeRegex.js'
vi.stubGlobal('autoFlagPreExistingSlackAccess', vi.fn().mockResolvedValue(undefined))
vi.stubGlobal('escapeRegex', escapeRegex)