Files
superlist/packages/shared/src/index.test.ts

35 lines
909 B
TypeScript

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 })
})
})