@@ -1150,4 +1150,82 @@ describe('API Gateway', () => {
11501150 expect ( dataSourceStorage . $testOrchestratorConnectionsDone ) . toEqual ( false ) ;
11511151 } ) ;
11521152 } ) ;
1153+
1154+ describe ( '/v1/cubesql' , ( ) => {
1155+ test ( 'simple query works' , async ( ) => {
1156+ const { app, apiGateway } = await createApiGateway ( ) ;
1157+
1158+ // Mock the sqlServer.execSql method
1159+ const execSqlMock = jest . fn ( async ( query , stream , securityContext , cacheMode , timezone ) => {
1160+ // Simulate writing schema and data to the stream
1161+ stream . write ( `${ JSON . stringify ( {
1162+ schema : [ { name : 'id' , column_type : 'Int' } ]
1163+ } ) } \n`) ;
1164+ stream . write ( `${ JSON . stringify ( {
1165+ data : [ [ 1 ] , [ 2 ] , [ 3 ] ]
1166+ } ) } \n`) ;
1167+ stream . end ( ) ;
1168+ } ) ;
1169+
1170+ apiGateway . getSQLServer ( ) . execSql = execSqlMock ;
1171+
1172+ await request ( app )
1173+ . post ( '/cubejs-api/v1/cubesql' )
1174+ . set ( 'Content-type' , 'application/json' )
1175+ . set ( 'Authorization' , 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M' )
1176+ . send ( {
1177+ query : 'SELECT id FROM test LIMIT 3'
1178+ } )
1179+ . responseType ( 'text' )
1180+ . expect ( 200 ) ;
1181+
1182+ // Verify the mock was called with correct parameters
1183+ expect ( execSqlMock ) . toHaveBeenCalledWith (
1184+ 'SELECT id FROM test LIMIT 3' ,
1185+ expect . anything ( ) ,
1186+ { } ,
1187+ undefined ,
1188+ undefined
1189+ ) ;
1190+ } ) ;
1191+
1192+ test ( 'timezone can be passed' , async ( ) => {
1193+ const { app, apiGateway } = await createApiGateway ( ) ;
1194+
1195+ // Mock the sqlServer.execSql method
1196+ const execSqlMock = jest . fn ( async ( query , stream , securityContext , cacheMode , timezone ) => {
1197+ // Simulate writing schema and data to the stream
1198+ stream . write ( `${ JSON . stringify ( {
1199+ schema : [ { name : 'created_at' , column_type : 'Timestamp' } ]
1200+ } ) } \n`) ;
1201+ stream . write ( `${ JSON . stringify ( {
1202+ data : [ [ '2025-12-22T16:00:00.000' ] , [ '2025-12-24T16:00:00.000' ] ]
1203+ } ) } \n`) ;
1204+ stream . end ( ) ;
1205+ } ) ;
1206+
1207+ apiGateway . getSQLServer ( ) . execSql = execSqlMock ;
1208+
1209+ await request ( app )
1210+ . post ( '/cubejs-api/v1/cubesql' )
1211+ . set ( 'Content-type' , 'application/json' )
1212+ . set ( 'Authorization' , 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M' )
1213+ . send ( {
1214+ query : 'SELECT created_at FROM orders WHERE created_at > \'2025-12-22 13:00:00\'::timestamptz' ,
1215+ cache : 'stale-while-revalidate' ,
1216+ timezone : 'America/Los_Angeles'
1217+ } )
1218+ . responseType ( 'text' )
1219+ . expect ( 200 ) ;
1220+
1221+ // Verify the mock was called with correct parameters including timezone
1222+ expect ( execSqlMock ) . toHaveBeenCalledWith (
1223+ 'SELECT created_at FROM orders WHERE created_at > \'2025-12-22 13:00:00\'::timestamptz' ,
1224+ expect . anything ( ) ,
1225+ { } ,
1226+ 'stale-while-revalidate' ,
1227+ 'America/Los_Angeles'
1228+ ) ;
1229+ } ) ;
1230+ } ) ;
11531231} ) ;
0 commit comments