test: define admin operations contracts

This commit is contained in:
Simo committed 2026-07-12 20:01:25 +02:00
1 parent dbb9cad01e
commit 21a61068fb
1 file changed
+43
+43
View File
@@ -0,0 +1,43 @@
import { existsSync, readFileSync } from 'node:fs'
import { describe, expect, it } from 'vitest'
const ROUTES: Array<[string, string]> = [
['moderation', 'PERMS.MODERATION_VIEW'],
['moderation/actions', 'PERMS.MODERATION_EDIT'],
['moderation/cfh', 'PERMS.MODERATION_VIEW'],
['moderation/cfh/[id]', 'PERMS.MODERATION_VIEW'],
['moderation/team', 'PERMS.MODERATION_VIEW'],
['logs/audit', 'PERMS.LOGS_VIEW'],
['logs/chat', 'PERMS.LOGS_VIEW'],
['logs/commands', 'PERMS.LOGS_VIEW'],
['logs/trades', 'PERMS.LOGS_VIEW'],
['analytics', 'PERMS.ANALYTICS_VIEW'],
['analytics/activity', 'PERMS.ANALYTICS_VIEW'],
['analytics/economy', 'PERMS.ANALYTICS_VIEW'],
['devops', 'PERMS.DEVOPS_VIEW'],
['devops/errors', 'PERMS.DEVOPS_VIEW'],
['online', 'PERMS.USERS_VIEW'],
]
describe('admin operations route contract', () => {
it.each(ROUTES)('provides and guards /admin/%s', (route, permission) => {
const path = `src/app/admin/${route}/page.tsx`
expect(existsSync(path), path).toBe(true)
expect(readFileSync(path, 'utf8'), path).toContain(permission)
})
it.each([
['analytics/export', 'PERMS.ANALYTICS_EXPORT'],
['devops/health', 'PERMS.DEVOPS_VIEW'],
])('provides and guards /api/admin/%s', (route, permission) => {
const path = `src/app/api/admin/${route}/route.ts`
expect(existsSync(path), path).toBe(true)
expect(readFileSync(path, 'utf8'), path).toContain(permission)
})
it('guards moderation mutations separately from page navigation', () => {
const source = readFileSync('src/actions/moderation.ts', 'utf8')
expect(source).toContain('PERMS.MODERATION_EDIT')
expect(source).toContain('adminAction')
})
})