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.
49 lines
1.6 KiB
JavaScript
49 lines
1.6 KiB
JavaScript
import { vi } from 'vitest'
|
|
import {
|
|
getCookie,
|
|
setCookie,
|
|
getMethod,
|
|
getHeader,
|
|
getHeaders,
|
|
setHeader,
|
|
getRequestURL,
|
|
createError,
|
|
defineEventHandler,
|
|
readBody,
|
|
getQuery,
|
|
getRouterParam,
|
|
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)
|
|
vi.stubGlobal('setCookie', setCookie)
|
|
vi.stubGlobal('getMethod', getMethod)
|
|
vi.stubGlobal('getHeader', getHeader)
|
|
vi.stubGlobal('getHeaders', getHeaders)
|
|
vi.stubGlobal('setHeader', setHeader)
|
|
vi.stubGlobal('getRequestURL', getRequestURL)
|
|
vi.stubGlobal('createError', createError)
|
|
vi.stubGlobal('defineEventHandler', defineEventHandler)
|
|
vi.stubGlobal('readBody', readBody)
|
|
vi.stubGlobal('getQuery', getQuery)
|
|
vi.stubGlobal('getRouterParam', getRouterParam)
|
|
vi.stubGlobal('sendRedirect', sendRedirect)
|
|
|
|
vi.stubGlobal('useRuntimeConfig', () => ({
|
|
jwtSecret: 'test-jwt-secret',
|
|
helcimApiToken: 'test-helcim-token'
|
|
}))
|
|
|
|
// Stubs for Nitro auto-imported server/utils (used by handlers that don't explicitly import them)
|
|
vi.stubGlobal('requireAuth', vi.fn())
|
|
vi.stubGlobal('requireAdmin', vi.fn())
|
|
vi.stubGlobal('validateBody', vi.fn(async (event) => readBody(event)))
|
|
vi.stubGlobal('logActivity', vi.fn())
|
|
vi.stubGlobal('validateTagSlugs', vi.fn())
|
|
vi.stubGlobal('autoFlagPreExistingSlackAccess', vi.fn().mockResolvedValue(undefined))
|
|
vi.stubGlobal('escapeRegex', escapeRegex)
|