@@ -359,6 +359,79 @@ describe('CubeApi with Abort Signal', () => {
359359 } ) ;
360360} ) ;
361361
362+ describe ( 'CubeApi cubeSql' , ( ) => {
363+ afterEach ( ( ) => {
364+ jest . clearAllMocks ( ) ;
365+ jest . restoreAllMocks ( ) ;
366+ } ) ;
367+
368+ const cubeSqlResponseBody = [
369+ JSON . stringify ( {
370+ schema : [
371+ { name : 'status' , column_type : 'String' } ,
372+ { name : 'measure(orders_transactions.count)' , column_type : 'Int64' }
373+ ] ,
374+ lastRefreshTime : '2026-02-24T00:34:01.594Z'
375+ } ) ,
376+ JSON . stringify ( { data : [ [ 'Cancelled' , '27090' ] , [ 'Returned' , '18232' ] ] } ) ,
377+ JSON . stringify ( { data : [ [ 'Shipped' , '45102' ] ] } ) ,
378+ ] . join ( '\n' ) ;
379+
380+ const cubeSqlResponseBodyNoRefreshTime = [
381+ JSON . stringify ( {
382+ schema : [
383+ { name : 'status' , column_type : 'String' } ,
384+ ] ,
385+ } ) ,
386+ JSON . stringify ( { data : [ [ 'Active' ] ] } ) ,
387+ ] . join ( '\n' ) ;
388+
389+ test ( 'should parse lastRefreshTime from response' , async ( ) => {
390+ jest . spyOn ( HttpTransport . prototype , 'request' ) . mockImplementation ( ( ) => ( {
391+ subscribe : ( cb ) => Promise . resolve ( cb ( {
392+ status : 200 ,
393+ text : ( ) => Promise . resolve ( JSON . stringify ( { error : cubeSqlResponseBody } ) ) ,
394+ } as any ,
395+ async ( ) => undefined as any ) )
396+ } ) ) ;
397+
398+ const cubeApi = new CubeApi ( 'token' , {
399+ apiUrl : 'http://localhost:4000/cubejs-api/v1' ,
400+ } ) ;
401+
402+ const res = await cubeApi . cubeSql ( 'SELECT status, measure(count) FROM orders_transactions' ) ;
403+ expect ( res . lastRefreshTime ) . toBe ( '2026-02-24T00:34:01.594Z' ) ;
404+ expect ( res . schema ) . toEqual ( [
405+ { name : 'status' , column_type : 'String' } ,
406+ { name : 'measure(orders_transactions.count)' , column_type : 'Int64' }
407+ ] ) ;
408+ expect ( res . data ) . toEqual ( [
409+ [ 'Cancelled' , '27090' ] ,
410+ [ 'Returned' , '18232' ] ,
411+ [ 'Shipped' , '45102' ] ,
412+ ] ) ;
413+ } ) ;
414+
415+ test ( 'should omit lastRefreshTime when not present in response' , async ( ) => {
416+ jest . spyOn ( HttpTransport . prototype , 'request' ) . mockImplementation ( ( ) => ( {
417+ subscribe : ( cb ) => Promise . resolve ( cb ( {
418+ status : 200 ,
419+ text : ( ) => Promise . resolve ( JSON . stringify ( { error : cubeSqlResponseBodyNoRefreshTime } ) ) ,
420+ } as any ,
421+ async ( ) => undefined as any ) )
422+ } ) ) ;
423+
424+ const cubeApi = new CubeApi ( 'token' , {
425+ apiUrl : 'http://localhost:4000/cubejs-api/v1' ,
426+ } ) ;
427+
428+ const res = await cubeApi . cubeSql ( 'SELECT status FROM users' ) ;
429+ expect ( res . lastRefreshTime ) . toBeUndefined ( ) ;
430+ expect ( res . schema ) . toEqual ( [ { name : 'status' , column_type : 'String' } ] ) ;
431+ expect ( res . data ) . toEqual ( [ [ 'Active' ] ] ) ;
432+ } ) ;
433+ } ) ;
434+
362435describe ( 'CubeApi with baseRequestId' , ( ) => {
363436 afterEach ( ( ) => {
364437 jest . clearAllMocks ( ) ;
0 commit comments