mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 06:14:59 +00:00
code: dbal,valid,is (3 files)
This commit is contained in:
18
dbal/ts/src/core/validation/is-valid-date.test.ts
Normal file
18
dbal/ts/src/core/validation/is-valid-date.test.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { isValidDate } from './is-valid-date'
|
||||
|
||||
describe('isValidDate', () => {
|
||||
const validDate = new Date('2024-01-01T00:00:00Z')
|
||||
const invalidDate = new Date('invalid')
|
||||
|
||||
it.each([
|
||||
{ value: validDate, expected: true },
|
||||
{ value: '2024-01-01T00:00:00Z', expected: true },
|
||||
{ value: 1704067200000, expected: true },
|
||||
{ value: invalidDate, expected: false },
|
||||
{ value: 'not-a-date', expected: false },
|
||||
{ value: {}, expected: false },
|
||||
])('returns $expected for %s', ({ value, expected }) => {
|
||||
expect(isValidDate(value)).toBe(expected)
|
||||
})
|
||||
})
|
||||
14
dbal/ts/src/core/validation/is-valid-semver.test.ts
Normal file
14
dbal/ts/src/core/validation/is-valid-semver.test.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { isValidSemver } from './is-valid-semver'
|
||||
|
||||
describe('isValidSemver', () => {
|
||||
it.each([
|
||||
{ version: '1.0.0', expected: true },
|
||||
{ version: '0.10.2', expected: true },
|
||||
{ version: '1.0', expected: false },
|
||||
{ version: '1.0.0-beta', expected: false },
|
||||
{ version: 'v1.0.0', expected: false },
|
||||
])('returns $expected for $version', ({ version, expected }) => {
|
||||
expect(isValidSemver(version)).toBe(expected)
|
||||
})
|
||||
})
|
||||
@@ -1,12 +1,17 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { validateId } from './validate-id'
|
||||
|
||||
describe('validateId', () => {
|
||||
it.each([
|
||||
{ name: 'valid', id: 'abc123', expected: [] },
|
||||
{ name: 'empty', id: '', expected: ['ID cannot be empty'] },
|
||||
{ name: 'whitespace', id: ' ', expected: ['ID cannot be empty'] },
|
||||
])('returns errors for $name', ({ id, expected }) => {
|
||||
{ id: '550e8400-e29b-41d4-a716-446655440000', expected: [] },
|
||||
])('accepts valid id $id', ({ id, expected }) => {
|
||||
expect(validateId(id)).toEqual(expected)
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ id: '', message: 'ID cannot be empty' },
|
||||
{ id: 'not-a-uuid', message: 'ID must be a valid UUID' },
|
||||
])('rejects invalid id $id', ({ id, message }) => {
|
||||
expect(validateId(id)).toContain(message)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user