-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core-1327 Adds bigint type support #2
Co-authored-by: Mehdi Raza Jaffery <[email protected]>
- Loading branch information
1 parent
f918d34
commit 99b9e00
Showing
3 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { bigint, validateAndMap, validateAndUnmap } from '../../src'; | ||
describe('bigint', () => { | ||
describe('Mapping', () => { | ||
it('should accept bigint', () => { | ||
const input = BigInt(9532532599932); | ||
const schema = bigint(); | ||
const output = validateAndMap(input, schema); | ||
expect(output.errors).toBeFalsy(); | ||
expect((output as any).result).toBe(input); | ||
}); | ||
|
||
it('should accept negative bigint', () => { | ||
const input = BigInt(-9532532599932); | ||
const schema = bigint(); | ||
const output = validateAndMap(input, schema); | ||
expect(output.errors).toBeFalsy(); | ||
expect((output as any).result).toBe(input); | ||
}); | ||
|
||
it('should accept bigint string', () => { | ||
const input = '9532532599932'; | ||
const schema = bigint(); | ||
const output = validateAndMap(input as any, schema); | ||
expect(output.errors).toBeFalsy(); | ||
expect((output as any).result).toBe(BigInt(input)); | ||
}); | ||
|
||
it('should accept negative bigint string', () => { | ||
const input = '-9532532599932'; | ||
const schema = bigint(); | ||
const output = validateAndMap(input as any, schema); | ||
expect(output.errors).toBeFalsy(); | ||
expect((output as any).result).toBe(BigInt(input)); | ||
}); | ||
|
||
it('should fail on other types', () => { | ||
const input = true; | ||
const schema = bigint(); | ||
const output = validateAndMap(input as any, schema); | ||
expect((output as any).result).toBeUndefined(); | ||
expect(output.errors).toHaveLength(1); | ||
expect(output.errors).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"branch": Array [ | ||
true, | ||
], | ||
"message": "Expected value to be of type 'bigint' but found 'boolean'. | ||
Given value: true | ||
Type: 'boolean' | ||
Expected type: 'bigint'", | ||
"path": Array [], | ||
"type": "bigint", | ||
"value": true, | ||
}, | ||
] | ||
`); | ||
}); | ||
}); | ||
|
||
describe('Unmapping', () => { | ||
it('should accept bigint', () => { | ||
const input = BigInt(9532532599932); | ||
const schema = bigint(); | ||
const output = validateAndUnmap(input, schema); | ||
expect(output.errors).toBeFalsy(); | ||
expect((output as any).result).toBe(input); | ||
}); | ||
|
||
it('should accept negative bigint', () => { | ||
const input = BigInt(-9532532599932); | ||
const schema = bigint(); | ||
const output = validateAndUnmap(input, schema); | ||
expect(output.errors).toBeFalsy(); | ||
expect((output as any).result).toBe(input); | ||
}); | ||
|
||
it('should accept bigint string', () => { | ||
const input = '9532532599932'; | ||
const schema = bigint(); | ||
const output = validateAndUnmap(input as any, schema); | ||
expect(output.errors).toBeFalsy(); | ||
expect((output as any).result).toBe(BigInt(input)); | ||
}); | ||
|
||
it('should accept negative bigint string', () => { | ||
const input = '-9532532599932'; | ||
const schema = bigint(); | ||
const output = validateAndUnmap(input as any, schema); | ||
expect(output.errors).toBeFalsy(); | ||
expect((output as any).result).toBe(BigInt(input)); | ||
}); | ||
|
||
it('should fail on other types', () => { | ||
const input = true; | ||
const schema = bigint(); | ||
const output = validateAndUnmap(input as any, schema); | ||
expect((output as any).result).toBeUndefined(); | ||
expect(output.errors).toHaveLength(1); | ||
expect(output.errors).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"branch": Array [ | ||
true, | ||
], | ||
"message": "Expected value to be of type 'bigint' but found 'boolean'. | ||
Given value: true | ||
Type: 'boolean' | ||
Expected type: 'bigint'", | ||
"path": Array [], | ||
"type": "bigint", | ||
"value": true, | ||
}, | ||
] | ||
`); | ||
}); | ||
}); | ||
}); |