@@ -2,10 +2,28 @@ import Decimal from 'decimal.js';
22import { describe , expect , it } from 'vitest' ;
33import { createTestClient } from '../utils' ;
44
5- describe ( 'zmodel type coverage tests' , ( ) => {
6- it ( 'supports all types' , async ( ) => {
7- const db = await createTestClient (
8- `
5+ const PG_DB_NAME = 'client-api-type-coverage-tests' ;
6+
7+ describe . each ( [ 'sqlite' , 'postgresql' ] as const ) ( 'zmodel type coverage tests' , ( provider ) => {
8+ it ( 'supports all types - plain' , async ( ) => {
9+ const date = new Date ( ) ;
10+ const data = {
11+ id : '1' ,
12+ String : 'string' ,
13+ Int : 100 ,
14+ BigInt : BigInt ( 9007199254740991 ) ,
15+ DateTime : date ,
16+ Float : 1.23 ,
17+ Decimal : new Decimal ( 1.2345 ) ,
18+ Boolean : true ,
19+ Bytes : new Uint8Array ( [ 1 , 2 , 3 , 4 ] ) ,
20+ Json : { foo : 'bar' } ,
21+ } ;
22+
23+ let db : any ;
24+ try {
25+ db = await createTestClient (
26+ `
927 model Foo {
1028 id String @id @default(cuid())
1129
@@ -17,28 +35,67 @@ describe('zmodel type coverage tests', () => {
1735 Decimal Decimal
1836 Boolean Boolean
1937 Bytes Bytes
38+ Json Json
2039
2140 @@allow('all', true)
2241 }
2342 ` ,
24- ) ;
43+ { provider, dbName : PG_DB_NAME } ,
44+ ) ;
45+
46+ await db . foo . create ( { data } ) ;
47+ await expect ( db . foo . findUnique ( { where : { id : '1' } } ) ) . resolves . toMatchObject ( data ) ;
48+ } finally {
49+ await db ?. $disconnect ( ) ;
50+ }
51+ } ) ;
52+
53+ it ( 'supports all types - array' , async ( ) => {
54+ if ( provider === 'sqlite' ) {
55+ return ;
56+ }
2557
2658 const date = new Date ( ) ;
2759 const data = {
2860 id : '1' ,
29- String : 'string' ,
30- Int : 100 ,
31- BigInt : BigInt ( 9007199254740991 ) ,
32- DateTime : date ,
33- Float : 1.23 ,
34- Decimal : new Decimal ( 1.2345 ) ,
35- Boolean : true ,
36- Bytes : new Uint8Array ( [ 1 , 2 , 3 , 4 ] ) ,
61+ String : [ 'string' ] ,
62+ Int : [ 100 ] ,
63+ BigInt : [ BigInt ( 9007199254740991 ) ] ,
64+ DateTime : [ date ] ,
65+ Float : [ 1.23 ] ,
66+ Decimal : [ new Decimal ( 1.2345 ) ] ,
67+ Boolean : [ true ] ,
68+ Bytes : [ new Uint8Array ( [ 1 , 2 , 3 , 4 ] ) ] ,
69+ Json : [ { foo : 'bar' } ] ,
3770 } ;
3871
39- await db . foo . create ( { data } ) ;
72+ let db : any ;
73+ try {
74+ db = await createTestClient (
75+ `
76+ model Foo {
77+ id String @id @default(cuid())
78+
79+ String String[]
80+ Int Int[]
81+ BigInt BigInt[]
82+ DateTime DateTime[]
83+ Float Float[]
84+ Decimal Decimal[]
85+ Boolean Boolean[]
86+ Bytes Bytes[]
87+ Json Json[]
88+
89+ @@allow('all', true)
90+ }
91+ ` ,
92+ { provider, dbName : PG_DB_NAME } ,
93+ ) ;
4094
41- const r = await db . foo . findUnique ( { where : { id : '1' } } ) ;
42- expect ( r . Bytes ) . toEqual ( data . Bytes ) ;
95+ await db . foo . create ( { data } ) ;
96+ await expect ( db . foo . findUnique ( { where : { id : '1' } } ) ) . resolves . toMatchObject ( data ) ;
97+ } finally {
98+ await db ?. $disconnect ( ) ;
99+ }
43100 } ) ;
44101} ) ;
0 commit comments