chore: scaffold turbo monorepo with hono api and react admin web
This commit is contained in:
34
packages/shared/src/index.test.ts
Normal file
34
packages/shared/src/index.test.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { Failure, Ok, problem, problemTypes } from '../src/index'
|
||||
|
||||
describe('Result', () => {
|
||||
it('wraps success values', () => {
|
||||
expect(Ok({ id: '1' })).toEqual({ ok: true, value: { id: '1' } })
|
||||
})
|
||||
|
||||
it('wraps failures', () => {
|
||||
expect(Failure('boom')).toEqual({ ok: false, error: 'boom' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('problem', () => {
|
||||
it('defaults type to about:blank and strips undefined members', () => {
|
||||
expect(problem({ title: 'Not Found', status: 404 })).toEqual({
|
||||
type: 'about:blank',
|
||||
title: 'Not Found',
|
||||
status: 404,
|
||||
})
|
||||
})
|
||||
|
||||
it('accepts a custom type and detail', () => {
|
||||
expect(
|
||||
problem({
|
||||
type: problemTypes.validation,
|
||||
title: 'Validation failed',
|
||||
status: 422,
|
||||
detail: 'name is required',
|
||||
}),
|
||||
).toMatchObject({ status: 422, type: problemTypes.validation })
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user