From bc2ffee5b6cafc9e7820e94e74d1ee25b0490149 Mon Sep 17 00:00:00 2001 From: Niall Farrell Date: Tue, 16 Dec 2025 17:29:25 +0000 Subject: [PATCH 1/2] Use Structured Text for datasources --- src/classes/insightsConnection.ts | 13 +++---------- src/commands/dataSourceCommand.ts | 23 +++++++++++++++++++++-- src/models/data.ts | 3 +++ src/utils/resultsRenderer.ts | 5 ++++- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/classes/insightsConnection.ts b/src/classes/insightsConnection.ts index 30a8d14f0..354d9d8a6 100644 --- a/src/classes/insightsConnection.ts +++ b/src/classes/insightsConnection.ts @@ -16,7 +16,6 @@ import { jwtDecode } from "jwt-decode"; import * as url from "url"; import { ext } from "../extensionVariables"; -import { isCompressed, uncompress } from "../ipc/c"; import { InsightsApiConfig, InsightsConfig, @@ -49,7 +48,7 @@ import { retrieveUDAtoCreateReqBody } from "../utils/uda"; const logger = "insightsConnection"; const customHeadersOctet = { - Accept: "application/octet-stream", + Accept: "application/struct-text", "Content-Type": "application/json", }; const customHeadersJson = { @@ -483,7 +482,6 @@ export class InsightsConnection { if (!options) { return undefined; } - options.responseType = "arraybuffer"; notify("REST", MessageKind.DEBUG, { logger, @@ -497,14 +495,9 @@ export class InsightsConnection { MessageKind.DEBUG, { logger }, ); - if (isCompressed(response.data)) { - response.data = uncompress(response.data); - } return { error: "", - arrayBuffer: response.data.buffer - ? response.data.buffer - : response.data, + results: response.data.payload, }; }) .catch((error: any) => { @@ -514,7 +507,7 @@ export class InsightsConnection { { logger, params: error }, ); return { - error: { buffer: error.response.data }, + error: error.response.data.header.ai, arrayBuffer: undefined, }; }); diff --git a/src/commands/dataSourceCommand.ts b/src/commands/dataSourceCommand.ts index d5d36a96f..60b1998d5 100644 --- a/src/commands/dataSourceCommand.ts +++ b/src/commands/dataSourceCommand.ts @@ -43,11 +43,13 @@ import { import { MessageKind, notify } from "../utils/notifications"; import { addQueryHistory, + convertRows, getQSQLWrapper, handleScratchpadTableRes, handleWSError, handleWSResults, } from "../utils/queryUtils"; +import { updatedExtractRowData } from "../utils/resultsRenderer"; import { retrieveUDAtoCreateReqBody } from "../utils/uda"; import { validateScratchpadOutputVariableName } from "../validators/interfaceValidator"; @@ -200,7 +202,12 @@ export async function runDataSource( } if (isNotebook || ext.isResultsTabVisible) { if (success) { - const resultCount = typeof res === "string" ? "0" : res.rows.length; + const resultCount = + typeof res === "string" + ? "0" + : res.rows + ? res.rows.length + : res.columns?.[0]?.values?.length || 0; notify(`Results: ${resultCount} rows`, MessageKind.DEBUG, { logger, }); @@ -231,8 +238,12 @@ export async function runDataSource( res = res.errorMsg ? res.errorMsg : res.error; } + const rowData = res.columns + ? convertRows(updatedExtractRowData(res)) + : res; + await writeQueryResultsToConsole( - res, + rowData, query, connLabel, executorName, @@ -312,6 +323,8 @@ export async function runApiDataSource( if (apiCall?.error) { return parseError(apiCall.error); + } else if (apiCall?.results) { + return apiCall.results; } else if (apiCall?.arrayBuffer) { const results = handleWSResults(apiCall.arrayBuffer); return handleScratchpadTableRes(results); @@ -423,6 +436,8 @@ export async function runQsqlDataSource( if (qsqlCall?.error) { return parseError(qsqlCall.error); + } else if (qsqlCall?.results) { + return qsqlCall.results; } else if (qsqlCall?.arrayBuffer) { const results = handleWSResults(qsqlCall.arrayBuffer, isTableView); return handleScratchpadTableRes(results); @@ -446,6 +461,8 @@ export async function runSqlDataSource( if (sqlCall?.error) { return parseError(sqlCall.error); + } else if (sqlCall?.results) { + return sqlCall.results; } else if (sqlCall?.arrayBuffer) { const results = handleWSResults(sqlCall.arrayBuffer, isTableView); return handleScratchpadTableRes(results); @@ -484,6 +501,8 @@ export async function executeUDARequest( if (udaCall?.error) { return parseError(udaCall.error); + } else if (udaCall?.results) { + return udaCall.results; } else if (udaCall?.arrayBuffer) { const results = handleWSResults(udaCall.arrayBuffer); return handleScratchpadTableRes(results); diff --git a/src/models/data.ts b/src/models/data.ts index 4f06b553c..3791de42c 100644 --- a/src/models/data.ts +++ b/src/models/data.ts @@ -11,6 +11,8 @@ * specific language governing permissions and limitations under the License. */ +import { StructuredTextResults } from "./queryResult"; + export type GetDataError = string | { buffer: ArrayBuffer }; export type GetDataObjectPayload = { @@ -22,6 +24,7 @@ export type GetDataObjectPayload = { columns: string[]; rows: any; }; + results?: StructuredTextResults; arrayBuffer?: ArrayBuffer; }; diff --git a/src/utils/resultsRenderer.ts b/src/utils/resultsRenderer.ts index 597d58f01..4269c09d9 100644 --- a/src/utils/resultsRenderer.ts +++ b/src/utils/resultsRenderer.ts @@ -28,7 +28,10 @@ export function convertToGrid( if ( (!isInsights && !isPython) || /* TODO: Workaround for Python structuredText bug */ - (!isPython && connVersion && isBaseVersionGreaterOrEqual(connVersion, 1.12)) + (!isPython && + connVersion && + isBaseVersionGreaterOrEqual(connVersion, 1.12)) || + results.columns ) { rowData = updatedExtractRowData(results); columnDefs = updatedExtractColumnDefs(results); From 2027f4f32d5c61d2710aa56604b7465a1998225d Mon Sep 17 00:00:00 2001 From: Niall Farrell Date: Wed, 17 Dec 2025 12:21:39 +0000 Subject: [PATCH 2/2] Update tests --- eslint.config.mjs | 2 +- test/fixtures/api/getData.ts | 31 + .../api/getMeta.ts} | 66 +- test/fixtures/config/datasource.ts | 45 ++ test/suite/commands/dataSourceCommand.test.ts | 764 +++++++----------- test/suite/commands/serverCommand.test.ts | 10 +- .../connectionManagementService.test.ts | 6 +- .../services/kdbTree/kdbTreeProvider.test.ts | 4 +- .../datasourceEditorProvider.test.ts | 121 +-- .../providers/queryHistoryProvider.test.ts | 4 +- test/suite/webPanels/datasourcePanel.test.ts | 4 +- 11 files changed, 452 insertions(+), 605 deletions(-) create mode 100644 test/fixtures/api/getData.ts rename test/{suite/services/services.utils.test.ts => fixtures/api/getMeta.ts} (51%) create mode 100644 test/fixtures/config/datasource.ts diff --git a/eslint.config.mjs b/eslint.config.mjs index ed05b4bdd..881ebce24 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -9,7 +9,7 @@ const currentYear = new Date().getFullYear(); export default [ { - ignores: ["**/*.d.ts", "**/*.js", "**/*.mjs", "src/ipc/**"], + ignores: ["**/*.d.ts", "**/*.js", "**/*.mjs", "src/ipc/**", "test/fixtures/**"], }, js.configs.recommended, ...tseslint.configs.recommended, diff --git a/test/fixtures/api/getData.ts b/test/fixtures/api/getData.ts new file mode 100644 index 000000000..be48db5a9 --- /dev/null +++ b/test/fixtures/api/getData.ts @@ -0,0 +1,31 @@ +import { GetDataObjectPayload } from "../../../src/models/data"; + +export const getDataResponse: GetDataObjectPayload = { + results: { + count: 2, + columns: [ + { + name: "time", + type: "timestamps", + values: [ + "2025.01.01D00:00:00.000000000", + "2025.01.01D00:00:00.000000000", + ], + order: [0, 1], + }, + { name: "val", type: "ints", values: ["2", "3"], order: [0, 1] }, + ], + }, + error: "", +}; + +export const getDataIntResponse: GetDataObjectPayload = { + results: { + count: 2, + columns: [ + { name: "a", type: "ints", values: ["1", "3", "5"], order: [0, 1, 2] }, + { name: "b", type: "ints", values: ["2", "4", "6"], order: [0, 1, 2] }, + ], + }, + error: "", +}; diff --git a/test/suite/services/services.utils.test.ts b/test/fixtures/api/getMeta.ts similarity index 51% rename from test/suite/services/services.utils.test.ts rename to test/fixtures/api/getMeta.ts index c0437142e..609f026ee 100644 --- a/test/suite/services/services.utils.test.ts +++ b/test/fixtures/api/getMeta.ts @@ -1,19 +1,6 @@ -/* - * Copyright (c) 1998-2025 KX Systems Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - import { MetaObject } from "../../../src/models/meta"; -export const dummyMeta: MetaObject = { +export const getMetaResponse: MetaObject = { header: { ac: "0", agg: ":127.0.0.1:5070", @@ -69,3 +56,54 @@ export const dummyMeta: MetaObject = { schema: [], }, }; + +export const getMetaNoAssemblyResponse: MetaObject = { + header: { + ac: "0", + agg: ":127.0.0.1:5070", + ai: "", + api: ".kxi.getMeta", + client: ":127.0.0.1:5050", + corr: "CorrHash", + http: "json", + logCorr: "logCorrHash", + protocol: "gw", + rc: "0", + rcvTS: "2099-05-22T11:06:33.650000000", + retryCount: "0", + to: "2099-05-22T11:07:33.650000000", + userID: "dummyID", + userName: "testUser", + }, + payload: { + rc: [ + { + api: 3, + agg: 1, + assembly: 1, + schema: 1, + rc: "dummy-rc", + labels: [{ kxname: "dummy-assembly" }], + started: "2023-10-04T17:20:57.659088747", + }, + ], + dap: [], + api: [], + agg: [ + { + aggFn: ".sgagg.aggFnDflt", + custom: false, + full: true, + metadata: { + description: "dummy desc.", + params: [{ description: "dummy desc." }], + return: { description: "dummy desc." }, + misc: {}, + }, + procs: [], + }, + ], + assembly: [], + schema: [], + }, +}; diff --git a/test/fixtures/config/datasource.ts b/test/fixtures/config/datasource.ts new file mode 100644 index 000000000..c846bd143 --- /dev/null +++ b/test/fixtures/config/datasource.ts @@ -0,0 +1,45 @@ +import { + DataSourceFiles, + DataSourceTypes, +} from "../../../src/models/dataSource"; + +type DataSource = DataSourceFiles["dataSource"]; + +export function createMockDatasource( + dataSourceOverrides?: Partial, +): DataSourceFiles { + return { + name: "mockDatasource", + insightsNode: "mockNode", + dataSource: { + selectedType: DataSourceTypes.API, + api: { + selectedApi: "getData", + table: "mock_table", + startTS: "2023-09-10T09:30", + endTS: "2023-09-19T12:30", + fill: "", + filter: [], + groupBy: [], + labels: [], + slice: [], + sortCols: [], + temporality: "", + agg: [], + }, + qsql: { + selectedTarget: "mock_table rdb", + query: "mock QSQL query", + }, + sql: { + query: "mock SQL query", + }, + uda: { + name: "test query", + description: "test description", + params: [], + }, + ...dataSourceOverrides, + }, + }; +} diff --git a/test/suite/commands/dataSourceCommand.test.ts b/test/suite/commands/dataSourceCommand.test.ts index d91f74229..b0248cafc 100644 --- a/test/suite/commands/dataSourceCommand.test.ts +++ b/test/suite/commands/dataSourceCommand.test.ts @@ -25,17 +25,20 @@ import { DataSourceFiles, DataSourceTypes, } from "../../../src/models/dataSource"; -import { MetaObject } from "../../../src/models/meta"; import { ConnectionManagementService } from "../../../src/services/connectionManagerService"; import { InsightsNode } from "../../../src/services/kdbTreeProvider"; import { KdbResultsViewProvider } from "../../../src/services/resultsPanelProvider"; import * as dataSourceUtils from "../../../src/utils/dataSource"; import * as loggers from "../../../src/utils/loggers"; import * as queryUtils from "../../../src/utils/queryUtils"; +import { + getDataIntResponse, + getDataResponse, +} from "../../fixtures/api/getData"; +import { getMetaResponse } from "../../fixtures/api/getMeta"; +import { createMockDatasource } from "../../fixtures/config/datasource"; describe("dataSourceCommand", () => { - let dummyDataSourceFiles: DataSourceFiles; - let _resultsPanel: KdbResultsViewProvider; ext.outputChannel = vscode.window.createOutputChannel("kdb", { log: true }); const localConn = new LocalConnection("localhost:5001", "test", []); const insightsNode = new InsightsNode( @@ -49,114 +52,68 @@ describe("dataSourceCommand", () => { vscode.TreeItemCollapsibleState.None, ); const insightsConn = new InsightsConnection(insightsNode.label, insightsNode); - const uriTest: vscode.Uri = vscode.Uri.parse("test"); - const _view: vscode.WebviewView = { - visible: true, - show: (): void => {}, - viewType: "kdb-results", - webview: { - options: {}, - html: "", - cspSource: "", - asWebviewUri: (uri: vscode.Uri) => uri, - onDidReceiveMessage: new vscode.EventEmitter().event, - postMessage: (): Thenable => { - return Promise.resolve(true); - }, - }, - onDidDispose: new vscode.EventEmitter().event, - onDidChangeVisibility: new vscode.EventEmitter().event, - }; - - beforeEach(() => { - dummyDataSourceFiles = { - name: "dummy ds", - insightsNode: "dummy insights", - dataSource: { - selectedType: DataSourceTypes.API, - api: { - selectedApi: "getData", - table: "dummy_table", - startTS: "2023-09-10T09:30", - endTS: "2023-09-19T12:30", - fill: "", - filter: [], - groupBy: [], - labels: [], - slice: [], - sortCols: [], - temporality: "", - agg: [], - }, - qsql: { - selectedTarget: "dummy_table rdb", - query: "dummy QSQL query", - }, - sql: { - query: "dummy SQL query", - }, - uda: { - name: "test query", - description: "test description", - params: [], - }, - }, - }; - _resultsPanel = new KdbResultsViewProvider(uriTest); - }); describe("getSelectedType", () => { it("should return selectedType if it is API", () => { - const result = dataSourceCommand.getSelectedType(dummyDataSourceFiles); + const result = dataSourceCommand.getSelectedType(createMockDatasource()); sinon.assert.match(result, "API"); }); it("should return selectedType if it is QSQL", () => { - dummyDataSourceFiles.dataSource.selectedType = DataSourceTypes.QSQL; - const result2 = dataSourceCommand.getSelectedType(dummyDataSourceFiles); + const result2 = dataSourceCommand.getSelectedType( + createMockDatasource({ selectedType: DataSourceTypes.QSQL }), + ); sinon.assert.match(result2, "QSQL"); }); it("should return selectedType if it is SQL", () => { - dummyDataSourceFiles.dataSource.selectedType = DataSourceTypes.SQL; - const result3 = dataSourceCommand.getSelectedType(dummyDataSourceFiles); + const result3 = dataSourceCommand.getSelectedType( + createMockDatasource({ selectedType: DataSourceTypes.SQL }), + ); sinon.assert.match(result3, "SQL"); }); }); describe("getQuery", () => { it("should return the correct query for API data sources", () => { - const query = dataSourceCommand.getQuery(dummyDataSourceFiles, "API"); - assert.strictEqual(query, "GetData - table: dummy_table"); + const ds = createMockDatasource(); + const query = dataSourceCommand.getQuery(ds, "API"); + assert.strictEqual(query, `GetData - table: ${ds.dataSource.api.table}`); }); it("should return the correct query for QSQL data sources", () => { - const query = dataSourceCommand.getQuery(dummyDataSourceFiles, "QSQL"); - assert.strictEqual(query, "dummy QSQL query"); + const ds = createMockDatasource(); + const query = dataSourceCommand.getQuery(ds, "QSQL"); + assert.strictEqual(query, ds.dataSource.qsql.query); }); it("should return the correct query for SQL data sources", () => { - const query = dataSourceCommand.getQuery(dummyDataSourceFiles, "SQL"); - assert.strictEqual(query, "dummy SQL query"); + const ds = createMockDatasource(); + const query = dataSourceCommand.getQuery(ds, "SQL"); + assert.strictEqual(query, ds.dataSource.sql.query); }); }); describe("getApiBody", () => { it("should return the correct API body for an old data source with all fields", () => { - const api = dummyDataSourceFiles.dataSource.api; - - api.startTS = "2022-01-01T00:00:00Z"; - api.endTS = "2022-01-02T00:00:00Z"; - api.fill = "none"; - api.temporality = "1h"; - api.filter = ["col1=val1;col2=val2", "col3=val3"]; - api.groupBy = ["col1", "col2"]; - api.agg = ["sum(col3)", "avg(col4)"]; - api.sortCols = ["col1 ASC", "col2 DESC"]; - api.slice = ["10", "20"]; - api.labels = ["label1", "label2"]; - api.table = "myTable"; - const apiBody = dataSourceCommand.getApiBody(dummyDataSourceFiles); + const apiBody = dataSourceCommand.getApiBody( + createMockDatasource({ + api: { + selectedApi: "getData", + startTS: "2022-01-01T00:00:00Z", + endTS: "2022-01-02T00:00:00Z", + fill: "none", + temporality: "1h", + filter: ["col1=val1,col2=val2", "col3=val3"], + groupBy: ["col1", "col2"], + agg: ["sum(col3)", "avg(col4)"], + sortCols: ["col1 ASC", "col2 DESC"], + slice: ["10", "20"], + labels: ["label1", "label2"], + table: "myTable", + }, + }), + ); assert.deepStrictEqual(apiBody, { table: "myTable", @@ -166,32 +123,36 @@ describe("dataSourceCommand", () => { }); it("should return the correct API body for a new data source with some fields", () => { - const api = dummyDataSourceFiles.dataSource.api; - - api.startTS = "2022-01-01T00:00:00Z"; - api.endTS = "2022-01-02T00:00:00Z"; - api.fill = "zero"; - api.rowCountLimit = "20"; - api.isRowLimitLast = true; - api.temporality = "snapshot"; - api.filter = ["col1=val1;col2=val2", "col3=val3"]; - api.groupBy = ["col1", "col2"]; - api.agg = ["sum(col3)", "avg(col4)"]; - api.sortCols = ["col1 ASC", "col2 DESC"]; - api.slice = ["10", "20"]; - api.labels = ["label1", "label2"]; - api.table = "myTable"; - api.optional = { - filled: true, - temporal: true, - rowLimit: true, - filters: [], - sorts: [], - groups: [], - aggs: [], - labels: [], - }; - const apiBody = dataSourceCommand.getApiBody(dummyDataSourceFiles); + const apiBody = dataSourceCommand.getApiBody( + createMockDatasource({ + api: { + selectedApi: "getData", + startTS: "2022-01-01T00:00:00Z", + endTS: "2022-01-02T00:00:00Z", + fill: "zero", + rowCountLimit: "20", + isRowLimitLast: true, + temporality: "snapshot", + filter: ["col1=val1,col2=val2", "col3=val3"], + groupBy: ["col1", "col2"], + agg: ["sum(col3)", "avg(col4)"], + sortCols: ["col1 ASC", "col2 DESC"], + slice: ["10", "20"], + labels: ["label1", "label2"], + table: "myTable", + optional: { + filled: true, + temporal: true, + rowLimit: true, + filters: [], + sorts: [], + groups: [], + aggs: [], + labels: [], + }, + }, + }), + ); assert.deepStrictEqual(apiBody, { table: "myTable", @@ -205,64 +166,74 @@ describe("dataSourceCommand", () => { }); it("should return the correct API body for a new data source with slice", () => { - const api = dummyDataSourceFiles.dataSource.api; - - api.startTS = "2022-01-01T00:00:00Z"; - api.endTS = "2022-01-02T00:00:00Z"; - api.fill = "zero"; - api.rowCountLimit = "20"; - api.isRowLimitLast = false; - api.temporality = "slice"; - api.filter = []; - api.groupBy = []; - api.agg = []; - api.sortCols = []; - api.slice = []; - api.labels = []; - api.table = "myTable"; - api.optional = { - rowLimit: true, - filled: false, - temporal: true, - filters: [], - sorts: [], - groups: [], - aggs: [], - labels: [], - }; - const apiBody = dataSourceCommand.getApiBody(dummyDataSourceFiles); + const apiBody = dataSourceCommand.getApiBody( + createMockDatasource({ + api: { + selectedApi: "getData", + startTS: "2022-01-01T00:00:00Z", + endTS: "2022-01-02T00:00:00Z", + fill: "zero", + rowCountLimit: "20", + isRowLimitLast: false, + temporality: "slice", + filter: [], + groupBy: [], + agg: [], + sortCols: [], + slice: [], + labels: [], + table: "myTable", + optional: { + rowLimit: true, + filled: false, + temporal: true, + filters: [], + sorts: [], + groups: [], + aggs: [], + labels: [], + }, + }, + }), + ); assert.strictEqual(apiBody.temporality, "slice"); }); it("should return the correct API body for a new data source with all fields", () => { - const api = dummyDataSourceFiles.dataSource.api; - - api.startTS = "2022-01-01T00:00:00Z"; - api.endTS = "2022-01-02T00:00:00Z"; - api.fill = "zero"; - api.temporality = "snapshot"; - api.rowCountLimit = "20"; - api.isRowLimitLast = false; - api.filter = []; - api.groupBy = []; - api.agg = []; - api.sortCols = []; - api.slice = []; - api.labels = []; - api.table = "myTable"; - api.optional = { - rowLimit: false, - filled: true, - temporal: true, - filters: [ - { active: true, column: "bid", operator: ">", values: "100" }, - ], - sorts: [{ active: true, column: "sym" }], - groups: [{ active: true, column: "bid" }], - aggs: [{ active: true, column: "ask", operator: "sum", key: "sumC" }], - labels: [{ active: true, key: "key", value: "value" }], - }; - const apiBody = dataSourceCommand.getApiBody(dummyDataSourceFiles); + const apiBody = dataSourceCommand.getApiBody( + createMockDatasource({ + api: { + selectedApi: "getData", + startTS: "2022-01-01T00:00:00Z", + endTS: "2022-01-02T00:00:00Z", + fill: "zero", + temporality: "snapshot", + rowCountLimit: "20", + isRowLimitLast: false, + filter: [], + groupBy: [], + agg: [], + sortCols: [], + slice: [], + labels: [], + table: "myTable", + optional: { + rowLimit: false, + filled: true, + temporal: true, + filters: [ + { active: true, column: "bid", operator: ">", values: "100" }, + ], + sorts: [{ active: true, column: "sym" }], + groups: [{ active: true, column: "bid" }], + aggs: [ + { active: true, column: "ask", operator: "sum", key: "sumC" }, + ], + labels: [{ active: true, key: "key", value: "value" }], + }, + }, + }), + ); assert.deepStrictEqual(apiBody, { table: "myTable", @@ -281,18 +252,25 @@ describe("dataSourceCommand", () => { }); it("should return the correct API body for a data source with only required fields", () => { - dummyDataSourceFiles.dataSource.api.startTS = "2022-01-01T00:00:00Z"; - dummyDataSourceFiles.dataSource.api.endTS = "2022-01-02T00:00:00Z"; - dummyDataSourceFiles.dataSource.api.fill = ""; - dummyDataSourceFiles.dataSource.api.temporality = ""; - dummyDataSourceFiles.dataSource.api.filter = []; - dummyDataSourceFiles.dataSource.api.groupBy = []; - dummyDataSourceFiles.dataSource.api.agg = []; - dummyDataSourceFiles.dataSource.api.sortCols = []; - dummyDataSourceFiles.dataSource.api.slice = []; - dummyDataSourceFiles.dataSource.api.labels = []; - dummyDataSourceFiles.dataSource.api.table = "myTable"; - const apiBody = dataSourceCommand.getApiBody(dummyDataSourceFiles); + const apiBody = dataSourceCommand.getApiBody( + createMockDatasource({ + api: { + selectedApi: "getData", + startTS: "2022-01-01T00:00:00Z", + endTS: "2022-01-02T00:00:00Z", + fill: "", + temporality: "", + filter: [], + groupBy: [], + agg: [], + sortCols: [], + slice: [], + labels: [], + table: "myTable", + }, + }), + ); + assert.deepStrictEqual(apiBody, { table: "myTable", startTS: "2022-01-01T00:00:00.000000000", @@ -302,15 +280,13 @@ describe("dataSourceCommand", () => { }); describe("runApiDataSource", () => { - let _windowMock: sinon.SinonMock; - let getApiBodyStub, - checkIfTimeParamIsCorrectStub, - getDataInsightsStub, - handleWSResultsStub, - handleScratchpadTableRes: sinon.SinonStub; + let getApiBodyStub: sinon.SinonStub; + let checkIfTimeParamIsCorrectStub: sinon.SinonStub; + let getDataInsightsStub: sinon.SinonStub; + let handleWSResultsStub: sinon.SinonStub; + let handleScratchpadTableRes: sinon.SinonStub; beforeEach(() => { - _windowMock = sinon.mock(vscode.window); getApiBodyStub = sinon.stub(dataSourceCommand, "getApiBody"); checkIfTimeParamIsCorrectStub = sinon.stub( dataSourceUtils, @@ -338,7 +314,7 @@ describe("dataSourceCommand", () => { ); await dataSourceCommand.runApiDataSource( - dummyDataSourceFiles, + createMockDatasource(), insightsConn, ); @@ -355,47 +331,27 @@ describe("dataSourceCommand", () => { it("should call the API and handle the results if the time parameters are correct", async () => { checkIfTimeParamIsCorrectStub.returns(true); getApiBodyStub.returns({ table: "myTable" }); - getDataInsightsStub.resolves({ arrayBuffer: true }); - handleWSResultsStub.resolves([ - { a: "2", b: "3" }, - { a: "4", b: "6" }, - { a: "6", b: "9" }, - ]); + getDataInsightsStub.resolves({ results: {} }); handleScratchpadTableRes.resolves([ { a: "2", b: "3" }, { a: "4", b: "6" }, { a: "6", b: "9" }, ]); - const result = await dataSourceCommand.runApiDataSource( - dummyDataSourceFiles, + await dataSourceCommand.runApiDataSource( + createMockDatasource(), insightsConn, ); sinon.assert.calledOnce(getDataInsightsStub); - sinon.assert.calledOnce(handleWSResultsStub); - assert.deepStrictEqual(result, [ - { a: "2", b: "3" }, - { a: "4", b: "6" }, - { a: "6", b: "9" }, - ]); }); }); describe("runQsqlDataSource", () => { - let _windowMock: sinon.SinonMock; - let getDataInsightsStub, - handleWSResultsStub, - handleScratchpadTableRes: sinon.SinonStub; + let getDataInsightsStub: sinon.SinonStub; beforeEach(() => { - _windowMock = sinon.mock(vscode.window); getDataInsightsStub = sinon.stub(insightsConn, "getDatasourceQuery"); - handleWSResultsStub = sinon.stub(queryUtils, "handleWSResults"); - handleScratchpadTableRes = sinon.stub( - queryUtils, - "handleScratchpadTableRes", - ); }); afterEach(() => { @@ -403,46 +359,23 @@ describe("dataSourceCommand", () => { }); it("should call the API and handle the results", async () => { - getDataInsightsStub.resolves({ arrayBuffer: true }); - handleWSResultsStub.resolves([ - { a: "2", b: "3" }, - { a: "4", b: "6" }, - { a: "6", b: "9" }, - ]); - handleScratchpadTableRes.resolves([ - { a: "2", b: "3" }, - { a: "4", b: "6" }, - { a: "6", b: "9" }, - ]); - const result = await dataSourceCommand.runQsqlDataSource( - dummyDataSourceFiles, + getDataInsightsStub.resolves(getDataIntResponse); + + const results = await dataSourceCommand.runQsqlDataSource( + createMockDatasource(), insightsConn, ); sinon.assert.calledOnce(getDataInsightsStub); - sinon.assert.calledOnce(handleWSResultsStub); - assert.deepStrictEqual(result, [ - { a: "2", b: "3" }, - { a: "4", b: "6" }, - { a: "6", b: "9" }, - ]); + assert.deepStrictEqual(results, getDataIntResponse.results); }); }); describe("runSqlDataSource", () => { - let _windowMock: sinon.SinonMock; - let getDataInsightsStub, - handleWSResultsStub, - handleScratchpadTableRes: sinon.SinonStub; + let getDataInsightsStub: sinon.SinonStub; beforeEach(() => { - _windowMock = sinon.mock(vscode.window); getDataInsightsStub = sinon.stub(insightsConn, "getDatasourceQuery"); - handleWSResultsStub = sinon.stub(queryUtils, "handleWSResults"); - handleScratchpadTableRes = sinon.stub( - queryUtils, - "handleScratchpadTableRes", - ); }); afterEach(() => { @@ -450,48 +383,27 @@ describe("dataSourceCommand", () => { }); it("should call the API and handle the results", async () => { - getDataInsightsStub.resolves({ arrayBuffer: true }); - handleWSResultsStub.resolves([ - { a: "2", b: "3" }, - { a: "4", b: "6" }, - { a: "6", b: "9" }, - ]); - handleScratchpadTableRes.resolves([ - { a: "2", b: "3" }, - { a: "4", b: "6" }, - { a: "6", b: "9" }, - ]); - const result = await dataSourceCommand.runSqlDataSource( - dummyDataSourceFiles, + getDataInsightsStub.resolves(getDataIntResponse); + + const results = await dataSourceCommand.runSqlDataSource( + createMockDatasource(), insightsConn, ); sinon.assert.calledOnce(getDataInsightsStub); - sinon.assert.calledOnce(handleWSResultsStub); - assert.deepStrictEqual(result, [ - { a: "2", b: "3" }, - { a: "4", b: "6" }, - { a: "6", b: "9" }, - ]); + assert.deepStrictEqual(results, getDataIntResponse.results); }); }); describe("runUDADataSource", () => { - let getDataInsightsStub, - handleWSResultsStub, - handleScratchpadTableRes, - isUDAAvailableStub, - parseErrorStub: sinon.SinonStub; + let getDataInsightsStub: sinon.SinonStub; + let isUDAAvailableStub: sinon.SinonStub; + let parseErrorStub: sinon.SinonStub; beforeEach(() => { getDataInsightsStub = sinon.stub(insightsConn, "getDatasourceQuery"); - handleWSResultsStub = sinon.stub(queryUtils, "handleWSResults"); parseErrorStub = sinon.stub(dataSourceCommand, "parseError"); isUDAAvailableStub = sinon.stub(insightsConn, "isUDAAvailable"); - handleScratchpadTableRes = sinon.stub( - queryUtils, - "handleScratchpadTableRes", - ); }); afterEach(() => { @@ -500,29 +412,15 @@ describe("dataSourceCommand", () => { it("should call the API and handle the results", async () => { isUDAAvailableStub.resolves(true); - getDataInsightsStub.resolves({ arrayBuffer: true }); - handleWSResultsStub.resolves([ - { a: "2", b: "3" }, - { a: "4", b: "6" }, - { a: "6", b: "9" }, - ]); - handleScratchpadTableRes.resolves([ - { a: "2", b: "3" }, - { a: "4", b: "6" }, - { a: "6", b: "9" }, - ]); - const result = await dataSourceCommand.runUDADataSource( - dummyDataSourceFiles, + getDataInsightsStub.resolves(getDataIntResponse); + + const results = await dataSourceCommand.runUDADataSource( + createMockDatasource(), insightsConn, ); sinon.assert.calledOnce(getDataInsightsStub); - sinon.assert.calledOnce(handleWSResultsStub); - assert.deepStrictEqual(result, [ - { a: "2", b: "3" }, - { a: "4", b: "6" }, - { a: "6", b: "9" }, - ]); + assert.deepStrictEqual(results, getDataIntResponse.results); }); it("should call the API and handle the error results", async () => { @@ -530,7 +428,7 @@ describe("dataSourceCommand", () => { getDataInsightsStub.resolves({ error: "error test" }); parseErrorStub.resolves({ error: "error test" }); const result = await dataSourceCommand.runUDADataSource( - dummyDataSourceFiles, + createMockDatasource(), insightsConn, ); @@ -541,7 +439,7 @@ describe("dataSourceCommand", () => { isUDAAvailableStub.resolves(true); getDataInsightsStub.resolves(undefined); const result = await dataSourceCommand.runUDADataSource( - dummyDataSourceFiles, + createMockDatasource(), insightsConn, ); @@ -552,7 +450,7 @@ describe("dataSourceCommand", () => { isUDAAvailableStub.resolves(false); getDataInsightsStub.resolves(undefined); const result = await dataSourceCommand.runUDADataSource( - dummyDataSourceFiles, + createMockDatasource(), insightsConn, ); @@ -564,20 +462,24 @@ describe("dataSourceCommand", () => { it("should handle if a required param is empty", async () => { isUDAAvailableStub.resolves(true); getDataInsightsStub.resolves(undefined); - const dummyDSFiles2 = dummyDataSourceFiles; - - dummyDSFiles2.dataSource.uda.params = [ - { - name: "param1", - description: "test param", - default: "", - isReq: true, - type: [0], - value: "", - }, - ]; + const result = await dataSourceCommand.runUDADataSource( - dummyDSFiles2, + createMockDatasource({ + uda: { + name: "test query", + description: "test description", + params: [ + { + name: "param1", + description: "test param", + default: "", + isReq: true, + type: [0], + value: "", + }, + ], + }, + }), insightsConn, ); @@ -589,11 +491,16 @@ describe("dataSourceCommand", () => { it("should handle if have invalid parameter type", async () => { isUDAAvailableStub.resolves(true); getDataInsightsStub.resolves(undefined); - const dummyDSFiles2 = dummyDataSourceFiles; - dummyDSFiles2.dataSource.uda.incompatibleError = "test error"; const result = await dataSourceCommand.runUDADataSource( - dummyDSFiles2, + createMockDatasource({ + uda: { + name: "test query", + description: "test description", + params: [], + incompatibleError: "test error", + }, + }), insightsConn, ); @@ -604,9 +511,10 @@ describe("dataSourceCommand", () => { }); it("should handle undefined UDA ", async () => { - dummyDataSourceFiles.dataSource.uda = undefined; const result = await dataSourceCommand.runUDADataSource( - dummyDataSourceFiles, + createMockDatasource({ + uda: undefined, + }), insightsConn, ); @@ -614,9 +522,14 @@ describe("dataSourceCommand", () => { }); it("should handle UDA without name", async () => { - dummyDataSourceFiles.dataSource.uda.name = ""; const result = await dataSourceCommand.runUDADataSource( - dummyDataSourceFiles, + createMockDatasource({ + uda: { + name: "", + description: "", + params: [], + }, + }), insightsConn, ); @@ -625,110 +538,48 @@ describe("dataSourceCommand", () => { }); describe("runDataSource", () => { - const dummyMeta: MetaObject = { - header: { - ac: "0", - agg: ":127.0.0.1:5070", - ai: "", - api: ".kxi.getMeta", - client: ":127.0.0.1:5050", - corr: "CorrHash", - http: "json", - logCorr: "logCorrHash", - protocol: "gw", - rc: "0", - rcvTS: "2099-05-22T11:06:33.650000000", - retryCount: "0", - to: "2099-05-22T11:07:33.650000000", - userID: "dummyID", - userName: "testUser", + const mockDataSourceFile = createMockDatasource({ + selectedType: DataSourceTypes.QSQL, + api: { + selectedApi: "getData", + table: "dummyTbl", + startTS: "2023-09-10T09:30", + endTS: "2023-09-19T12:30", + fill: "", + temporality: "", + filter: [], + groupBy: [], + agg: [], + sortCols: [], + slice: [], + labels: [], }, - payload: { - rc: [ - { - api: 3, - agg: 1, - assembly: 1, - schema: 1, - rc: "dummy-rc", - labels: [{ kxname: "dummy-assembly" }], - started: "2023-10-04T17:20:57.659088747", - }, - ], - dap: [], - api: [], - agg: [ - { - aggFn: ".sgagg.aggFnDflt", - custom: false, - full: true, - metadata: { - description: "dummy desc.", - params: [{ description: "dummy desc." }], - return: { description: "dummy desc." }, - misc: {}, - }, - procs: [], - }, - ], - assembly: [ - { - assembly: "dummy-assembly", - kxname: "dummy-assembly", - tbls: ["dummyTbl"], - }, - ], - schema: [], + qsql: { + query: + "n:10;\n([] date:n?(reverse .z.d-1+til 10); instance:n?`inst1`inst2`inst3`inst4; sym:n?`USD`EUR`GBP`JPY; cnt:n?10; lists:{x?10}@/:1+n?10)\n", + selectedTarget: "dummy-target", }, - }; - const dummyFileContent: DataSourceFiles = { - name: "dummy-DS", - dataSource: { - selectedType: DataSourceTypes.QSQL, - api: { - selectedApi: "getData", - table: "dummyTbl", - startTS: "2023-09-10T09:30", - endTS: "2023-09-19T12:30", - fill: "", - temporality: "", - filter: [], - groupBy: [], - agg: [], - sortCols: [], - slice: [], - labels: [], - }, - qsql: { - query: - "n:10;\n([] date:n?(reverse .z.d-1+til 10); instance:n?`inst1`inst2`inst3`inst4; sym:n?`USD`EUR`GBP`JPY; cnt:n?10; lists:{x?10}@/:1+n?10)\n", - selectedTarget: "dummy-target", - }, - sql: { query: "test query" }, - uda: { - name: "test query", - description: "test description", - params: [], - }, + sql: { query: "test query" }, + uda: { + name: "test query", + description: "test description", + params: [], }, - insightsNode: "dummyNode", - }; + }); + const dummyError = { error: "error message", }; const connMngService = new ConnectionManagementService(); const uriTest: vscode.Uri = vscode.Uri.parse("test"); - const ab = new ArrayBuffer(26); ext.resultsViewProvider = new KdbResultsViewProvider(uriTest); - let isVisibleStub, - getMetaStub, - _handleWSResultsStub, - _handleScratchpadTableRes, - retrieveConnStub, - getDataInsightsStub, - writeQueryResultsToViewStub, - writeQueryResultsToConsoleStub: sinon.SinonStub; + let isVisibleStub: sinon.SinonStub; + let getMetaStub: sinon.SinonStub; + let retrieveConnStub: sinon.SinonStub; + let getDataInsightsStub: sinon.SinonStub; + let writeQueryResultsToViewStub: sinon.SinonStub; + let writeQueryResultsToConsoleStub: sinon.SinonStub; let windowMock: sinon.SinonMock; ext.outputChannel = vscode.window.createOutputChannel("kdb", { log: true }); @@ -741,12 +592,6 @@ describe("dataSourceCommand", () => { windowMock = sinon.mock(vscode.window); getMetaStub = sinon.stub(insightsConn, "getMeta"); isVisibleStub = sinon.stub(ext.resultsViewProvider, "isVisible"); - _handleWSResultsStub = sinon - .stub(queryUtils, "handleWSResults") - .returns("dummy results"); - _handleScratchpadTableRes = sinon - .stub(queryUtils, "handleScratchpadTableRes") - .returns("dummy results"); getDataInsightsStub = sinon.stub(insightsConn, "getDatasourceQuery"); writeQueryResultsToViewStub = sinon.stub( serverCommand, @@ -809,13 +654,13 @@ describe("dataSourceCommand", () => { it("should return error for visible results panel", async () => { ext.connectedConnectionList.push(insightsConn); retrieveConnStub.resolves(insightsConn); - insightsConn.meta = dummyMeta; - getMetaStub.resolves(dummyMeta); + insightsConn.meta = getMetaResponse; + getMetaStub.resolves(getMetaResponse); sinon.stub(dataSourceCommand, "runQsqlDataSource").resolves(dummyError); ext.isResultsTabVisible = true; await dataSourceCommand.runDataSource( - dummyFileContent as DataSourceFiles, + mockDataSourceFile, insightsConn.connLabel, "test-file.kdb.json", ); @@ -828,13 +673,13 @@ describe("dataSourceCommand", () => { it("should return error for console panel", async () => { ext.connectedConnectionList.push(insightsConn); retrieveConnStub.resolves(insightsConn); - insightsConn.meta = dummyMeta; - getMetaStub.resolves(dummyMeta); + insightsConn.meta = getMetaResponse; + getMetaStub.resolves(getMetaResponse); sinon.stub(dataSourceCommand, "runQsqlDataSource").resolves(dummyError); ext.isResultsTabVisible = false; await dataSourceCommand.runDataSource( - dummyFileContent as DataSourceFiles, + mockDataSourceFile, insightsConn.connLabel, "test-file.kdb.json", ); @@ -847,12 +692,12 @@ describe("dataSourceCommand", () => { it("should return QSQL results", async () => { ext.connectedConnectionList.push(insightsConn); retrieveConnStub.resolves(insightsConn); - insightsConn.meta = dummyMeta; - getMetaStub.resolves(dummyMeta); - getDataInsightsStub.resolves({ arrayBuffer: ab, error: "" }); + insightsConn.meta = getMetaResponse; + getMetaStub.resolves(getMetaResponse); + getDataInsightsStub.resolves({ results: getDataResponse, error: "" }); ext.isResultsTabVisible = true; await dataSourceCommand.runDataSource( - dummyFileContent as DataSourceFiles, + mockDataSourceFile, insightsConn.connLabel, "test-file.kdb.json", ); @@ -865,13 +710,13 @@ describe("dataSourceCommand", () => { it("should return API results", async () => { ext.connectedConnectionList.push(insightsConn); retrieveConnStub.resolves(insightsConn); - insightsConn.meta = dummyMeta; - dummyFileContent.dataSource.selectedType = DataSourceTypes.API; - getMetaStub.resolves(dummyMeta); - getDataInsightsStub.resolves({ arrayBuffer: ab, error: "" }); + insightsConn.meta = getMetaResponse; + mockDataSourceFile.dataSource.selectedType = DataSourceTypes.API; + getMetaStub.resolves(getMetaResponse); + getDataInsightsStub.resolves({ results: getDataResponse, error: "" }); ext.isResultsTabVisible = false; await dataSourceCommand.runDataSource( - dummyFileContent as DataSourceFiles, + mockDataSourceFile, insightsConn.connLabel, "test-file.kdb.json", ); @@ -884,13 +729,13 @@ describe("dataSourceCommand", () => { it("should return SQL results", async () => { ext.connectedConnectionList.push(insightsConn); retrieveConnStub.resolves(insightsConn); - insightsConn.meta = dummyMeta; - dummyFileContent.dataSource.selectedType = DataSourceTypes.SQL; - getMetaStub.resolves(dummyMeta); - getDataInsightsStub.resolves({ arrayBuffer: ab, error: "" }); + insightsConn.meta = getMetaResponse; + mockDataSourceFile.dataSource.selectedType = DataSourceTypes.SQL; + getMetaStub.resolves(getMetaResponse); + getDataInsightsStub.resolves({ results: getDataResponse, error: "" }); ext.isResultsTabVisible = false; await dataSourceCommand.runDataSource( - dummyFileContent as DataSourceFiles, + mockDataSourceFile, insightsConn.connLabel, "test-file.kdb.json", ); @@ -903,13 +748,13 @@ describe("dataSourceCommand", () => { it("should return UDA results", async () => { ext.connectedConnectionList.push(insightsConn); retrieveConnStub.resolves(insightsConn); - insightsConn.meta = dummyMeta; - dummyFileContent.dataSource.selectedType = DataSourceTypes.UDA; - getMetaStub.resolves(dummyMeta); - getDataInsightsStub.resolves({ arrayBuffer: ab, error: "" }); + insightsConn.meta = getMetaResponse; + mockDataSourceFile.dataSource.selectedType = DataSourceTypes.UDA; + getMetaStub.resolves(getMetaResponse); + getDataInsightsStub.resolves({ results: getDataResponse, error: "" }); ext.isResultsTabVisible = false; await dataSourceCommand.runDataSource( - dummyFileContent as DataSourceFiles, + mockDataSourceFile, insightsConn.connLabel, "test-file.kdb.json", ); @@ -920,12 +765,12 @@ describe("dataSourceCommand", () => { }); it("should return error message QSQL", async () => { - dummyFileContent.dataSource.selectedType = DataSourceTypes.QSQL; - getMetaStub.resolves(dummyMeta); - getDataInsightsStub.resolves({ arrayBuffer: ab, error: "error" }); + mockDataSourceFile.dataSource.selectedType = DataSourceTypes.QSQL; + getMetaStub.resolves(getMetaResponse); + getDataInsightsStub.resolves({ results: getDataResponse, error: "" }); isVisibleStub.returns(false); await dataSourceCommand.runDataSource( - dummyFileContent as DataSourceFiles, + mockDataSourceFile, insightsConn.connLabel, "test-file.kdb.json", ); @@ -934,12 +779,12 @@ describe("dataSourceCommand", () => { }); it("should return error message API", async () => { - dummyFileContent.dataSource.selectedType = DataSourceTypes.API; - getMetaStub.resolves(dummyMeta); - getDataInsightsStub.resolves({ arrayBuffer: ab, error: "error" }); + mockDataSourceFile.dataSource.selectedType = DataSourceTypes.API; + getMetaStub.resolves(getMetaResponse); + getDataInsightsStub.resolves({ results: getDataResponse, error: "" }); isVisibleStub.returns(false); await dataSourceCommand.runDataSource( - dummyFileContent as DataSourceFiles, + mockDataSourceFile, insightsConn.connLabel, "test-file.kdb.json", ); @@ -948,12 +793,12 @@ describe("dataSourceCommand", () => { }); it("should return error message SQL", async () => { - dummyFileContent.dataSource.selectedType = DataSourceTypes.SQL; - getMetaStub.resolves(dummyMeta); - getDataInsightsStub.resolves({ arrayBuffer: ab, error: "error" }); + mockDataSourceFile.dataSource.selectedType = DataSourceTypes.SQL; + getMetaStub.resolves(getMetaResponse); + getDataInsightsStub.resolves({ results: getDataResponse, error: "" }); isVisibleStub.returns(false); await dataSourceCommand.runDataSource( - dummyFileContent as DataSourceFiles, + mockDataSourceFile, insightsConn.connLabel, "test-file.kdb.json", ); @@ -962,12 +807,12 @@ describe("dataSourceCommand", () => { }); it("should return error message QSQL", async () => { - dummyFileContent.dataSource.selectedType = DataSourceTypes.QSQL; - getMetaStub.resolves(dummyMeta); + mockDataSourceFile.dataSource.selectedType = DataSourceTypes.QSQL; + getMetaStub.resolves(getMetaResponse); getDataInsightsStub.resolves(undefined); isVisibleStub.returns(false); await dataSourceCommand.runDataSource( - dummyFileContent as DataSourceFiles, + mockDataSourceFile, insightsConn.connLabel, "test-file.kdb.json", ); @@ -976,12 +821,12 @@ describe("dataSourceCommand", () => { }); it("should return error message API", async () => { - dummyFileContent.dataSource.selectedType = DataSourceTypes.API; - getMetaStub.resolves(dummyMeta); + mockDataSourceFile.dataSource.selectedType = DataSourceTypes.API; + getMetaStub.resolves(getMetaResponse); getDataInsightsStub.resolves(undefined); isVisibleStub.returns(false); await dataSourceCommand.runDataSource( - dummyFileContent as DataSourceFiles, + mockDataSourceFile, insightsConn.connLabel, "test-file.kdb.json", ); @@ -990,12 +835,12 @@ describe("dataSourceCommand", () => { }); it("should return error message SQL", async () => { - dummyFileContent.dataSource.selectedType = DataSourceTypes.SQL; - getMetaStub.resolves(dummyMeta); + mockDataSourceFile.dataSource.selectedType = DataSourceTypes.SQL; + getMetaStub.resolves(getMetaResponse); getDataInsightsStub.resolves(undefined); isVisibleStub.returns(false); await dataSourceCommand.runDataSource( - dummyFileContent as DataSourceFiles, + mockDataSourceFile, insightsConn.connLabel, "test-file.kdb.json", ); @@ -1006,7 +851,7 @@ describe("dataSourceCommand", () => { it("should handle errors correctly", async () => { retrieveConnStub.throws(new Error("Test error")); await dataSourceCommand.runDataSource( - dummyFileContent as DataSourceFiles, + mockDataSourceFile, insightsConn.connLabel, "test-file.kdb.json", ); @@ -1016,9 +861,7 @@ describe("dataSourceCommand", () => { describe("populateScratchpad", async () => { let windowMock: sinon.SinonMock; - let connMngService: ConnectionManagementService; - let qeStatusStub: sinon.SinonStub; - const dummyFileContent: DataSourceFiles = { + const mockDataSourceFile: DataSourceFiles = { name: "dummy-DS", dataSource: { selectedType: DataSourceTypes.QSQL, @@ -1054,11 +897,6 @@ describe("dataSourceCommand", () => { beforeEach(() => { ext.activeConnection = insightsConn; windowMock = sinon.mock(vscode.window); - connMngService = new ConnectionManagementService(); - qeStatusStub = sinon.stub( - connMngService, - "retrieveInsightsConnQEEnabled", - ); }); afterEach(() => { @@ -1068,7 +906,7 @@ describe("dataSourceCommand", () => { it("should show error msg", async () => { await dataSourceCommand.populateScratchpad( - dummyFileContent, + mockDataSourceFile, localConn.connLabel, "testOutput", ); diff --git a/test/suite/commands/serverCommand.test.ts b/test/suite/commands/serverCommand.test.ts index 276c24809..e40535154 100644 --- a/test/suite/commands/serverCommand.test.ts +++ b/test/suite/commands/serverCommand.test.ts @@ -27,10 +27,7 @@ import { ServerDetails, ServerType, } from "../../../src/models/connectionsModels"; -import { - createDefaultDataSourceFile, - DataSourceTypes, -} from "../../../src/models/dataSource"; +import { DataSourceTypes } from "../../../src/models/dataSource"; import { ExecutionTypes } from "../../../src/models/execution"; import { QueryHistory } from "../../../src/models/queryHistory"; import { ScratchpadResult } from "../../../src/models/scratchpadResult"; @@ -49,6 +46,7 @@ import { ExecutionConsole } from "../../../src/utils/executionConsole"; import * as loggers from "../../../src/utils/loggers"; import * as notifications from "../../../src/utils/notifications"; import * as kdbValidators from "../../../src/validators/kdbValidator"; +import { createMockDatasource } from "../../fixtures/config/datasource"; describe("serverCommand", () => { const servers = { @@ -1085,7 +1083,7 @@ describe("serverCommand", () => { }); it("should run datasource for datasource query", async function () { - const ds = createDefaultDataSourceFile(); + const ds = createMockDatasource(); const rerunQueryElement: QueryHistory = { executorName: "test", isDatasource: true, @@ -1510,7 +1508,7 @@ describe("serverCommand", () => { }); it("should not copy query to clipboard if query is not string", async () => { - const dummyDsFiles = createDefaultDataSourceFile(); + const dummyDsFiles = createMockDatasource(); const queryHistory: QueryHistory = { executorName: "test", connectionName: "conn", diff --git a/test/suite/services/connectionManagementService.test.ts b/test/suite/services/connectionManagementService.test.ts index 4b3a3eedd..7a9ec8d15 100644 --- a/test/suite/services/connectionManagementService.test.ts +++ b/test/suite/services/connectionManagementService.test.ts @@ -15,7 +15,6 @@ import * as assert from "assert"; import * as sinon from "sinon"; import * as vscode from "vscode"; -import { dummyMeta } from "./services.utils.test"; import { InsightsConnection } from "../../../src/classes/insightsConnection"; import { LocalConnection } from "../../../src/classes/localConnection"; import { ext } from "../../../src/extensionVariables"; @@ -30,6 +29,7 @@ import { import * as loggers from "../../../src/utils/loggers"; import AuthSettings from "../../../src/utils/secretStorage"; import { Telemetry } from "../../../src/utils/telemetryClient"; +import { getMetaResponse } from "../../fixtures/api/getMeta"; describe("ConnectionManagementService", () => { const connectionManagerService = new ConnectionManagementService(); @@ -602,7 +602,7 @@ describe("ConnectionManagementService", () => { }); it("should return meta object for valid input", () => { - insightsConn.meta = dummyMeta; + insightsConn.meta = getMetaResponse; sandbox .stub(connectionManagerService, "getMetaInfoType") .returns(MetaInfoType.META); @@ -614,7 +614,7 @@ describe("ConnectionManagementService", () => { insightsConn.connLabel, "meta", ), - JSON.stringify(dummyMeta.payload), + JSON.stringify(getMetaResponse.payload), ); }); }); diff --git a/test/suite/services/kdbTree/kdbTreeProvider.test.ts b/test/suite/services/kdbTree/kdbTreeProvider.test.ts index c4dd5b911..b458625ff 100644 --- a/test/suite/services/kdbTree/kdbTreeProvider.test.ts +++ b/test/suite/services/kdbTree/kdbTreeProvider.test.ts @@ -34,7 +34,7 @@ import { QServerNode, } from "../../../../src/services/kdbTreeProvider"; import { KdbTreeService } from "../../../../src/services/kdbTreeService"; -import { dummyMeta } from "../services.utils.test"; +import { getMetaResponse } from "../../../fixtures/api/getMeta"; describe("kdbTreeProvider", () => { let servers: Server; @@ -621,7 +621,7 @@ describe("kdbTreeProvider", () => { insightNode, ); sinon.stub(connMng, "retrieveConnectedConnection").returns(insightsConn); - insightsConn.meta = dummyMeta; + insightsConn.meta = getMetaResponse; const result = await kdbProvider.getChildren(metaNode); assert.notStrictEqual(result, undefined); }); diff --git a/test/suite/services/providers/datasourceEditorProvider.test.ts b/test/suite/services/providers/datasourceEditorProvider.test.ts index 36c6ab0f0..29f312697 100644 --- a/test/suite/services/providers/datasourceEditorProvider.test.ts +++ b/test/suite/services/providers/datasourceEditorProvider.test.ts @@ -19,11 +19,14 @@ import { createPanel } from "./provider.utils.test"; import { InsightsConnection } from "../../../../src/classes/insightsConnection"; import { LocalConnection } from "../../../../src/classes/localConnection"; import { ext } from "../../../../src/extensionVariables"; -import { MetaObject } from "../../../../src/models/meta"; import { ConnectionManagementService } from "../../../../src/services/connectionManagerService"; import { DataSourceEditorProvider } from "../../../../src/services/dataSourceEditorProvider"; import { InsightsNode } from "../../../../src/services/kdbTreeProvider"; import * as utils from "../../../../src/utils/uriUtils"; +import { + getMetaNoAssemblyResponse, + getMetaResponse, +} from "../../../fixtures/api/getMeta"; describe("dataSourceEditorProvider", () => { let context: vscode.ExtensionContext; @@ -65,113 +68,6 @@ describe("dataSourceEditorProvider", () => { }); describe("getMeta", () => { - const dummyMeta: MetaObject = { - header: { - ac: "0", - agg: ":127.0.0.1:5070", - ai: "", - api: ".kxi.getMeta", - client: ":127.0.0.1:5050", - corr: "CorrHash", - http: "json", - logCorr: "logCorrHash", - protocol: "gw", - rc: "0", - rcvTS: "2099-05-22T11:06:33.650000000", - retryCount: "0", - to: "2099-05-22T11:07:33.650000000", - userID: "dummyID", - userName: "testUser", - }, - payload: { - rc: [ - { - api: 3, - agg: 1, - assembly: 1, - schema: 1, - rc: "dummy-rc", - labels: [{ kxname: "dummy-assembly" }], - started: "2023-10-04T17:20:57.659088747", - }, - ], - dap: [], - api: [], - agg: [ - { - aggFn: ".sgagg.aggFnDflt", - custom: false, - full: true, - metadata: { - description: "dummy desc.", - params: [{ description: "dummy desc." }], - return: { description: "dummy desc." }, - misc: {}, - }, - procs: [], - }, - ], - assembly: [ - { - assembly: "dummy-assembly", - kxname: "dummy-assembly", - tbls: ["dummyTbl"], - }, - ], - schema: [], - }, - }; - - const dummyMetaNoAssembly: MetaObject = { - header: { - ac: "0", - agg: ":127.0.0.1:5070", - ai: "", - api: ".kxi.getMeta", - client: ":127.0.0.1:5050", - corr: "CorrHash", - http: "json", - logCorr: "logCorrHash", - protocol: "gw", - rc: "0", - rcvTS: "2099-05-22T11:06:33.650000000", - retryCount: "0", - to: "2099-05-22T11:07:33.650000000", - userID: "dummyID", - userName: "testUser", - }, - payload: { - rc: [ - { - api: 3, - agg: 1, - assembly: 1, - schema: 1, - rc: "dummy-rc", - labels: [{ kxname: "dummy-assembly" }], - started: "2023-10-04T17:20:57.659088747", - }, - ], - dap: [], - api: [], - agg: [ - { - aggFn: ".sgagg.aggFnDflt", - custom: false, - full: true, - metadata: { - description: "dummy desc.", - params: [{ description: "dummy desc." }], - return: { description: "dummy desc." }, - misc: {}, - }, - procs: [], - }, - ], - assembly: [], - schema: [], - }, - }; const insightsNode = new InsightsNode( [], "insightsnode1", @@ -188,7 +84,8 @@ describe("dataSourceEditorProvider", () => { ); const localConn = new LocalConnection("127.0.0.1:5001", "testLabel", []); const connMngService = new ConnectionManagementService(); - let isConnetedStub, _retrieveConnectedConnectionStub: sinon.SinonStub; + let isConnetedStub: sinon.SinonStub; + let _retrieveConnectedConnectionStub: sinon.SinonStub; beforeEach(() => { isConnetedStub = sinon.stub(connMngService, "isConnected"); _retrieveConnectedConnectionStub = sinon.stub( @@ -236,7 +133,7 @@ describe("dataSourceEditorProvider", () => { ext.connectedContextStrings.push(insightsConn.connLabel); ext.connectedConnectionList.push(insightsConn); isConnetedStub.resolves(true); - insightsConn.meta = dummyMetaNoAssembly; + insightsConn.meta = getMetaNoAssemblyResponse; const provider = new DataSourceEditorProvider(context); const result = await provider.getMeta(insightsConn.connLabel); assert.deepStrictEqual(result, {}); @@ -245,10 +142,10 @@ describe("dataSourceEditorProvider", () => { ext.connectedContextStrings.push(insightsConn.connLabel); ext.connectedConnectionList.push(insightsConn); isConnetedStub.resolves(true); - insightsConn.meta = dummyMeta; + insightsConn.meta = getMetaResponse; const provider = new DataSourceEditorProvider(context); const result = await provider.getMeta(insightsConn.connLabel); - assert.deepStrictEqual(result, dummyMeta.payload); + assert.deepStrictEqual(result, getMetaResponse.payload); }); }); }); diff --git a/test/suite/services/providers/queryHistoryProvider.test.ts b/test/suite/services/providers/queryHistoryProvider.test.ts index a0d88981d..1a258c3d7 100644 --- a/test/suite/services/providers/queryHistoryProvider.test.ts +++ b/test/suite/services/providers/queryHistoryProvider.test.ts @@ -16,15 +16,15 @@ import * as vscode from "vscode"; import { ext } from "../../../../src/extensionVariables"; import { ServerType } from "../../../../src/models/connectionsModels"; -import { createDefaultDataSourceFile } from "../../../../src/models/dataSource"; import { QueryHistory } from "../../../../src/models/queryHistory"; import { QueryHistoryProvider, QueryHistoryTreeItem, } from "../../../../src/services/queryHistoryProvider"; +import { createMockDatasource } from "../../../fixtures/config/datasource"; describe("queryHistoryProvider", () => { - const dummyDS = createDefaultDataSourceFile(); + const dummyDS = createMockDatasource(); const dummyQueryHistory: QueryHistory[] = [ { executorName: "testExecutorName", diff --git a/test/suite/webPanels/datasourcePanel.test.ts b/test/suite/webPanels/datasourcePanel.test.ts index 3aa802d21..1dd36e8a3 100644 --- a/test/suite/webPanels/datasourcePanel.test.ts +++ b/test/suite/webPanels/datasourcePanel.test.ts @@ -15,12 +15,12 @@ import assert from "assert"; import * as sinon from "sinon"; import * as vscode from "vscode"; -import { createDefaultDataSourceFile } from "../../../src/models/dataSource"; import { DataSourcesPanel } from "../../../src/panels/datasource"; import * as loggers from "../../../src/utils/loggers"; +import { createMockDatasource } from "../../fixtures/config/datasource"; describe("DataSourcesPanel", () => { - const dsTest = createDefaultDataSourceFile(); + const dsTest = createMockDatasource(); const uriTest: vscode.Uri = vscode.Uri.parse("test"); let kdbOutputLogStub: sinon.SinonStub;