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
151
tests/_archive/server/tasks/check-slack-joins.test.js
Normal file
151
tests/_archive/server/tasks/check-slack-joins.test.js
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
|
||||
// Hoist mock functions so vi.mock factories can reference them
|
||||
const { mockFind, mockFindByIdAndUpdate, mockLookupByEmail } = vi.hoisted(() => ({
|
||||
mockFind: vi.fn(),
|
||||
mockFindByIdAndUpdate: vi.fn(),
|
||||
mockLookupByEmail: vi.fn()
|
||||
}))
|
||||
|
||||
// Mock mongoose connection
|
||||
vi.mock('../../../server/utils/mongoose.js', () => ({
|
||||
connectDB: vi.fn()
|
||||
}))
|
||||
|
||||
// Mock Member model
|
||||
vi.mock('../../../server/models/member.js', () => ({
|
||||
default: {
|
||||
find: mockFind,
|
||||
findByIdAndUpdate: mockFindByIdAndUpdate
|
||||
}
|
||||
}))
|
||||
|
||||
// Mock @slack/web-api — use function expression so `new WebClient()` works
|
||||
vi.mock('@slack/web-api', () => ({
|
||||
WebClient: vi.fn().mockImplementation(function () {
|
||||
this.users = { lookupByEmail: mockLookupByEmail }
|
||||
})
|
||||
}))
|
||||
|
||||
import { checkSlackJoins } from '../../../server/utils/checkSlackJoins.js'
|
||||
|
||||
describe('checkSlackJoins', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
// Default: find returns empty with select chain
|
||||
mockFind.mockReturnValue({ select: vi.fn().mockResolvedValue([]) })
|
||||
})
|
||||
|
||||
it('8.1: detects joined member — updates status and stores slackUserId', async () => {
|
||||
mockFind.mockReturnValue({
|
||||
select: vi.fn().mockResolvedValue([
|
||||
{ _id: 'm1', email: 'alice@example.com', slackInviteStatus: 'sent' }
|
||||
])
|
||||
})
|
||||
mockLookupByEmail.mockResolvedValue({ user: { id: 'U123ABC' } })
|
||||
mockFindByIdAndUpdate.mockResolvedValue({})
|
||||
|
||||
const result = await checkSlackJoins('xoxb-test-token')
|
||||
|
||||
expect(mockLookupByEmail).toHaveBeenCalledWith({ email: 'alice@example.com' })
|
||||
expect(mockFindByIdAndUpdate).toHaveBeenCalledWith('m1', {
|
||||
slackInviteStatus: 'joined',
|
||||
slackUserId: 'U123ABC'
|
||||
})
|
||||
expect(result).toEqual({ checked: 1, joined: 1 })
|
||||
})
|
||||
|
||||
it('8.2: no change when member not found in Slack', async () => {
|
||||
mockFind.mockReturnValue({
|
||||
select: vi.fn().mockResolvedValue([
|
||||
{ _id: 'm2', email: 'bob@example.com', slackInviteStatus: 'sent' }
|
||||
])
|
||||
})
|
||||
// Slack throws users_not_found for unknown emails
|
||||
mockLookupByEmail.mockRejectedValue({ data: { error: 'users_not_found' } })
|
||||
|
||||
const result = await checkSlackJoins('xoxb-test-token')
|
||||
|
||||
expect(mockFindByIdAndUpdate).not.toHaveBeenCalled()
|
||||
expect(result).toEqual({ checked: 1, joined: 0 })
|
||||
})
|
||||
|
||||
it('8.3: skips already-joined members (not included in query)', async () => {
|
||||
mockFind.mockReturnValue({
|
||||
select: vi.fn().mockResolvedValue([])
|
||||
})
|
||||
|
||||
const result = await checkSlackJoins('xoxb-test-token')
|
||||
|
||||
// Verify the query only looks for 'sent' and 'accepted'
|
||||
expect(mockFind).toHaveBeenCalledWith({
|
||||
slackInviteStatus: { $in: ['sent', 'accepted'] }
|
||||
})
|
||||
expect(result).toEqual({ checked: 0, joined: 0 })
|
||||
expect(mockLookupByEmail).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('8.4: skips members with null slackInviteStatus (not included in query)', async () => {
|
||||
mockFind.mockReturnValue({
|
||||
select: vi.fn().mockResolvedValue([])
|
||||
})
|
||||
|
||||
await checkSlackJoins('xoxb-test-token')
|
||||
|
||||
// Query uses $in with only 'sent' and 'accepted' — null is excluded
|
||||
const queryArg = mockFind.mock.calls[0][0]
|
||||
expect(queryArg.slackInviteStatus.$in).toEqual(['sent', 'accepted'])
|
||||
expect(queryArg.slackInviteStatus.$in).not.toContain(null)
|
||||
})
|
||||
|
||||
it('8.6: partial failure does not abort batch — remaining members still processed', async () => {
|
||||
mockFind.mockReturnValue({
|
||||
select: vi.fn().mockResolvedValue([
|
||||
{ _id: 'm1', email: 'alice@example.com', slackInviteStatus: 'sent' },
|
||||
{ _id: 'm2', email: 'bob@example.com', slackInviteStatus: 'sent' },
|
||||
{ _id: 'm3', email: 'carol@example.com', slackInviteStatus: 'sent' }
|
||||
])
|
||||
})
|
||||
|
||||
// First call: unexpected API error
|
||||
mockLookupByEmail
|
||||
.mockRejectedValueOnce(new Error('Slack API timeout'))
|
||||
// Second call: not found
|
||||
.mockRejectedValueOnce({ data: { error: 'users_not_found' } })
|
||||
// Third call: found
|
||||
.mockResolvedValueOnce({ user: { id: 'U999' } })
|
||||
|
||||
mockFindByIdAndUpdate.mockResolvedValue({})
|
||||
|
||||
const result = await checkSlackJoins('xoxb-test-token')
|
||||
|
||||
// All three were checked
|
||||
expect(mockLookupByEmail).toHaveBeenCalledTimes(3)
|
||||
// Only the third member joined
|
||||
expect(mockFindByIdAndUpdate).toHaveBeenCalledTimes(1)
|
||||
expect(mockFindByIdAndUpdate).toHaveBeenCalledWith('m3', {
|
||||
slackInviteStatus: 'joined',
|
||||
slackUserId: 'U999'
|
||||
})
|
||||
expect(result).toEqual({ checked: 3, joined: 1 })
|
||||
})
|
||||
|
||||
it('8.7: handles accepted status members too', async () => {
|
||||
mockFind.mockReturnValue({
|
||||
select: vi.fn().mockResolvedValue([
|
||||
{ _id: 'm4', email: 'dave@example.com', slackInviteStatus: 'accepted' }
|
||||
])
|
||||
})
|
||||
mockLookupByEmail.mockResolvedValue({ user: { id: 'UABC' } })
|
||||
mockFindByIdAndUpdate.mockResolvedValue({})
|
||||
|
||||
const result = await checkSlackJoins('xoxb-test-token')
|
||||
|
||||
expect(mockLookupByEmail).toHaveBeenCalledWith({ email: 'dave@example.com' })
|
||||
expect(mockFindByIdAndUpdate).toHaveBeenCalledWith('m4', {
|
||||
slackInviteStatus: 'joined',
|
||||
slackUserId: 'UABC'
|
||||
})
|
||||
expect(result).toEqual({ checked: 1, joined: 1 })
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue