Skip to content

Commit

Permalink
Add integration and helper tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simoneNEMO committed Jun 20, 2024
1 parent 09d194e commit b10a8fb
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/integration/schema/string.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* @vinejs/vine
*
* (c) VineJS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import { test } from '@japa/runner'
import vine from '../../../index.js'

test.group('String', () => {
test('fail when value is not a string', async ({ assert }) => {
const schema = vine.object({
name: vine.string(),
})

const data = { name: 42 }
await assert.validationErrors(vine.validate({ schema, data }), [
{
field: 'name',
message: 'The name field must be a string',
rule: 'string',
},
])
})

test('fail when value is not a valid ULID', async ({ assert }) => {
const schema = vine.object({
id: vine.string().ulid(),
})

const data = { id: '01J0TMIXKWW62H0BKGQ984AS' }
await assert.validationErrors(vine.validate({ schema, data }), [
{
field: 'id',
message: 'The id field must be a valid ULID',
rule: 'ulid',
},
])
})

test('pass when value is a valid ULID', async ({ assert }) => {
const schema = vine.object({
id: vine.string().ulid(),
})

const data = { id: '01J0TMSK8WMJSTX1T2633GFA4G' }
await assert.validationOutput(vine.validate({ schema, data }), {
id: '01J0TMSK8WMJSTX1T2633GFA4G',
})
})
})
6 changes: 6 additions & 0 deletions tests/unit/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,10 @@ test.group('Vine Helpers', () => {
assert.isTrue(vine.helpers.isPostalCode('69200', 'FR'))
assert.isTrue(vine.helpers.isMobilePhone('0612345678', 'fr-FR'))
})

test('check if the value is a ULID', ({ assert }) => {
assert.isTrue(vine.helpers.isULID('01J0TSV6ZP6VTAHWZ7A7SYDBM2'))
assert.isTrue(vine.helpers.isULID('01j0tsv6zp6vtahwz7a7sydbm2'))
assert.isFalse(vine.helpers.isULID('01J0TSV6ZP6VTAHWZIL7A7SYDB'))
})
})

0 comments on commit b10a8fb

Please sign in to comment.