From 319a7fd003d5121477def285f5f7e12554c1047e Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Mon, 16 Sep 2024 18:50:14 +0200 Subject: [PATCH] csv import test (failing) --- .../__tests__/import-formats.spec.js | 43 +++++++++++++++++++ integration-tests/package.json | 3 +- integration-tests/setupTests.js | 8 ++++ integration-tests/tools.js | 5 --- package.json | 1 + yarn.lock | 5 +++ 6 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 integration-tests/__tests__/import-formats.spec.js diff --git a/integration-tests/__tests__/import-formats.spec.js b/integration-tests/__tests__/import-formats.spec.js new file mode 100644 index 00000000..4631531d --- /dev/null +++ b/integration-tests/__tests__/import-formats.spec.js @@ -0,0 +1,43 @@ +const dbgateApi = require('dbgate-api/src/shell'); +// const jsonLinesWriter = require('dbgate-api/src/shell/jsonLinesWriter'); +const tmp = require('tmp'); +// const dbgatePluginCsv = require('dbgate-plugin-csv/src/backend'); +const fs = require('fs'); +const requirePlugin = require('dbgate-api/src/shell/requirePlugin'); + +const CSV_DATA = `Issue Number; Title; Github URL; Labels; State; Created At; Updated At; Reporter; Assignee +801; "Does it 'burst' the database on startup or first lUI load ? "; https://github.com/dbgate/dbgate/issues/801; ""; open; 05/23/2024; 05/23/2024; rgarrigue; +799; "BUG: latest AppImage crashes on opening in Fedora 39"; https://github.com/dbgate/dbgate/issues/799; ""; open; 05/21/2024; 05/24/2024; BenGraham-Git; +798; "MongoDB write operations fail"; https://github.com/dbgate/dbgate/issues/798; "bug,solved"; open; 05/21/2024; 05/24/2024; mahmed0715; +797; "BUG: Unable to open SQL files"; https://github.com/dbgate/dbgate/issues/797; "bug"; open; 05/20/2024; 05/21/2024; cesarValdivia; +795; "BUG: MS SQL Server connection error (KEY_USAGE_BIT_INCORRECT)"; https://github.com/dbgate/dbgate/issues/795; ""; open; 05/20/2024; 05/20/2024; keskinonur; +794; "GLIBC_2.29' not found and i have 2.31"; https://github.com/dbgate/dbgate/issues/794; ""; closed; 05/20/2024; 05/21/2024; MFdanGM; +793; "BUG: PostgresSQL doesn't show tables when connected"; https://github.com/dbgate/dbgate/issues/793; ""; open; 05/20/2024; 05/22/2024; stomper013; +792; "FEAT: Wayland support"; https://github.com/dbgate/dbgate/issues/792; ""; closed; 05/19/2024; 05/21/2024; VosaXalo; +`; + +test('csv import test', async () => { + expect(1).toEqual(1); + const dbgatePluginCsv = requirePlugin('dbgate-plugin-csv'); + + const csvFileName = tmp.tmpNameSync(); + const jsonlFileName = tmp.tmpNameSync(); + + fs.writeFileSync(csvFileName, CSV_DATA); + + const reader = await dbgatePluginCsv.shellApi.reader({ + fileName: csvFileName, + }); + + const writer = await dbgateApi.jsonLinesWriter({ + fileName: jsonlFileName, + }); + await dbgateApi.copyStream(reader, writer); + + const jsonData = fs.readFileSync(jsonlFileName, 'utf-8'); + const rows = jsonData + .split('\n') + .filter(x => x.trim() !== '') + .map(x => JSON.parse(x)); + expect(rows.length).toEqual(9); +}); diff --git a/integration-tests/package.json b/integration-tests/package.json index dcb1e67e..6a0dea08 100644 --- a/integration-tests/package.json +++ b/integration-tests/package.json @@ -22,6 +22,7 @@ "devDependencies": { "cross-env": "^7.0.3", "jest": "^27.0.1", - "pino-pretty": "^11.2.2" + "pino-pretty": "^11.2.2", + "tmp": "^0.2.3" } } diff --git a/integration-tests/setupTests.js b/integration-tests/setupTests.js index b52c4066..e0f76378 100644 --- a/integration-tests/setupTests.js +++ b/integration-tests/setupTests.js @@ -1,4 +1,10 @@ +global.DBGATE_PACKAGES = { + 'dbgate-tools': require('dbgate-tools'), + 'dbgate-sqltree': require('dbgate-sqltree'), +}; + const { prettyFactory } = require('pino-pretty'); +const tmp = require('tmp'); const pretty = prettyFactory({ colorize: true, @@ -20,3 +26,5 @@ global.console = { process.stdout.write(messages.join(' ') + '\n'); }, }; + +tmp.setGracefulCleanup(); diff --git a/integration-tests/tools.js b/integration-tests/tools.js index 846c2765..4ab8c20d 100644 --- a/integration-tests/tools.js +++ b/integration-tests/tools.js @@ -1,8 +1,3 @@ -global.DBGATE_PACKAGES = { - 'dbgate-tools': require('dbgate-tools'), - 'dbgate-sqltree': require('dbgate-sqltree'), -}; - const requireEngineDriver = require('dbgate-api/src/utility/requireEngineDriver'); const crypto = require('crypto'); diff --git a/package.json b/package.json index ec6297e8..ac6acbc0 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "build:api": "yarn workspace dbgate-api build", "build:web:docker": "yarn workspace dbgate-web build", "build:plugins:frontend": "workspaces-run --only=\"dbgate-plugin-*\" -- yarn build:frontend", + "build:plugins:backend": "workspaces-run --only=\"dbgate-plugin-*\" -- yarn build:backend", "build:plugins:frontend:watch": "workspaces-run --parallel --only=\"dbgate-plugin-*\" -- yarn build:frontend:watch", "storage-json": "dbmodel model-to-json storage-db packages/api/src/storageModel.js --commonjs", "plugins:copydist": "workspaces-run --only=\"dbgate-plugin-*\" -- yarn copydist", diff --git a/yarn.lock b/yarn.lock index 97bc9f2e..acc569e5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10182,6 +10182,11 @@ tmp@^0.0.33: dependencies: os-tmpdir "~1.0.2" +tmp@^0.2.3: + version "0.2.3" + resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.3.tgz#eb783cc22bc1e8bebd0671476d46ea4eb32a79ae" + integrity sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w== + tmpl@1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.5.tgz#8683e0b902bb9c20c4f726e3c0b69f36518c07cc"