test: align board-channels and wiki-sync mocks with current source
board-channels: source renamed getSlackServiceNoVetting → getSlackAdminService. wiki-sync: syncWikiArticles now also calls fetchCollections; URLs starting with / are normalized to https://wiki.ghostguild.org.
This commit is contained in:
parent
e96d493024
commit
5fb2f18cab
2 changed files with 19 additions and 18 deletions
|
|
@ -1,6 +1,14 @@
|
|||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { setResponseStatus } from 'h3'
|
||||
|
||||
import { requireAuth, requireAdmin } from '../../../server/utils/auth.js'
|
||||
import { validateBody } from '../../../server/utils/validateBody.js'
|
||||
import getHandler from '../../../server/api/board/channels.get.js'
|
||||
import postHandler from '../../../server/api/admin/board-channels.post.js'
|
||||
import patchHandler from '../../../server/api/admin/board-channels/[id].patch.js'
|
||||
import deleteHandler from '../../../server/api/admin/board-channels/[id].delete.js'
|
||||
import { createMockEvent } from '../helpers/createMockEvent.js'
|
||||
|
||||
vi.stubGlobal('setResponseStatus', setResponseStatus)
|
||||
|
||||
const { mockFind, mockFindOne, mockCreate, mockFindByIdAndUpdate, mockFindByIdAndDelete } = vi.hoisted(() => ({
|
||||
|
|
@ -44,19 +52,11 @@ const { mockCreateSlackChannel } = vi.hoisted(() => ({
|
|||
}))
|
||||
|
||||
vi.mock('../../../server/utils/slack.ts', () => ({
|
||||
getSlackServiceNoVetting: () => ({
|
||||
getSlackAdminService: () => ({
|
||||
createChannel: mockCreateSlackChannel,
|
||||
}),
|
||||
}))
|
||||
|
||||
import { requireAuth, requireAdmin } from '../../../server/utils/auth.js'
|
||||
import { validateBody } from '../../../server/utils/validateBody.js'
|
||||
import getHandler from '../../../server/api/board/channels.get.js'
|
||||
import postHandler from '../../../server/api/admin/board-channels.post.js'
|
||||
import patchHandler from '../../../server/api/admin/board-channels/[id].patch.js'
|
||||
import deleteHandler from '../../../server/api/admin/board-channels/[id].delete.js'
|
||||
import { createMockEvent } from '../helpers/createMockEvent.js'
|
||||
|
||||
describe('GET /api/board/channels', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,13 @@
|
|||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
|
||||
import WikiArticle from '../../../server/models/wikiArticle.js'
|
||||
import { fetchAllDocuments, extractSummary } from '../../../server/utils/outline.js'
|
||||
import syncHandler from '../../../server/api/admin/wiki/sync.post.js'
|
||||
import { createMockEvent } from '../helpers/createMockEvent.js'
|
||||
|
||||
// Also test extractSummary directly (unmocked)
|
||||
import { extractSummary as realExtractSummary } from '../../../server/utils/outline.js'
|
||||
|
||||
// Mock dependencies before imports
|
||||
vi.mock('../../../server/models/wikiArticle.js', () => ({
|
||||
default: {
|
||||
|
|
@ -10,17 +18,10 @@ vi.mock('../../../server/models/wikiArticle.js', () => ({
|
|||
vi.mock('../../../server/utils/mongoose.js', () => ({ connectDB: vi.fn() }))
|
||||
vi.mock('../../../server/utils/outline.js', () => ({
|
||||
fetchAllDocuments: vi.fn(),
|
||||
fetchCollections: vi.fn(() => new Map()),
|
||||
extractSummary: vi.fn((text) => text || '')
|
||||
}))
|
||||
|
||||
import WikiArticle from '../../../server/models/wikiArticle.js'
|
||||
import { fetchAllDocuments, extractSummary } from '../../../server/utils/outline.js'
|
||||
import syncHandler from '../../../server/api/admin/wiki/sync.post.js'
|
||||
import { createMockEvent } from '../helpers/createMockEvent.js'
|
||||
|
||||
// Also test extractSummary directly (unmocked)
|
||||
import { extractSummary as realExtractSummary } from '../../../server/utils/outline.js'
|
||||
|
||||
function makeOutlineDoc(overrides = {}) {
|
||||
return {
|
||||
id: 'doc-1',
|
||||
|
|
@ -120,7 +121,7 @@ describe('wiki sync endpoint', () => {
|
|||
expect.objectContaining({
|
||||
$set: expect.objectContaining({
|
||||
title: 'Updated Title',
|
||||
url: '/doc/new-url'
|
||||
url: 'https://wiki.ghostguild.org/doc/new-url'
|
||||
})
|
||||
}),
|
||||
{ upsert: true, new: true, rawResult: true }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue