Add initial project files

This commit is contained in:
Igor Martyniuk
2026-09-01 13:03:41 +03:00
parent 22e111bb44
commit 74cb5b6176
1841 changed files with 242819 additions and 30 deletions
@@ -0,0 +1,41 @@
import { test } from '@japa/runner'
import type { HttpContext } from '@adonisjs/core/http'
import { FileNotFoundException } from '#exceptions/file_manager_exceptions'
import { PageRouteConflictException } from '#exceptions/web_manager_exceptions'
function captureContext() {
const captured: { status?: number; body?: unknown } = {}
const response = {
status(code: number) {
captured.status = code
return response
},
send(body: unknown) {
captured.body = body
},
}
return { captured, ctx: { response } as unknown as HttpContext }
}
test.group('API exceptions', () => {
test('page manager exceptions self-render as message and code', async ({ assert }) => {
const { captured, ctx } = captureContext()
const error = new PageRouteConflictException('en', 'about')
await error.handle(error, ctx)
assert.equal(captured.status, 409)
assert.deepEqual(captured.body, {
message: 'A page already uses /en/about',
code: 'E_PAGE_ROUTE_CONFLICT',
})
})
test('file manager exceptions self-render as message and code', async ({ assert }) => {
const { captured, ctx } = captureContext()
const error = new FileNotFoundException()
await error.handle(error, ctx)
assert.equal(captured.status, 404)
assert.deepEqual(captured.body, { message: 'File not found', code: 'E_FILE_NOT_FOUND' })
})
})