@natlibfi/oracledb-mock 1.0.1 → 1.0.2-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _deepEql = _interopRequireDefault(require("deep-eql"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ /**
10
+ *
11
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
12
+ *
13
+ * A mock for oracledb Node.js module
14
+ *
15
+ * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
16
+ *
17
+ * This file is part of oracledb-mock-js
18
+ *
19
+ * oracledb-mock-js program is free software: you can redistribute it and/or modify
20
+ * it under the terms of the GNU Affero General Public License as
21
+ * published by the Free Software Foundation, either version 3 of the
22
+ * License, or (at your option) any later version.
23
+ *
24
+ * oracledb-mock-js is distributed in the hope that it will be useful,
25
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
+ * GNU Affero General Public License for more details.
28
+ *
29
+ * You should have received a copy of the GNU Affero General Public License
30
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
31
+ *
32
+ * @licend The above is the entire license notice
33
+ * for the JavaScript code in this file.
34
+ *
35
+ */
36
+ var _default = () => {
37
+ const options = [];
38
+ const DEFAULT_OPTIONS = {
39
+ queryPattern: /.*/u,
40
+ results: []
41
+ };
42
+ const connection = {
43
+ close: () => {},
44
+ // eslint-disable-line no-empty-function
45
+ break: () => {},
46
+ // eslint-disable-line no-empty-function
47
+ execute: (query, args) => {
48
+ const rows = getRows();
49
+ return {
50
+ resultSet: {
51
+ getRow: () => rows.shift(),
52
+ // eslint-disable-line functional/immutable-data
53
+ close: () => {} // eslint-disable-line no-empty-function
54
+ }
55
+ };
56
+
57
+ function getRows() {
58
+ const index = options.findIndex(({
59
+ queryPattern,
60
+ expectedArgs
61
+ }) => {
62
+ if (queryPattern.test(query) && (expectedArgs === undefined || (0, _deepEql.default)(args, expectedArgs))) {
63
+ return true;
64
+ }
65
+ return false;
66
+ });
67
+ if (index >= 0) {
68
+ const {
69
+ results
70
+ } = options.splice(index, 1).shift(); // eslint-disable-line functional/immutable-data
71
+ return results;
72
+ }
73
+ return [];
74
+ }
75
+ }
76
+ };
77
+ return {
78
+ getConnection: () => connection,
79
+ createPool: () => ({
80
+ getConnection: () => connection,
81
+ close: () => {} // eslint-disable-line no-empty-function
82
+ }),
83
+
84
+ _clear: () => {
85
+ // Clear array
86
+ options.splice(0); // eslint-disable-line functional/immutable-data
87
+ Object.keys(options).forEach(k => delete options[k]); // eslint-disable-line functional/immutable-data
88
+ },
89
+
90
+ _execute: optList => {
91
+ // Clear array
92
+ options.splice(0); // eslint-disable-line functional/immutable-data
93
+
94
+ optList.forEach(opts => {
95
+ options.push({
96
+ ...DEFAULT_OPTIONS,
97
+ ...opts
98
+ }); // eslint-disable-line functional/immutable-data
99
+ });
100
+ }
101
+ };
102
+ };
103
+ exports.default = _default;
104
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_deepEql","_interopRequireDefault","require","obj","__esModule","default","_default","options","DEFAULT_OPTIONS","queryPattern","results","connection","close","break","execute","query","args","rows","getRows","resultSet","getRow","shift","index","findIndex","expectedArgs","test","undefined","deepEqual","splice","getConnection","createPool","_clear","Object","keys","forEach","k","_execute","optList","opts","push","exports"],"sources":["../src/index.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* A mock for oracledb Node.js module\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of oracledb-mock-js\n*\n* oracledb-mock-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* oracledb-mock-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport deepEqual from 'deep-eql';\n\nexport default () => {\n const options = [];\n const DEFAULT_OPTIONS = {\n queryPattern: /.*/u,\n results: []\n };\n\n const connection = {\n close: () => {}, // eslint-disable-line no-empty-function\n break: () => {}, // eslint-disable-line no-empty-function\n execute: (query, args) => {\n const rows = getRows();\n\n return {\n resultSet: {\n getRow: () => rows.shift(), // eslint-disable-line functional/immutable-data\n close: () => {} // eslint-disable-line no-empty-function\n }\n };\n\n function getRows() {\n const index = options.findIndex(({queryPattern, expectedArgs}) => {\n if (queryPattern.test(query) && (expectedArgs === undefined || deepEqual(args, expectedArgs))) {\n return true;\n }\n\n return false;\n });\n\n if (index >= 0) {\n const {results} = options.splice(index, 1).shift(); // eslint-disable-line functional/immutable-data\n return results;\n }\n\n return [];\n }\n }\n };\n\n return {\n getConnection: () => connection,\n createPool: () => ({\n getConnection: () => connection,\n close: () => {} // eslint-disable-line no-empty-function\n }),\n _clear: () => {\n // Clear array\n options.splice(0); // eslint-disable-line functional/immutable-data\n Object.keys(options).forEach(k => delete options[k]); // eslint-disable-line functional/immutable-data\n },\n _execute: optList => {\n // Clear array\n options.splice(0); // eslint-disable-line functional/immutable-data\n\n optList.forEach(opts => {\n options.push({...DEFAULT_OPTIONS, ...opts}); // eslint-disable-line functional/immutable-data\n });\n }\n };\n};\n"],"mappings":";;;;;;AA4BA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAiC,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,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A,OAAO,EAAE;MACX;IACF;EACF,CAAC;EAED,OAAO;IACLmB,aAAa,EAAEA,CAAA,KAAMlB,UAAU;IAC/BmB,UAAU,EAAEA,CAAA,MAAO;MACjBD,aAAa,EAAEA,CAAA,KAAMlB,UAAU;MAC/BC,KAAK,EAAEA,CAAA,KAAM,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC;;IACFmB,MAAM,EAAEA,CAAA,KAAM;MACZ;MACAxB,OAAO,CAACqB,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;MACnBI,MAAM,CAACC,IAAI,CAAC1B,OAAO,CAAC,CAAC2B,OAAO,CAACC,CAAC,IAAI,OAAO5B,OAAO,CAAC4B,CAAC,CAAC,CAAC,CAAC,CAAC;IACxD,CAAC;;IACDC,QAAQ,EAAEC,OAAO,IAAI;MACnB;MACA9B,OAAO,CAACqB,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;;MAEnBS,OAAO,CAACH,OAAO,CAACI,IAAI,IAAI;QACtB/B,OAAO,CAACgC,IAAI,CAAC;UAAC,GAAG/B,eAAe;UAAE,GAAG8B;QAAI,CAAC,CAAC,CAAC,CAAC;MAC/C,CAAC,CAAC;IACJ;EACF,CAAC;AACH,CAAC;AAAAE,OAAA,CAAAnC,OAAA,GAAAC,QAAA"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+
3
+ var _ = _interopRequireDefault(require("."));
4
+ var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
5
+ var _chai = require("chai");
6
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
+ /**
8
+ *
9
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
10
+ *
11
+ * A mock for oracledb Node.js module
12
+ *
13
+ * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
14
+ *
15
+ * This file is part of oracledb-mock-js
16
+ *
17
+ * oracledb-mock-js program is free software: you can redistribute it and/or modify
18
+ * it under the terms of the GNU Affero General Public License as
19
+ * published by the Free Software Foundation, either version 3 of the
20
+ * License, or (at your option) any later version.
21
+ *
22
+ * oracledb-mock-js is distributed in the hope that it will be useful,
23
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
+ * GNU Affero General Public License for more details.
26
+ *
27
+ * You should have received a copy of the GNU Affero General Public License
28
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
29
+ *
30
+ * @licend The above is the entire license notice
31
+ * for the JavaScript code in this file.
32
+ *
33
+ */
34
+
35
+ (0, _fixugen.default)({
36
+ useMetadataFile: true,
37
+ path: [__dirname, '..', 'test-fixtures'],
38
+ callback: async ({
39
+ dbResults,
40
+ usePool = false,
41
+ expectedResults,
42
+ query,
43
+ args = {}
44
+ }) => {
45
+ const mock = (0, _.default)();
46
+ mock._execute(formatDbResults());
47
+ if (usePool) {
48
+ const pool = await mock.createPool();
49
+ const connection = await pool.getConnection();
50
+ const {
51
+ resultSet
52
+ } = await connection.execute(query, args);
53
+ const results = await fetchResults(resultSet);
54
+ (0, _chai.expect)(results).to.eql(expectedResults);
55
+ await connection.close();
56
+ await pool.close();
57
+ mock._clear();
58
+ return;
59
+ }
60
+ const connection = await mock.getConnection();
61
+ const {
62
+ resultSet
63
+ } = await connection.execute(query, args);
64
+ const results = await fetchResults(resultSet);
65
+ (0, _chai.expect)(results).to.eql(expectedResults);
66
+ await connection.close();
67
+ mock._clear();
68
+ async function fetchResults(resultSet, results = []) {
69
+ const row = await resultSet.getRow();
70
+ if (row) {
71
+ return fetchResults(resultSet, results.concat(row));
72
+ }
73
+ await resultSet.close();
74
+ return results;
75
+ }
76
+ function formatDbResults() {
77
+ return dbResults.map(({
78
+ queryPattern,
79
+ ...rest
80
+ }) => {
81
+ if (queryPattern) {
82
+ return {
83
+ ...rest,
84
+ queryPattern: new RegExp(queryPattern, 'u')
85
+ };
86
+ }
87
+ return rest;
88
+ });
89
+ }
90
+ }
91
+ });
92
+ //# sourceMappingURL=index.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.spec.js","names":["_","_interopRequireDefault","require","_fixugen","_chai","obj","__esModule","default","generateTests","useMetadataFile","path","__dirname","callback","dbResults","usePool","expectedResults","query","args","mock","createMock","_execute","formatDbResults","pool","createPool","connection","getConnection","resultSet","execute","results","fetchResults","expect","to","eql","close","_clear","row","getRow","concat","map","queryPattern","rest","RegExp"],"sources":["../src/index.spec.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* A mock for oracledb Node.js module\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of oracledb-mock-js\n*\n* oracledb-mock-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* oracledb-mock-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport createMock from '.';\nimport generateTests from '@natlibfi/fixugen';\nimport {expect} from 'chai';\n\ngenerateTests({\n useMetadataFile: true,\n path: [__dirname, '..', 'test-fixtures'],\n callback: async ({dbResults, usePool = false, expectedResults, query, args = {}}) => {\n const mock = createMock();\n\n mock._execute(formatDbResults());\n\n if (usePool) {\n const pool = await mock.createPool();\n const connection = await pool.getConnection();\n const {resultSet} = await connection.execute(query, args);\n const results = await fetchResults(resultSet);\n\n expect(results).to.eql(expectedResults);\n\n await connection.close();\n await pool.close();\n\n mock._clear();\n return;\n }\n\n const connection = await mock.getConnection();\n const {resultSet} = await connection.execute(query, args);\n const results = await fetchResults(resultSet);\n\n expect(results).to.eql(expectedResults);\n\n await connection.close();\n mock._clear();\n\n async function fetchResults(resultSet, results = []) {\n const row = await resultSet.getRow();\n\n if (row) {\n return fetchResults(resultSet, results.concat(row));\n }\n\n await resultSet.close();\n return results;\n }\n\n function formatDbResults() {\n return dbResults.map(({queryPattern, ...rest}) => {\n if (queryPattern) {\n return {\n ...rest,\n queryPattern: new RegExp(queryPattern, 'u')\n };\n }\n\n return rest;\n });\n }\n }\n});\n"],"mappings":";;AA4BA,IAAAA,CAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAA4B,SAAAD,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AA9B5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA,IAAAG,gBAAa,EAAC;EACZC,eAAe,EAAE,IAAI;EACrBC,IAAI,EAAE,CAACC,SAAS,EAAE,IAAI,EAAE,eAAe,CAAC;EACxCC,QAAQ,EAAE,MAAAA,CAAO;IAACC,SAAS;IAAEC,OAAO,GAAG,KAAK;IAAEC,eAAe;IAAEC,KAAK;IAAEC,IAAI,GAAG,CAAC;EAAC,CAAC,KAAK;IACnF,MAAMC,IAAI,GAAG,IAAAC,SAAU,EAAC,CAAC;IAEzBD,IAAI,CAACE,QAAQ,CAACC,eAAe,CAAC,CAAC,CAAC;IAEhC,IAAIP,OAAO,EAAE;MACX,MAAMQ,IAAI,GAAG,MAAMJ,IAAI,CAACK,UAAU,CAAC,CAAC;MACpC,MAAMC,UAAU,GAAG,MAAMF,IAAI,CAACG,aAAa,CAAC,CAAC;MAC7C,MAAM;QAACC;MAAS,CAAC,GAAG,MAAMF,UAAU,CAACG,OAAO,CAACX,KAAK,EAAEC,IAAI,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,CAAC,CAAC;IACJ;EACF;AACF,CAAC,CAAC"}
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "url": "git@github.com:natlibfi/oracledb-mock-js.git"
15
15
  },
16
16
  "license": "LGPL-3.0+",
17
- "version": "1.0.1",
17
+ "version": "1.0.2-alpha.1",
18
18
  "main": "./dist/index.js",
19
19
  "engines": {
20
20
  "node": ">=12"
@@ -23,6 +23,7 @@
23
23
  "access": "public"
24
24
  },
25
25
  "scripts": {
26
+ "prepare": "npm run build",
26
27
  "lint": "eslint src",
27
28
  "lint:dev": "eslint --fix src",
28
29
  "test:base": "cross-env NODE_ENV=test nyc mocha --require @babel/register",