Skip to content

Commit

Permalink
add string token schema test (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann authored Oct 9, 2023
1 parent d0831d0 commit 304ad97
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/schemas/numberTokenSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,27 @@ describe('Schema: numberToken', () => {
}).success,
).toStrictEqual(false)
})

it('fails on wrong value', () => {
// invalid string
expect(
numberToken.safeParse({
...validToken,
$value: 'string',
}).success,
).toStrictEqual(false)
// undefined
expect(
numberToken.safeParse({
...validToken,
$value: undefined,
}).success,
).toStrictEqual(false)
// no type
expect(
numberToken.safeParse({
$value: false,
}).success,
).toStrictEqual(false)
})
})
80 changes: 80 additions & 0 deletions src/schemas/stringTokenSchema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import {stringToken} from './stringToken'

describe('Schema: stringToken', () => {
const validToken = {
$value: 'a string',
$type: 'string',
$description: 'a string token',
}

it('parses valid string tokens', () => {
expect(stringToken.safeParse(validToken).success).toStrictEqual(true)
})

it('fails on invalid properties', () => {
// additional element
expect(
stringToken.safeParse({
...validToken,
additional: 1000,
}).success,
).toStrictEqual(false)
// missing value
expect(
stringToken.safeParse({
$type: 'string',
}).success,
).toStrictEqual(false)
// missing type
expect(
stringToken.safeParse({
$value: 'a string',
}).success,
).toStrictEqual(false)
})

it('fails on wrong type', () => {
expect(
stringToken.safeParse({
...validToken,
$type: 'motion',
}).success,
).toStrictEqual(false)
// undefined
expect(
stringToken.safeParse({
...validToken,
$type: undefined,
}).success,
).toStrictEqual(false)
// no type
expect(
stringToken.safeParse({
$value: 'a string',
}).success,
).toStrictEqual(false)
})

it('fails on wrong value', () => {
// invalid string
expect(
stringToken.safeParse({
...validToken,
$value: 100,
}).success,
).toStrictEqual(false)
// undefined
expect(
stringToken.safeParse({
...validToken,
$value: undefined,
}).success,
).toStrictEqual(false)
// no type
expect(
stringToken.safeParse({
$value: false,
}).success,
).toStrictEqual(false)
})
})

0 comments on commit 304ad97

Please sign in to comment.