code: validate,nextjs,frontends (2 files)

This commit is contained in:
2025-12-25 19:47:26 +00:00
parent 6ad4365489
commit 361db2421d
2 changed files with 25 additions and 1 deletions

View File

@@ -0,0 +1,24 @@
import { describe, expect, it } from 'vitest'
import { validateCredentialCreate } from '../../../src/core/validation/validate-credential-create'
describe('validateCredentialCreate', () => {
const base = {
username: 'valid_user',
passwordHash: 'hashed_value',
firstLogin: true,
}
it.each([
{ data: base, expected: [] },
])('returns $expected for valid case', ({ data, expected }) => {
expect(validateCredentialCreate(data)).toEqual(expected)
})
it.each([
{ data: { ...base, username: 'ab' }, message: 'username must be 3-50 characters (alphanumeric, underscore, hyphen)' },
{ data: { ...base, passwordHash: ' ' }, message: 'passwordHash must be a non-empty string' },
{ data: { ...base, firstLogin: 'yes' as unknown as boolean }, message: 'firstLogin must be a boolean' },
])('rejects invalid case', ({ data, message }) => {
expect(validateCredentialCreate(data)).toContain(message)
})
})

View File

@@ -9,5 +9,5 @@ export {
getScrambledPassword,
DEFAULT_USERS,
DEFAULT_CREDENTIALS,
} from './auth/index'
} from './index'