refactor: extract escapeRegex and validateTagSlugs server utils
Deduplicate tag validation and regex escaping into shared auto-imported utils. Add tag validation to wiki patch/batch-tag routes. Remove duplicate tags field from event schema.
This commit is contained in:
parent
f585fabf21
commit
a516f172fb
11 changed files with 33 additions and 31 deletions
|
|
@ -29,6 +29,7 @@ vi.mock('../../../server/utils/schemas.js', () => ({
|
|||
|
||||
import Tag from '../../../server/models/tag.js'
|
||||
import { validateBody } from '../../../server/utils/validateBody.js'
|
||||
import { validateTagSlugs } from '../../../server/utils/validateTagSlugs.js'
|
||||
import createHandler from '../../../server/api/admin/events.post.js'
|
||||
import updateHandler from '../../../server/api/admin/events/[id].put.js'
|
||||
import { createMockEvent } from '../helpers/createMockEvent.js'
|
||||
|
|
@ -51,8 +52,9 @@ const validEventBody = {
|
|||
describe('Event tag validation', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
// Override the global validateBody stub (from setup.js) to use our mock
|
||||
// Override global stubs (from setup.js) to use the real/mocked implementations
|
||||
globalThis.validateBody = validateBody
|
||||
globalThis.validateTagSlugs = validateTagSlugs
|
||||
})
|
||||
|
||||
describe('create route (events.post)', () => {
|
||||
|
|
|
|||
|
|
@ -41,3 +41,8 @@ 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())
|
||||
|
||||
// Real server/utils that are safe to use as-is in tests
|
||||
import { escapeRegex } from '../../server/utils/escapeRegex.js'
|
||||
vi.stubGlobal('escapeRegex', escapeRegex)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue