@@ -57,6 +57,7 @@ import {
5757 ServerDetails ,
5858 ServerType ,
5959} from "../../src/models/connectionsModels" ;
60+ import { InsightsApiConfig } from "../../src/models/config" ;
6061
6162describe ( "dataSourceCommand" , ( ) => {
6263 afterEach ( ( ) => {
@@ -147,6 +148,11 @@ describe("dataSourceCommand2", () => {
147148 sql : {
148149 query : "dummy SQL query" ,
149150 } ,
151+ uda : {
152+ name : "test query" ,
153+ description : "test description" ,
154+ params : [ ] ,
155+ } ,
150156 } ,
151157 } ;
152158 resultsPanel = new KdbResultsViewProvider ( uriTest ) ;
@@ -520,6 +526,99 @@ describe("dataSourceCommand2", () => {
520526 } ) ;
521527 } ) ;
522528
529+ describe ( "runUDADataSource" , ( ) => {
530+ let getDataInsightsStub ,
531+ handleWSResultsStub ,
532+ handleScratchpadTableRes ,
533+ parseErrorStub : sinon . SinonStub ;
534+
535+ beforeEach ( ( ) => {
536+ getDataInsightsStub = sinon . stub ( insightsConn , "getDatasourceQuery" ) ;
537+ handleWSResultsStub = sinon . stub ( queryUtils , "handleWSResults" ) ;
538+ parseErrorStub = sinon . stub ( dataSourceCommand , "parseError" ) ;
539+ handleScratchpadTableRes = sinon . stub (
540+ queryUtils ,
541+ "handleScratchpadTableRes" ,
542+ ) ;
543+ } ) ;
544+
545+ afterEach ( ( ) => {
546+ sinon . restore ( ) ;
547+ } ) ;
548+
549+ it ( "should call the API and handle the results" , async ( ) => {
550+ getDataInsightsStub . resolves ( { arrayBuffer : true } ) ;
551+ handleWSResultsStub . resolves ( [
552+ { a : "2" , b : "3" } ,
553+ { a : "4" , b : "6" } ,
554+ { a : "6" , b : "9" } ,
555+ ] ) ;
556+ handleScratchpadTableRes . resolves ( [
557+ { a : "2" , b : "3" } ,
558+ { a : "4" , b : "6" } ,
559+ { a : "6" , b : "9" } ,
560+ ] ) ;
561+
562+ const result = await dataSourceCommand . runUDADataSource (
563+ dummyDataSourceFiles ,
564+ insightsConn ,
565+ ) ;
566+
567+ sinon . assert . calledOnce ( getDataInsightsStub ) ;
568+ sinon . assert . calledOnce ( handleWSResultsStub ) ;
569+ assert . deepStrictEqual ( result , [
570+ { a : "2" , b : "3" } ,
571+ { a : "4" , b : "6" } ,
572+ { a : "6" , b : "9" } ,
573+ ] ) ;
574+ } ) ;
575+
576+ it ( "should call the API and handle the error results" , async ( ) => {
577+ getDataInsightsStub . resolves ( { error : "error test" } ) ;
578+ parseErrorStub . resolves ( { error : "error test" } ) ;
579+
580+ const result = await dataSourceCommand . runUDADataSource (
581+ dummyDataSourceFiles ,
582+ insightsConn ,
583+ ) ;
584+
585+ assert . deepStrictEqual ( result , { error : "error test" } ) ;
586+ } ) ;
587+
588+ it ( "should call the API and handle undefined response " , async ( ) => {
589+ getDataInsightsStub . resolves ( undefined ) ;
590+
591+ const result = await dataSourceCommand . runUDADataSource (
592+ dummyDataSourceFiles ,
593+ insightsConn ,
594+ ) ;
595+
596+ assert . deepStrictEqual ( result , { error : "UDA call failed" } ) ;
597+ } ) ;
598+
599+ it ( "should handle undefined UDA " , async ( ) => {
600+ dummyDataSourceFiles . dataSource . uda = undefined ;
601+
602+ const result = await dataSourceCommand . runUDADataSource (
603+ dummyDataSourceFiles ,
604+ insightsConn ,
605+ ) ;
606+
607+ assert . deepStrictEqual ( result , { error : "UDA not found" } ) ;
608+ } ) ;
609+
610+ it ( "should handle UDA without name" , async ( ) => {
611+ dummyDataSourceFiles . dataSource . uda . name = "" ;
612+
613+ const result = await dataSourceCommand . runUDADataSource (
614+ dummyDataSourceFiles ,
615+ insightsConn ,
616+ ) ;
617+
618+ assert . deepStrictEqual ( result , { error : "UDA name not found" } ) ;
619+ } ) ;
620+ } ) ;
621+
523622 describe ( "runDataSource" , ( ) => {
524623 const dummyMeta : MetaObject = {
525624 header : {
@@ -601,6 +700,11 @@ describe("dataSourceCommand2", () => {
601700 selectedTarget : "dummy-target" ,
602701 } ,
603702 sql : { query : "test query" } ,
703+ uda : {
704+ name : "test query" ,
705+ description : "test description" ,
706+ params : [ ] ,
707+ } ,
604708 } ,
605709 insightsNode : "dummyNode" ,
606710 } ;
@@ -610,6 +714,7 @@ describe("dataSourceCommand2", () => {
610714 const connMngService = new ConnectionManagementService ( ) ;
611715 const uriTest : vscode . Uri = vscode . Uri . parse ( "test" ) ;
612716 const ab = new ArrayBuffer ( 26 ) ;
717+
613718 ext . resultsViewProvider = new KdbResultsViewProvider ( uriTest ) ;
614719 let isVisibleStub ,
615720 getMetaStub ,
@@ -618,7 +723,8 @@ describe("dataSourceCommand2", () => {
618723 retrieveConnStub ,
619724 getDataInsightsStub ,
620725 writeQueryResultsToViewStub ,
621- writeQueryResultsToConsoleStub : sinon . SinonStub ;
726+ writeQueryResultsToConsoleStub ,
727+ qeStatusStub : sinon . SinonStub ;
622728 let windowMock : sinon . SinonMock ;
623729
624730 ext . outputChannel = vscode . window . createOutputChannel ( "kdb" ) ;
@@ -752,6 +858,30 @@ describe("dataSourceCommand2", () => {
752858 ext . connectedConnectionList . length = 0 ;
753859 } ) ;
754860
861+ it ( "should fail run QSQL if qe is off" , async ( ) => {
862+ const apiConfig : InsightsApiConfig = {
863+ encryptionDatabase : false ,
864+ encryptionInTransit : false ,
865+ queryEnvironmentsEnabled : false ,
866+ version : "1.0" ,
867+ } ;
868+ insightsConn . apiConfig = apiConfig ;
869+ ext . connectedConnectionList . push ( insightsConn ) ;
870+ retrieveConnStub . resolves ( insightsConn ) ;
871+ insightsConn . meta = dummyMeta ;
872+ getMetaStub . resolves ( dummyMeta ) ;
873+ ext . isResultsTabVisible = true ;
874+ await dataSourceCommand . runDataSource (
875+ dummyFileContent as DataSourceFiles ,
876+ insightsConn . connLabel ,
877+ "test-file.kdb.json" ,
878+ ) ;
879+ sinon . assert . neverCalledWith ( writeQueryResultsToConsoleStub ) ;
880+ sinon . assert . neverCalledWith ( writeQueryResultsToViewStub ) ;
881+ insightsConn . apiConfig . queryEnvironmentsEnabled = true ;
882+ ext . connectedConnectionList . length = 0 ;
883+ } ) ;
884+
755885 it ( "should return API results" , async ( ) => {
756886 ext . connectedConnectionList . push ( insightsConn ) ;
757887 retrieveConnStub . resolves ( insightsConn ) ;
@@ -790,6 +920,25 @@ describe("dataSourceCommand2", () => {
790920 ext . connectedConnectionList . length = 0 ;
791921 } ) ;
792922
923+ it ( "should return UDA results" , async ( ) => {
924+ ext . connectedConnectionList . push ( insightsConn ) ;
925+ retrieveConnStub . resolves ( insightsConn ) ;
926+ insightsConn . meta = dummyMeta ;
927+ dummyFileContent . dataSource . selectedType = DataSourceTypes . UDA ;
928+ getMetaStub . resolves ( dummyMeta ) ;
929+ getDataInsightsStub . resolves ( { arrayBuffer : ab , error : "" } ) ;
930+ ext . isResultsTabVisible = false ;
931+ await dataSourceCommand . runDataSource (
932+ dummyFileContent as DataSourceFiles ,
933+ insightsConn . connLabel ,
934+ "test-file.kdb.json" ,
935+ ) ;
936+ sinon . assert . neverCalledWith ( writeQueryResultsToViewStub ) ;
937+ sinon . assert . calledOnce ( writeQueryResultsToConsoleStub ) ;
938+
939+ ext . connectedConnectionList . length = 0 ;
940+ } ) ;
941+
793942 it ( "should return error message QSQL" , async ( ) => {
794943 dummyFileContent . dataSource . selectedType = DataSourceTypes . QSQL ;
795944 getMetaStub . resolves ( dummyMeta ) ;
@@ -910,13 +1059,26 @@ describe("dataSourceCommand2", () => {
9101059 selectedTarget : "dummy-target" ,
9111060 } ,
9121061 sql : { query : "test query" } ,
1062+ uda : {
1063+ name : "test query" ,
1064+ description : "test description" ,
1065+ params : [ ] ,
1066+ } ,
9131067 } ,
9141068 insightsNode : "dummyNode" ,
9151069 } ;
9161070 let windowMock : sinon . SinonMock ;
1071+ let connMngService : ConnectionManagementService ;
1072+ let qeStatusStub : sinon . SinonStub ;
9171073
9181074 beforeEach ( ( ) => {
1075+ ext . activeConnection = insightsConn ;
9191076 windowMock = sinon . mock ( vscode . window ) ;
1077+ connMngService = new ConnectionManagementService ( ) ;
1078+ qeStatusStub = sinon . stub (
1079+ connMngService ,
1080+ "retrieveInsightsConnQEEnabled" ,
1081+ ) ;
9201082 } ) ;
9211083 afterEach ( ( ) => {
9221084 ext . activeConnection = undefined ;
@@ -932,6 +1094,18 @@ describe("dataSourceCommand2", () => {
9321094 . once ( )
9331095 . withArgs ( "Please connect to an Insights server" ) ;
9341096 } ) ;
1097+
1098+ it ( "should show error msg if qe is off" , async ( ) => {
1099+ qeStatusStub . returns ( "disabled" ) ;
1100+ await dataSourceCommand . populateScratchpad (
1101+ dummyFileContent ,
1102+ insightsConn . connLabel ,
1103+ ) ;
1104+ windowMock
1105+ . expects ( "showErrorMessage" )
1106+ . once ( )
1107+ . withArgs ( "The query enviroment(s) are disabled for this connection" ) ;
1108+ } ) ;
9351109 } ) ;
9361110
9371111 describe ( "parseError" , ( ) => {
0 commit comments