chore(board): remove old board tests, update seed + onboarding tests
This commit is contained in:
parent
7707068f36
commit
f3df1945bd
7 changed files with 55 additions and 638 deletions
|
|
@ -1,5 +1,9 @@
|
|||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
|
||||
const { mockBoardPostExists } = vi.hoisted(() => ({
|
||||
mockBoardPostExists: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('../../../server/utils/auth.js', () => ({
|
||||
requireAuth: vi.fn()
|
||||
}))
|
||||
|
|
@ -8,6 +12,10 @@ vi.mock('../../../server/utils/mongoose.js', () => ({
|
|||
connectDB: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('../../../server/models/boardPost.js', () => ({
|
||||
default: { exists: mockBoardPostExists }
|
||||
}))
|
||||
|
||||
import { requireAuth } from '../../../server/utils/auth.js'
|
||||
import handler from '../../../server/api/onboarding/status.get.js'
|
||||
import { createMockEvent } from '../helpers/createMockEvent.js'
|
||||
|
|
@ -15,6 +23,7 @@ import { createMockEvent } from '../helpers/createMockEvent.js'
|
|||
describe('GET /api/onboarding/status', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mockBoardPostExists.mockResolvedValue(null)
|
||||
})
|
||||
|
||||
// 1.1: Default state for new member — all false, completedAt null
|
||||
|
|
@ -22,7 +31,6 @@ describe('GET /api/onboarding/status', () => {
|
|||
requireAuth.mockResolvedValue({
|
||||
_id: 'member-1',
|
||||
craftTags: [],
|
||||
board: { topics: [] },
|
||||
onboarding: {
|
||||
completedAt: null,
|
||||
eventPageVisited: false,
|
||||
|
|
@ -45,14 +53,11 @@ describe('GET /api/onboarding/status', () => {
|
|||
})
|
||||
})
|
||||
|
||||
// 1.2: hasProfileTags true when both tag types present
|
||||
it('hasProfileTags is true when member has both craft tags and board topics', async () => {
|
||||
// 1.2: hasProfileTags true when craft tags present
|
||||
it('hasProfileTags is true when member has craft tags', async () => {
|
||||
requireAuth.mockResolvedValue({
|
||||
_id: 'member-1',
|
||||
craftTags: ['game-design'],
|
||||
board: {
|
||||
topics: [{ tagSlug: 'governance', state: 'interested' }],
|
||||
},
|
||||
onboarding: {
|
||||
completedAt: null,
|
||||
eventPageVisited: false,
|
||||
|
|
@ -67,12 +72,11 @@ describe('GET /api/onboarding/status', () => {
|
|||
expect(result.goals.hasProfileTags).toBe(true)
|
||||
})
|
||||
|
||||
// 1.3: hasProfileTags false when only craft tags
|
||||
it('hasProfileTags is false when member has craft tags but no board topics', async () => {
|
||||
// 1.3: hasProfileTags false when no craft tags
|
||||
it('hasProfileTags is false when member has no craft tags', async () => {
|
||||
requireAuth.mockResolvedValue({
|
||||
_id: 'member-1',
|
||||
craftTags: ['game-design'],
|
||||
board: { topics: [] },
|
||||
craftTags: [],
|
||||
onboarding: {
|
||||
completedAt: null,
|
||||
eventPageVisited: false,
|
||||
|
|
@ -87,14 +91,11 @@ describe('GET /api/onboarding/status', () => {
|
|||
expect(result.goals.hasProfileTags).toBe(false)
|
||||
})
|
||||
|
||||
// 1.5: hasEngagedBoard true when visited AND has tag with engagement state
|
||||
it('hasEngagedBoard is true when page visited and has engaged topic', async () => {
|
||||
// 1.5: hasEngagedBoard true when visited AND has a BoardPost
|
||||
it('hasEngagedBoard is true when page visited and member has posted', async () => {
|
||||
requireAuth.mockResolvedValue({
|
||||
_id: 'member-1',
|
||||
craftTags: [],
|
||||
board: {
|
||||
topics: [{ tagSlug: 'governance', state: 'help' }],
|
||||
},
|
||||
onboarding: {
|
||||
completedAt: null,
|
||||
eventPageVisited: false,
|
||||
|
|
@ -102,19 +103,20 @@ describe('GET /api/onboarding/status', () => {
|
|||
wikiClicked: false,
|
||||
},
|
||||
})
|
||||
mockBoardPostExists.mockResolvedValue({ _id: 'post-1' })
|
||||
|
||||
const event = createMockEvent({ method: 'GET', path: '/api/onboarding/status' })
|
||||
const result = await handler(event)
|
||||
|
||||
expect(result.goals.hasEngagedBoard).toBe(true)
|
||||
expect(mockBoardPostExists).toHaveBeenCalledWith({ author: 'member-1' })
|
||||
})
|
||||
|
||||
// 1.6: hasEngagedBoard false when visited but no engagement state
|
||||
it('hasEngagedBoard is false when page visited but no topics have engagement state', async () => {
|
||||
// 1.6: hasEngagedBoard false when visited but no posts
|
||||
it('hasEngagedBoard is false when page visited but member has no posts', async () => {
|
||||
requireAuth.mockResolvedValue({
|
||||
_id: 'member-1',
|
||||
craftTags: [],
|
||||
board: { topics: [] },
|
||||
onboarding: {
|
||||
completedAt: null,
|
||||
eventPageVisited: false,
|
||||
|
|
@ -122,6 +124,7 @@ describe('GET /api/onboarding/status', () => {
|
|||
wikiClicked: false,
|
||||
},
|
||||
})
|
||||
mockBoardPostExists.mockResolvedValue(null)
|
||||
|
||||
const event = createMockEvent({ method: 'GET', path: '/api/onboarding/status' })
|
||||
const result = await handler(event)
|
||||
|
|
@ -134,7 +137,6 @@ describe('GET /api/onboarding/status', () => {
|
|||
requireAuth.mockResolvedValue({
|
||||
_id: 'member-1',
|
||||
craftTags: [],
|
||||
board: { topics: [] },
|
||||
onboarding: {
|
||||
completedAt: null,
|
||||
eventPageVisited: true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue