1+ import { BSON } from 'bsonfy' ;
12import { Struct , Timestamp , type JsonValue } from '@bufbuild/protobuf' ;
23import { createRouterTransport , type Transport } from '@connectrpc/connect' ;
34import { beforeEach , describe , expect , it , vi } from 'vitest' ;
@@ -86,6 +87,7 @@ describe('DataClient tests', () => {
8687 const lastId = 'lastId' ;
8788 const countOnly = true ;
8889 const includeInternalData = false ;
90+ const startDate = new Date ( 1 , 1 , 1 , 1 , 1 , 1 ) ;
8991
9092 const binaryId1 = new BinaryID ( {
9193 fileId : 'testFileId1' ,
@@ -99,16 +101,17 @@ describe('DataClient tests', () => {
99101 } ) ;
100102
101103 describe ( 'tabularDataBySQL tests' , ( ) => {
102- const data : Record < string , JsonValue > [ ] = [
103- { key1 : 1 , key2 : '2' , key3 : [ 1 , 2 , 3 ] , key4 : { key4sub1 : 1 } } ,
104+ type returnType = JsonValue | Date ;
105+ const data : Record < string , returnType > [ ] = [
106+ { key1 : startDate , key2 : '2' , key3 : [ 1 , 2 , 3 ] , key4 : { key4sub1 : 1 } } ,
104107 ] ;
105108
106109 beforeEach ( ( ) => {
107110 mockTransport = createRouterTransport ( ( { service } ) => {
108111 service ( DataService , {
109112 tabularDataBySQL : ( ) => {
110113 return new TabularDataBySQLResponse ( {
111- data : data . map ( ( x ) => Struct . fromJson ( x ) ) ,
114+ rawData : data . map ( ( x ) => BSON . serialize ( x ) ) ,
112115 } ) ;
113116 } ,
114117 } ) ;
@@ -120,21 +123,24 @@ describe('DataClient tests', () => {
120123 'some_org_id' ,
121124 'some_sql_query'
122125 ) ;
126+ const result = promise as typeof data ;
127+ expect ( result [ 0 ] ?. key1 ) . toBeInstanceOf ( Date ) ;
123128 expect ( promise ) . toEqual ( data ) ;
124129 } ) ;
125130 } ) ;
126131
127132 describe ( 'tabularDataByMQL tests' , ( ) => {
128- const data : Record < string , JsonValue > [ ] = [
129- { key1 : 1 , key2 : '2' , key3 : [ 1 , 2 , 3 ] , key4 : { key4sub1 : 1 } } ,
133+ type returnType = JsonValue | Date ;
134+ const data : Record < string , returnType > [ ] = [
135+ { key1 : startDate , key2 : '2' , key3 : [ 1 , 2 , 3 ] , key4 : { key4sub1 : 1 } } ,
130136 ] ;
131137
132138 beforeEach ( ( ) => {
133139 mockTransport = createRouterTransport ( ( { service } ) => {
134140 service ( DataService , {
135141 tabularDataByMQL : ( ) => {
136142 return new TabularDataByMQLResponse ( {
137- data : data . map ( ( x ) => Struct . fromJson ( x ) ) ,
143+ rawData : data . map ( ( x ) => BSON . serialize ( x ) ) ,
138144 } ) ;
139145 } ,
140146 } ) ;
@@ -145,6 +151,8 @@ describe('DataClient tests', () => {
145151 const promise = await subject ( ) . tabularDataByMQL ( 'some_org_id' , [
146152 new TextEncoder ( ) . encode ( 'some_mql_query' ) ,
147153 ] ) ;
154+ const result = promise as typeof data ;
155+ expect ( result [ 0 ] ?. key1 ) . toBeInstanceOf ( Date ) ;
148156 expect ( promise ) . toEqual ( data ) ;
149157 } ) ;
150158 } ) ;
0 commit comments