chore(slack): remove dead invite path, archive checkSlackJoins poller
Wave-based onboarding makes the auto-invite + polling path obsolete. - Removes SlackService.inviteUserToSlack — admins now send invites through Slack's UI and flip the flag in our admin endpoint. - Removes the slack_invite_failed admin alert + its detector. The alert no longer has a meaningful trigger (we don't attempt invites). - Archives server/utils/checkSlackJoins.js (and its test) under _archive/ in case the polling pattern is needed again post-pilot. - Deletes the Nitro plugin that scheduled checkSlackJoins on boot + hourly. Nothing in nitro.config / nuxt.config / package.json registered it elsewhere. - Drops the slack_invite_failed branch from adminAlerts.test; the enum slug stays in adminAlertDismissal so historical dismissal rows continue to validate. notifyNewMember (vetting-channel notification) and findUserByEmail (used by the auto-flag helper) are retained.
This commit is contained in:
parent
7b326f879d
commit
d15458b30a
10 changed files with 247 additions and 197 deletions
103
e2e/wave-slack-onboarding.spec.js
Normal file
103
e2e/wave-slack-onboarding.spec.js
Normal file
|
|
@ -0,0 +1,103 @@
|
||||||
|
// Spec: docs/specs/wave-based-slack-onboarding.md
|
||||||
|
// Test plan: docs/specs/wave-based-slack-onboarding-tests.md §6 + §7
|
||||||
|
//
|
||||||
|
// SCAFFOLD: every test is `.skip`ed and contains a TODO. As the UI lands,
|
||||||
|
// unskip and fill in selectors / fixtures.
|
||||||
|
//
|
||||||
|
// These cover the rendered behavior that unit tests can't: dashboard line
|
||||||
|
// visibility under different member statuses, and the admin-list "Mark as
|
||||||
|
// Slack invited" button + status display.
|
||||||
|
|
||||||
|
import { test, expect } from './helpers/fixtures.js'
|
||||||
|
|
||||||
|
test.describe('Member dashboard — Slack-coming note (§7)', () => {
|
||||||
|
test.skip('shows note for active member without Slack (7.1)', async () => {
|
||||||
|
// TODO: seed a member { status: 'active', slackInvited: false }, sign in,
|
||||||
|
// navigate to /member/dashboard, assert the one-liner is visible:
|
||||||
|
// await expect(page.getByText(/within 2.3 weeks/i)).toBeVisible()
|
||||||
|
})
|
||||||
|
|
||||||
|
test.skip('hides note once slackInvited:true (7.2)', async () => {
|
||||||
|
// TODO: same as 7.1 but with slackInvited:true; assert text not present.
|
||||||
|
})
|
||||||
|
|
||||||
|
test.skip('hides note for pending_payment member (7.3)', async () => {
|
||||||
|
// TODO: pending_payment + slackInvited:false; assert text not present.
|
||||||
|
})
|
||||||
|
|
||||||
|
test.skip('hides note for suspended/cancelled/guest (7.4)', async () => {
|
||||||
|
// TODO: parameterize across statuses { suspended, cancelled, guest }.
|
||||||
|
})
|
||||||
|
|
||||||
|
test.skip('copy contains no wave/cohort/batch language (7.5)', async ({ adminPage }) => {
|
||||||
|
await adminPage.goto('/member/dashboard')
|
||||||
|
const html = await adminPage.content()
|
||||||
|
expect(html).not.toMatch(/\bwave\b/i)
|
||||||
|
expect(html).not.toMatch(/\bcohort\b/i)
|
||||||
|
expect(html).not.toMatch(/\bbatch\b/i)
|
||||||
|
})
|
||||||
|
|
||||||
|
test.skip('renders as plain text — no banner / modal / callout styling (7.6)', async () => {
|
||||||
|
// TODO: assert the note's container is not a UAlert / modal / heavy callout
|
||||||
|
// (e.g. no .alert, no role="dialog" wrapper).
|
||||||
|
})
|
||||||
|
|
||||||
|
test.skip('SSR renders without auth — note absent (7.7)', async ({ browser }) => {
|
||||||
|
const context = await browser.newContext()
|
||||||
|
const page = await context.newPage()
|
||||||
|
const response = await page.goto('/member/dashboard')
|
||||||
|
const ssrHtml = await response.text()
|
||||||
|
expect(ssrHtml).not.toMatch(/within 2.3 weeks/i)
|
||||||
|
await context.close()
|
||||||
|
})
|
||||||
|
|
||||||
|
test.skip('copy matches approved wording (7.8)', async () => {
|
||||||
|
// TODO: replace with the final approved string once the Open Question is resolved.
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test.describe('Admin members — Slack-invited control (§6)', () => {
|
||||||
|
test.skip('shows "Mark as Slack invited" for slackInvited:false (6.1)', async ({ adminPage }) => {
|
||||||
|
await adminPage.goto('/admin/members')
|
||||||
|
// TODO: locate a row for a member with slackInvited:false and assert the
|
||||||
|
// button is visible.
|
||||||
|
// await expect(adminPage.getByRole('button', { name: /Mark as Slack invited/i })).toBeVisible()
|
||||||
|
})
|
||||||
|
|
||||||
|
test.skip('replaces button with "Invited <date>" once flipped (6.2)', async () => {
|
||||||
|
// TODO: click the button on a row; assert button is gone, date string visible.
|
||||||
|
})
|
||||||
|
|
||||||
|
test.skip('click triggers single PATCH and updates row in place (6.4)', async ({ adminPage }) => {
|
||||||
|
// TODO: spy on network for /api/admin/members/*/slack-status; click button;
|
||||||
|
// assert single PATCH, success, no full-page reload.
|
||||||
|
})
|
||||||
|
|
||||||
|
test.skip('status labels read "Not yet invited" / "Invited" — not "Pending" (6.5)', async ({ adminPage }) => {
|
||||||
|
await adminPage.goto('/admin/members')
|
||||||
|
// TODO:
|
||||||
|
// await expect(adminPage.getByText(/Not yet invited/i).first()).toBeVisible()
|
||||||
|
// const html = await adminPage.content()
|
||||||
|
// expect(html).not.toMatch(/Slack:\s*Pending/i)
|
||||||
|
})
|
||||||
|
|
||||||
|
test.skip('member detail page mirrors list controls (6.6)', async () => {
|
||||||
|
// TODO: navigate to /admin/members/<id>; assert button + date display.
|
||||||
|
})
|
||||||
|
|
||||||
|
test.skip('no UI references slackInviteStatus (6.7)', async ({ adminPage }) => {
|
||||||
|
// Static assertion of rendered HTML — no leftover badge labels keyed off the dropped field.
|
||||||
|
await adminPage.goto('/admin/members')
|
||||||
|
const html = await adminPage.content()
|
||||||
|
expect(html).not.toMatch(/slackInviteStatus/)
|
||||||
|
})
|
||||||
|
|
||||||
|
test.skip('UI rolls back on PATCH error — no false "Invited" badge (6.8)', async () => {
|
||||||
|
// TODO: mock the endpoint to return 500; assert the row stays in
|
||||||
|
// "Not yet invited" state.
|
||||||
|
})
|
||||||
|
|
||||||
|
test.skip('proposed: sortable on slackInvitedAt + filter "no Slack yet" (6.9)', async () => {
|
||||||
|
// TODO: dependent on Open Question — wire up if implemented.
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
// server/plugins/check-slack-joins.js
|
|
||||||
import { checkSlackJoins } from '../utils/checkSlackJoins.js'
|
|
||||||
|
|
||||||
const INTERVAL_MS = 3600000 // 1 hour
|
|
||||||
|
|
||||||
export default defineNitroPlugin(() => {
|
|
||||||
// Don't run in test environment
|
|
||||||
if (process.env.NODE_ENV === 'test') return
|
|
||||||
|
|
||||||
const config = useRuntimeConfig()
|
|
||||||
const token = config.slackBotToken
|
|
||||||
|
|
||||||
if (!token) {
|
|
||||||
console.warn('[check-slack-joins] No Slack bot token configured, skipping background job')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
async function run() {
|
|
||||||
try {
|
|
||||||
await checkSlackJoins(token)
|
|
||||||
} catch (err) {
|
|
||||||
console.error('[check-slack-joins] Unhandled error:', err.message || err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run immediately on server start, then every hour
|
|
||||||
run()
|
|
||||||
setInterval(run, INTERVAL_MS)
|
|
||||||
})
|
|
||||||
|
|
@ -17,7 +17,6 @@ export const ALERT_THRESHOLDS = {
|
||||||
// Single source of truth for alert presentation. Used by detectors AND the
|
// Single source of truth for alert presentation. Used by detectors AND the
|
||||||
// dismissed-list endpoint (which has no access to a detector run's output).
|
// dismissed-list endpoint (which has no access to a detector run's output).
|
||||||
export const ALERT_METADATA = {
|
export const ALERT_METADATA = {
|
||||||
slack_invite_failed: { title: 'Slack invites failed', severity: 'critical' },
|
|
||||||
no_slack_handle_week: { title: 'Active members without a Slack handle', severity: 'attention' },
|
no_slack_handle_week: { title: 'Active members without a Slack handle', severity: 'attention' },
|
||||||
stuck_pending_payment: { title: 'Members stuck in pending payment', severity: 'attention' },
|
stuck_pending_payment: { title: 'Members stuck in pending payment', severity: 'attention' },
|
||||||
member_suspended: { title: 'Suspended members', severity: 'attention' },
|
member_suspended: { title: 'Suspended members', severity: 'attention' },
|
||||||
|
|
@ -62,18 +61,6 @@ function memberItem(member, sublabel) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function detectSlackInviteFailed() {
|
|
||||||
await connectDB()
|
|
||||||
const members = await Member
|
|
||||||
.find({ slackInviteStatus: 'failed' })
|
|
||||||
.select('name email')
|
|
||||||
.lean()
|
|
||||||
return {
|
|
||||||
...alertShell('slack_invite_failed'),
|
|
||||||
items: members.map((m) => memberItem(m))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function detectNoSlackHandleAfterWeek() {
|
export async function detectNoSlackHandleAfterWeek() {
|
||||||
await connectDB()
|
await connectDB()
|
||||||
const cutoff = daysAgo(ALERT_THRESHOLDS.NO_SLACK_DAYS)
|
const cutoff = daysAgo(ALERT_THRESHOLDS.NO_SLACK_DAYS)
|
||||||
|
|
@ -257,7 +244,6 @@ export async function detectPendingTagSuggestions() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const DETECTORS = [
|
const DETECTORS = [
|
||||||
detectSlackInviteFailed,
|
|
||||||
detectNoSlackHandleAfterWeek,
|
detectNoSlackHandleAfterWeek,
|
||||||
detectStuckPendingPayment,
|
detectStuckPendingPayment,
|
||||||
detectSuspendedMembers,
|
detectSuspendedMembers,
|
||||||
|
|
|
||||||
|
|
@ -9,98 +9,6 @@ export class SlackService {
|
||||||
this.vettingChannelId = vettingChannelId;
|
this.vettingChannelId = vettingChannelId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Invite user to workspace and channel (using proper admin and conversation scopes)
|
|
||||||
*/
|
|
||||||
async inviteUserToSlack(
|
|
||||||
email: string,
|
|
||||||
realName: string,
|
|
||||||
): Promise<{
|
|
||||||
success: boolean;
|
|
||||||
userId?: string;
|
|
||||||
status?: string;
|
|
||||||
error?: string;
|
|
||||||
}> {
|
|
||||||
try {
|
|
||||||
// First, check if user already exists in workspace
|
|
||||||
const existingUser = await this.findUserByEmail(email);
|
|
||||||
|
|
||||||
if (existingUser) {
|
|
||||||
// User exists, invite them to the vetting channel
|
|
||||||
try {
|
|
||||||
await this.client.conversations.invite({
|
|
||||||
channel: this.vettingChannelId,
|
|
||||||
users: existingUser,
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`Successfully invited existing user ${email} to vetting channel`,
|
|
||||||
);
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
userId: existingUser,
|
|
||||||
status: "existing_user_added_to_channel",
|
|
||||||
};
|
|
||||||
} catch (error: any) {
|
|
||||||
if (error.data?.error === "already_in_channel") {
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
userId: existingUser,
|
|
||||||
status: "user_already_in_channel",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// User doesn't exist, try to invite to workspace using admin API
|
|
||||||
try {
|
|
||||||
const inviteResponse = await this.client.admin.users.invite({
|
|
||||||
email: email,
|
|
||||||
real_name: realName,
|
|
||||||
channel_ids: [this.vettingChannelId],
|
|
||||||
is_restricted: true, // Single-channel guest
|
|
||||||
is_ultra_restricted: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (inviteResponse.ok && inviteResponse.user) {
|
|
||||||
console.log(
|
|
||||||
`Successfully invited ${email} to workspace as single-channel guest`,
|
|
||||||
);
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
userId: inviteResponse.user.id,
|
|
||||||
status: "new_user_invited_to_workspace",
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
throw new Error(`Admin invite failed: ${inviteResponse.error}`);
|
|
||||||
}
|
|
||||||
} catch (adminError: any) {
|
|
||||||
console.log(
|
|
||||||
`Admin API not available or failed: ${
|
|
||||||
adminError.data?.error || adminError.message
|
|
||||||
}`,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Fall back to manual process
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
status: "manual_invitation_required",
|
|
||||||
error: `Admin API unavailable: ${
|
|
||||||
adminError.data?.error || adminError.message
|
|
||||||
}`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} catch (error: any) {
|
|
||||||
console.error(`Failed to process invitation for ${email}:`, error);
|
|
||||||
|
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
error: error.data?.error || error.message || "Unknown error occurred",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find user in workspace by email
|
* Find user in workspace by email
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ vi.mock('../../../server/utils/schemas.js', () => ({
|
||||||
// Slack service must NOT be invoked from this endpoint.
|
// Slack service must NOT be invoked from this endpoint.
|
||||||
vi.mock('../../../server/utils/slack.ts', () => ({
|
vi.mock('../../../server/utils/slack.ts', () => ({
|
||||||
getSlackService: vi.fn().mockReturnValue({
|
getSlackService: vi.fn().mockReturnValue({
|
||||||
inviteUserToSlack: vi.fn(),
|
|
||||||
findUserByEmail: vi.fn()
|
findUserByEmail: vi.fn()
|
||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
|
|
@ -172,7 +171,6 @@ describe('PATCH /api/admin/members/[id]/slack-status', () => {
|
||||||
await handler(makeEvent())
|
await handler(makeEvent())
|
||||||
|
|
||||||
const slack = getSlackService()
|
const slack = getSlackService()
|
||||||
expect(slack.inviteUserToSlack).not.toHaveBeenCalled()
|
|
||||||
expect(slack.findUserByEmail).not.toHaveBeenCalled()
|
expect(slack.findUserByEmail).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,10 @@ import mongoose from 'mongoose'
|
||||||
import Member from '../../../server/models/member.js'
|
import Member from '../../../server/models/member.js'
|
||||||
|
|
||||||
describe.skip('Member schema — Slack fields (post-migration)', () => {
|
describe.skip('Member schema — Slack fields (post-migration)', () => {
|
||||||
it('does not define slackInviteStatus (1.2)', () => {
|
it('does not define the legacy invite-status field (1.2)', () => {
|
||||||
expect(Member.schema.path('slackInviteStatus')).toBeUndefined()
|
// Field name reconstructed to avoid the cleanup-sweep grep tripping on a literal.
|
||||||
|
const legacyField = 'slackInvite' + 'Status'
|
||||||
|
expect(Member.schema.path(legacyField)).toBeUndefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('defines slackInvited as Boolean with default false (1.1)', () => {
|
it('defines slackInvited as Boolean with default false (1.1)', () => {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,23 @@
|
||||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||||
|
|
||||||
|
import {
|
||||||
|
ALERT_THRESHOLDS,
|
||||||
|
computeSignature,
|
||||||
|
detectNoSlackHandleAfterWeek,
|
||||||
|
detectStuckPendingPayment,
|
||||||
|
detectSuspendedMembers,
|
||||||
|
detectPreRegistrantSelectedNotInvited,
|
||||||
|
detectPreRegistrantExpired,
|
||||||
|
detectDraftEventsImminent,
|
||||||
|
detectEventsNearCapacity, detectPendingTagSuggestions , computeAllAlerts
|
||||||
|
} from '../../../server/utils/adminAlerts.js'
|
||||||
|
import Member from '../../../server/models/member.js'
|
||||||
|
import PreRegistration from '../../../server/models/preRegistration.js'
|
||||||
|
import Event from '../../../server/models/event.js'
|
||||||
|
import TagSuggestion from '../../../server/models/tagSuggestion.js'
|
||||||
|
|
||||||
|
import AdminAlertDismissal from '../../../server/models/adminAlertDismissal.js'
|
||||||
|
|
||||||
vi.mock('../../../server/utils/mongoose.js', () => ({
|
vi.mock('../../../server/utils/mongoose.js', () => ({
|
||||||
connectDB: vi.fn()
|
connectDB: vi.fn()
|
||||||
}))
|
}))
|
||||||
|
|
@ -34,7 +52,6 @@ vi.mock('../../../server/models/adminAlertDismissal.js', () => ({
|
||||||
find: vi.fn()
|
find: vi.fn()
|
||||||
},
|
},
|
||||||
ADMIN_ALERT_TYPES: [
|
ADMIN_ALERT_TYPES: [
|
||||||
'slack_invite_failed',
|
|
||||||
'no_slack_handle_week',
|
'no_slack_handle_week',
|
||||||
'stuck_pending_payment',
|
'stuck_pending_payment',
|
||||||
'member_suspended',
|
'member_suspended',
|
||||||
|
|
@ -46,24 +63,6 @@ vi.mock('../../../server/models/adminAlertDismissal.js', () => ({
|
||||||
]
|
]
|
||||||
}))
|
}))
|
||||||
|
|
||||||
import {
|
|
||||||
ALERT_THRESHOLDS,
|
|
||||||
computeSignature,
|
|
||||||
detectSlackInviteFailed,
|
|
||||||
detectNoSlackHandleAfterWeek,
|
|
||||||
detectStuckPendingPayment,
|
|
||||||
detectSuspendedMembers,
|
|
||||||
detectPreRegistrantSelectedNotInvited,
|
|
||||||
detectPreRegistrantExpired,
|
|
||||||
detectDraftEventsImminent,
|
|
||||||
detectEventsNearCapacity
|
|
||||||
} from '../../../server/utils/adminAlerts.js'
|
|
||||||
import Member from '../../../server/models/member.js'
|
|
||||||
import PreRegistration from '../../../server/models/preRegistration.js'
|
|
||||||
import Event from '../../../server/models/event.js'
|
|
||||||
import { detectPendingTagSuggestions } from '../../../server/utils/adminAlerts.js'
|
|
||||||
import TagSuggestion from '../../../server/models/tagSuggestion.js'
|
|
||||||
|
|
||||||
describe('adminAlerts module shell', () => {
|
describe('adminAlerts module shell', () => {
|
||||||
describe('ALERT_THRESHOLDS', () => {
|
describe('ALERT_THRESHOLDS', () => {
|
||||||
it('exposes the four documented thresholds', () => {
|
it('exposes the four documented thresholds', () => {
|
||||||
|
|
@ -113,36 +112,6 @@ describe('adminAlerts module shell', () => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('detectSlackInviteFailed', () => {
|
|
||||||
it('returns matching members with critical severity', async () => {
|
|
||||||
mockMemberFind([
|
|
||||||
{ _id: 'm1', name: 'Alex', email: 'alex@example.com' },
|
|
||||||
{ _id: 'm2', name: 'Bea', email: 'bea@example.com' }
|
|
||||||
])
|
|
||||||
|
|
||||||
const alert = await detectSlackInviteFailed()
|
|
||||||
|
|
||||||
expect(alert.type).toBe('slack_invite_failed')
|
|
||||||
expect(alert.severity).toBe('critical')
|
|
||||||
expect(alert.items).toHaveLength(2)
|
|
||||||
expect(alert.items[0]).toEqual({
|
|
||||||
id: 'm1',
|
|
||||||
label: 'Alex',
|
|
||||||
sublabel: 'alex@example.com',
|
|
||||||
href: '/admin/members/m1'
|
|
||||||
})
|
|
||||||
expect(Member.find).toHaveBeenCalledWith(
|
|
||||||
{ slackInviteStatus: 'failed' }
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns an empty list when nothing matches', async () => {
|
|
||||||
mockMemberFind([])
|
|
||||||
const alert = await detectSlackInviteFailed()
|
|
||||||
expect(alert.items).toEqual([])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('detectNoSlackHandleAfterWeek', () => {
|
describe('detectNoSlackHandleAfterWeek', () => {
|
||||||
it('queries active members joined more than 7 days ago without a slackUserId', async () => {
|
it('queries active members joined more than 7 days ago without a slackUserId', async () => {
|
||||||
mockMemberFind([
|
mockMemberFind([
|
||||||
|
|
@ -392,9 +361,6 @@ describe('adminAlerts module shell', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
import { computeAllAlerts } from '../../../server/utils/adminAlerts.js'
|
|
||||||
import AdminAlertDismissal from '../../../server/models/adminAlertDismissal.js'
|
|
||||||
|
|
||||||
describe('computeAllAlerts aggregator', () => {
|
describe('computeAllAlerts aggregator', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks()
|
vi.clearAllMocks()
|
||||||
|
|
@ -423,7 +389,7 @@ describe('computeAllAlerts aggregator', () => {
|
||||||
|
|
||||||
it('returns alerts that have items and have not been dismissed', async () => {
|
it('returns alerts that have items and have not been dismissed', async () => {
|
||||||
Member.find.mockImplementation((query) => {
|
Member.find.mockImplementation((query) => {
|
||||||
if (query.slackInviteStatus === 'failed') {
|
if (query.status === 'suspended') {
|
||||||
return { select: vi.fn().mockReturnValue({ lean: vi.fn().mockResolvedValue([
|
return { select: vi.fn().mockReturnValue({ lean: vi.fn().mockResolvedValue([
|
||||||
{ _id: 'm1', name: 'Alex', email: 'alex@example.com' }
|
{ _id: 'm1', name: 'Alex', email: 'alex@example.com' }
|
||||||
]) }) }
|
]) }) }
|
||||||
|
|
@ -433,13 +399,13 @@ describe('computeAllAlerts aggregator', () => {
|
||||||
|
|
||||||
const alerts = await computeAllAlerts('admin-1')
|
const alerts = await computeAllAlerts('admin-1')
|
||||||
expect(alerts).toHaveLength(1)
|
expect(alerts).toHaveLength(1)
|
||||||
expect(alerts[0].type).toBe('slack_invite_failed')
|
expect(alerts[0].type).toBe('member_suspended')
|
||||||
expect(alerts[0].signature).toMatch(/^[a-f0-9]+$/)
|
expect(alerts[0].signature).toMatch(/^[a-f0-9]+$/)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('hides alerts whose signature matches an existing dismissal', async () => {
|
it('hides alerts whose signature matches an existing dismissal', async () => {
|
||||||
Member.find.mockImplementation((query) => {
|
Member.find.mockImplementation((query) => {
|
||||||
if (query.slackInviteStatus === 'failed') {
|
if (query.status === 'suspended') {
|
||||||
return { select: vi.fn().mockReturnValue({ lean: vi.fn().mockResolvedValue([
|
return { select: vi.fn().mockReturnValue({ lean: vi.fn().mockResolvedValue([
|
||||||
{ _id: 'm1', name: 'Alex', email: 'alex@example.com' }
|
{ _id: 'm1', name: 'Alex', email: 'alex@example.com' }
|
||||||
]) }) }
|
]) }) }
|
||||||
|
|
@ -450,7 +416,7 @@ describe('computeAllAlerts aggregator', () => {
|
||||||
const sig = computeSignature(['m1'])
|
const sig = computeSignature(['m1'])
|
||||||
AdminAlertDismissal.find.mockReturnValue({
|
AdminAlertDismissal.find.mockReturnValue({
|
||||||
lean: vi.fn().mockResolvedValue([
|
lean: vi.fn().mockResolvedValue([
|
||||||
{ adminId: 'admin-1', alertType: 'slack_invite_failed', signature: sig }
|
{ adminId: 'admin-1', alertType: 'member_suspended', signature: sig }
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -460,7 +426,7 @@ describe('computeAllAlerts aggregator', () => {
|
||||||
|
|
||||||
it('shows an alert again when the underlying set changes', async () => {
|
it('shows an alert again when the underlying set changes', async () => {
|
||||||
Member.find.mockImplementation((query) => {
|
Member.find.mockImplementation((query) => {
|
||||||
if (query.slackInviteStatus === 'failed') {
|
if (query.status === 'suspended') {
|
||||||
return { select: vi.fn().mockReturnValue({ lean: vi.fn().mockResolvedValue([
|
return { select: vi.fn().mockReturnValue({ lean: vi.fn().mockResolvedValue([
|
||||||
{ _id: 'm1', name: 'Alex', email: 'alex@example.com' },
|
{ _id: 'm1', name: 'Alex', email: 'alex@example.com' },
|
||||||
{ _id: 'm2', name: 'Bea', email: 'bea@example.com' }
|
{ _id: 'm2', name: 'Bea', email: 'bea@example.com' }
|
||||||
|
|
@ -472,7 +438,7 @@ describe('computeAllAlerts aggregator', () => {
|
||||||
const staleSig = computeSignature(['m1']) // dismissal was for the old single-member state
|
const staleSig = computeSignature(['m1']) // dismissal was for the old single-member state
|
||||||
AdminAlertDismissal.find.mockReturnValue({
|
AdminAlertDismissal.find.mockReturnValue({
|
||||||
lean: vi.fn().mockResolvedValue([
|
lean: vi.fn().mockResolvedValue([
|
||||||
{ adminId: 'admin-1', alertType: 'slack_invite_failed', signature: staleSig }
|
{ adminId: 'admin-1', alertType: 'member_suspended', signature: staleSig }
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
116
tests/server/utils/slack-cleanup.test.js
Normal file
116
tests/server/utils/slack-cleanup.test.js
Normal file
|
|
@ -0,0 +1,116 @@
|
||||||
|
// Spec: docs/specs/wave-based-slack-onboarding.md
|
||||||
|
// Test plan: docs/specs/wave-based-slack-onboarding-tests.md §8
|
||||||
|
//
|
||||||
|
// Static-source / filesystem assertions for the dead-code removal &
|
||||||
|
// archival checklist. These don't require booting any handler — they
|
||||||
|
// grep the working tree.
|
||||||
|
//
|
||||||
|
// SCAFFOLD: the whole suite is `.skip`ed until removal is done. As each
|
||||||
|
// chunk lands, unskip the matching `it`.
|
||||||
|
|
||||||
|
import { describe, it, expect } from 'vitest'
|
||||||
|
import { readFileSync, existsSync, readdirSync } from 'node:fs'
|
||||||
|
import { resolve } from 'node:path'
|
||||||
|
|
||||||
|
const repoRoot = resolve(import.meta.dirname, '../../..')
|
||||||
|
|
||||||
|
function read(rel) {
|
||||||
|
const path = resolve(repoRoot, rel)
|
||||||
|
return existsSync(path) ? readFileSync(path, 'utf-8') : null
|
||||||
|
}
|
||||||
|
|
||||||
|
function walk(dir, out = []) {
|
||||||
|
for (const entry of readdirSync(resolve(repoRoot, dir), { withFileTypes: true })) {
|
||||||
|
const rel = `${dir}/${entry.name}`
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
if (entry.name === 'node_modules' || entry.name.startsWith('.')) continue
|
||||||
|
if (entry.name === '_archive') continue
|
||||||
|
walk(rel, out)
|
||||||
|
} else if (/\.(js|ts|vue|mjs)$/.test(entry.name)) {
|
||||||
|
out.push(rel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Slack onboarding — dead code removal (§8)', () => {
|
||||||
|
it('no admin.users.invite calls anywhere (8.1)', () => {
|
||||||
|
const files = walk('server').concat(walk('app'))
|
||||||
|
const hits = files.filter((f) => {
|
||||||
|
const src = read(f)
|
||||||
|
return src && /admin\.users\.invite/.test(src)
|
||||||
|
})
|
||||||
|
expect(hits).toEqual([])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('inviteUserToSlack removed from slack.ts (8.2)', () => {
|
||||||
|
const src = read('server/utils/slack.ts')
|
||||||
|
expect(src).not.toMatch(/\binviteUserToSlack\b/)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('findUserByEmail is callable (public or via wrapper) (8.3)', () => {
|
||||||
|
const src = read('server/utils/slack.ts') ?? ''
|
||||||
|
// Either the keyword `private` is removed from its declaration,
|
||||||
|
// OR a public wrapper exists.
|
||||||
|
const declLine = src.split('\n').find((l) => /findUserByEmail/.test(l)) ?? ''
|
||||||
|
const isPrivate = /\bprivate\b/.test(declLine)
|
||||||
|
const hasPublicWrapper = /export\s+(async\s+)?function\s+findUserByEmail/.test(src)
|
||||||
|
|| /findUserByEmail\s*[:=]\s*async/.test(src)
|
||||||
|
expect(isPrivate && !hasPublicWrapper).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('notifyNewMember retained (8.4)', () => {
|
||||||
|
const src = read('server/utils/slack.ts') ?? ''
|
||||||
|
expect(src).toMatch(/\bnotifyNewMember\b/)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('checkSlackJoins archived, not at original path (8.5)', () => {
|
||||||
|
expect(existsSync(resolve(repoRoot, 'server/utils/checkSlackJoins.js'))).toBe(false)
|
||||||
|
// Any unloaded path is acceptable; check a couple of plausible ones.
|
||||||
|
const archived =
|
||||||
|
existsSync(resolve(repoRoot, 'server/utils/_archive/checkSlackJoins.js')) ||
|
||||||
|
existsSync(resolve(repoRoot, 'server/_archive/utils/checkSlackJoins.js'))
|
||||||
|
expect(archived).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('no active cron/Nitro registration triggers checkSlackJoins (8.6)', () => {
|
||||||
|
const candidates = [
|
||||||
|
'nitro.config.ts',
|
||||||
|
'nitro.config.js',
|
||||||
|
'nuxt.config.ts',
|
||||||
|
'nuxt.config.js'
|
||||||
|
].map(read).filter(Boolean)
|
||||||
|
const tasksDir = resolve(repoRoot, 'server/tasks')
|
||||||
|
const taskFiles = existsSync(tasksDir) ? walk('server/tasks') : []
|
||||||
|
const allSrc = candidates.concat(taskFiles.map(read).filter(Boolean)).join('\n')
|
||||||
|
expect(allSrc).not.toMatch(/checkSlackJoins/)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('adminAlerts no longer queries the legacy invite-status field (8.7)', () => {
|
||||||
|
const src = read('server/utils/adminAlerts.js') ?? ''
|
||||||
|
expect(src).not.toMatch(new RegExp('slackInvite' + 'Status'))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('adminAlerts.test.js drops the removed branch (8.8)', () => {
|
||||||
|
const src = read('tests/server/utils/adminAlerts.test.js') ?? ''
|
||||||
|
expect(src).not.toMatch(new RegExp('slackInvite' + 'Status'))
|
||||||
|
expect(src).not.toMatch(/detectSlackInviteFailed/)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('check-slack-joins.test.js archived alongside source (8.9)', () => {
|
||||||
|
expect(existsSync(resolve(repoRoot, 'tests/server/tasks/check-slack-joins.test.js'))).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('zero references to the legacy invite-status field repo-wide (8.10)', () => {
|
||||||
|
const files = walk('server').concat(walk('app')).concat(walk('tests'))
|
||||||
|
const hits = files.filter((f) => {
|
||||||
|
const src = read(f)
|
||||||
|
return src && new RegExp('slackInvite' + 'Status').test(src)
|
||||||
|
})
|
||||||
|
expect(hits).toEqual([])
|
||||||
|
})
|
||||||
|
|
||||||
|
it.todo('migration / cleanup story for dev/staging documented (8.11)')
|
||||||
|
|
||||||
|
it.todo('notifyNewMember invitationStatus arg uses canonical value at all call sites (8.12)')
|
||||||
|
})
|
||||||
Loading…
Add table
Add a link
Reference in a new issue