import { describe, it, expect } from 'vitest' import { readFileSync, existsSync } from 'node:fs' import { resolve } from 'node:path' const eventsDir = resolve(import.meta.dirname, '../../../server/api/events/[id]') describe('waitlist.post.js bypasses validators on event.save()', () => { const source = readFileSync(resolve(eventsDir, 'waitlist.post.js'), 'utf-8') it('calls eventData.save with validateBeforeSave: false', () => { expect(source).toContain('eventData.save({ validateBeforeSave: false })') }) it('does not contain a bare eventData.save() call', () => { expect(source).not.toMatch(/eventData\.save\(\s*\)/) }) }) describe('waitlist.delete.js bypasses validators on event.save()', () => { const source = readFileSync(resolve(eventsDir, 'waitlist.delete.js'), 'utf-8') it('calls eventData.save with validateBeforeSave: false', () => { expect(source).toContain('eventData.save({ validateBeforeSave: false })') }) it('does not contain a bare eventData.save() call', () => { expect(source).not.toMatch(/eventData\.save\(\s*\)/) }) }) // payment.post.js cases are handled by Fix #3 (file deletion). // If the file still exists, it should also pass the validators bypass. describe.skipIf(!existsSync(resolve(eventsDir, 'payment.post.js')))( 'payment.post.js bypasses validators on event.save()', () => { const source = existsSync(resolve(eventsDir, 'payment.post.js')) ? readFileSync(resolve(eventsDir, 'payment.post.js'), 'utf-8') : '' it('has exactly two eventData.save({ validateBeforeSave: false }) calls', () => { const matches = source.match(/eventData\.save\(\{\s*validateBeforeSave:\s*false\s*\}\)/g) || [] expect(matches.length).toBe(2) }) it('does not contain a bare eventData.save() call', () => { expect(source).not.toMatch(/eventData\.save\(\s*\)/) }) } )