Skip to content

Commit 1da8d95

Browse files
committed
Refactor and add tests
1 parent 472c828 commit 1da8d95

File tree

138 files changed

+1682
-2025
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+1682
-2025
lines changed

test/accessPropertiesOnClosedObjects.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434

3535
const oracledb = require('oracledb');
3636
const assert = require('assert');
37-
const dbconfig = require('./dbconfig.js');
37+
const dbConfig = require('./dbconfig.js');
3838

3939
describe('223. accessPropertiesOnClosedObjects.js', () => {
4040

4141
it('223.1 access properties of closed Connection object', async () => {
42-
const conn = await oracledb.getConnection(dbconfig);
42+
const conn = await oracledb.getConnection(dbConfig);
4343
assert(conn);
4444
await conn.close();
4545

@@ -48,7 +48,7 @@ describe('223. accessPropertiesOnClosedObjects.js', () => {
4848
}); // 223.1
4949

5050
it('223.2 access properties of closed Lob object', async () => {
51-
const conn = await oracledb.getConnection(dbconfig);
51+
const conn = await oracledb.getConnection(dbConfig);
5252

5353
const Lob = await conn.createLob(oracledb.DB_TYPE_BLOB);
5454

test/aq1.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
const oracledb = require('oracledb');
3636
const assert = require('assert');
37-
const dbconfig = require('./dbconfig.js');
37+
const dbConfig = require('./dbconfig.js');
3838
const testsUtil = require('./testsUtil.js');
3939

4040
describe('217. aq1.js', function() {
@@ -48,7 +48,7 @@ describe('217. aq1.js', function() {
4848
const RAW_TABLE = 'NODB_RAW_QUEUE_TAB';
4949

5050
before(async function() {
51-
if (!dbconfig.test.DBA_PRIVILEGE) {
51+
if (!dbConfig.test.DBA_PRIVILEGE) {
5252
isRunnable = false;
5353
}
5454

@@ -60,7 +60,7 @@ describe('217. aq1.js', function() {
6060
let credential = {
6161
user: AQ_USER,
6262
password: AQ_USER_PWD,
63-
connectString: dbconfig.connectString
63+
connectString: dbConfig.connectString
6464
};
6565
conn = await oracledb.getConnection(credential);
6666

test/aq2.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
'use strict';
3434

3535
const oracledb = require('oracledb');
36-
const dbconfig = require('./dbconfig.js');
36+
const dbConfig = require('./dbconfig.js');
3737
const testsUtil = require('./testsUtil.js');
3838
const assert = require('assert');
3939

@@ -50,7 +50,7 @@ describe('218. aq2.js', function() {
5050
const objTable = "NODB_TAB_ADDR";
5151

5252
before(async function() {
53-
if (!dbconfig.test.DBA_PRIVILEGE) {
53+
if (!dbConfig.test.DBA_PRIVILEGE) {
5454
isRunnable = false;
5555
}
5656

@@ -63,7 +63,7 @@ describe('218. aq2.js', function() {
6363
let credential = {
6464
user: AQ_USER,
6565
password: AQ_USER_PWD,
66-
connectString: dbconfig.connectString
66+
connectString: dbConfig.connectString
6767
};
6868
conn = await oracledb.getConnection(credential);
6969

test/aq3.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
const oracledb = require('oracledb');
3535
const assert = require('assert');
36-
const dbconfig = require('./dbconfig.js');
36+
const dbConfig = require('./dbconfig.js');
3737
const testsUtil = require('./testsUtil.js');
3838

3939
describe('219. aq3.js', function() {
@@ -47,7 +47,7 @@ describe('219. aq3.js', function() {
4747
const RAW_TABLE = 'NODB_RAW_QUEUE_TAB';
4848

4949
before(async function() {
50-
if (!dbconfig.test.DBA_PRIVILEGE) {
50+
if (!dbConfig.test.DBA_PRIVILEGE) {
5151
isRunnable = false;
5252
}
5353

@@ -60,7 +60,7 @@ describe('219. aq3.js', function() {
6060
let credential = {
6161
user: AQ_USER,
6262
password: AQ_USER_PWD,
63-
connectString: dbconfig.connectString
63+
connectString: dbConfig.connectString
6464
};
6565
conn = await oracledb.getConnection(credential);
6666

test/aq4.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
'use strict';
3333

3434
const oracledb = require('oracledb');
35-
const dbconfig = require('./dbconfig.js');
35+
const dbConfig = require('./dbconfig.js');
3636
const testsUtil = require('./testsUtil.js');
3737
const assert = require('assert');
3838

@@ -92,7 +92,7 @@ describe('267. aq4.js', function() {
9292
`;
9393

9494
before(async function() {
95-
if (!dbconfig.test.DBA_PRIVILEGE) {
95+
if (!dbConfig.test.DBA_PRIVILEGE) {
9696
this.skip();
9797
return;
9898
}
@@ -102,7 +102,7 @@ describe('267. aq4.js', function() {
102102
const credential = {
103103
user: AQ_USER,
104104
password: AQ_USER_PWD,
105-
connectString: dbconfig.connectString
105+
connectString: dbConfig.connectString
106106
};
107107
conn = await oracledb.getConnection(credential);
108108

@@ -112,7 +112,7 @@ describe('267. aq4.js', function() {
112112

113113

114114
after(async function() {
115-
if (!dbconfig.test.DBA_PRIVILEGE)
115+
if (!dbConfig.test.DBA_PRIVILEGE)
116116
return;
117117

118118
if (conn)

test/asyncStack.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
const oracledb = require('oracledb');
3535
const assert = require('assert');
36+
const dbConfig = require('./dbconfig.js');
3637

3738
const asyncMiddleware = async () => {
3839
await oracledb.getConnection({connectString: 'doesnotexist.oracle.com'});
@@ -44,8 +45,8 @@ describe('263. asyncStack.js', () => {
4445
await assert.rejects(
4546
async () => await asyncMiddleware(),
4647
(e) => {
47-
assert.ok(e.stack.includes('asyncStack.js:38:'), e.stack);
48-
assert.ok(e.stack.includes('asyncStack.js:45:'), e.stack);
48+
assert.ok(e.stack.includes('asyncStack.js:39:'), e.stack);
49+
assert.ok(e.stack.includes('asyncStack.js:46:'), e.stack);
4950
return true;
5051
}
5152
);
@@ -63,23 +64,18 @@ describe('263. asyncStack.js', () => {
6364
await assert.rejects(
6465
async () => await oracledb.createPool(config),
6566
(e) => {
66-
assert.ok(e.stack.includes('asyncStack.js:64:'), e.stack);
67+
assert.ok(e.stack.includes('asyncStack.js:65:'), e.stack);
6768
return true;
6869
}
6970
);
7071
});
7172

7273
it('263.3 stack on error in execute', async () => {
73-
const config = {
74-
user : process.env.NODE_ORACLEDB_USER,
75-
password : process.env.NODE_ORACLEDB_PASSWORD,
76-
connectString : process.env.NODE_ORACLEDB_CONNECTIONSTRING
77-
};
78-
const conn = await oracledb.getConnection(config);
74+
const conn = await oracledb.getConnection(dbConfig);
7975
await assert.rejects(
8076
async () => await conn.execute("SELECT * FROM NON_EXISTENT_TABLE"),
8177
(e) => {
82-
assert.ok(e.stack.includes('asyncStack.js:80:'), e.stack);
78+
assert.ok(e.stack.includes('asyncStack.js:75:'), e.stack);
8379
return true;
8480
}
8581
);

test/autoCommit.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ describe('7. autoCommit.js', function() {
6262

6363
pool = await oracledb.createPool(
6464
{
65-
user : dbConfig.user,
66-
password : dbConfig.password,
67-
connectString : dbConfig.connectString,
65+
...dbConfig,
6866
poolMin : 3,
6967
poolMax : 7,
7068
poolIncrement : 1

test/autoCommit4nestedExecutes.js

+35-40
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ const dbConfig = require('./dbconfig.js');
4242

4343
describe('63. autoCommit4nestedExecutes.js', function() {
4444

45-
let tableName = "nodb_issue269tab";
46-
let procName = "issue269proc";
47-
let connection = null;
45+
const tableName = "nodb_issue269tab";
46+
const procName = "issue269proc";
47+
let connection;
4848

4949
before('prepare table and procedure', async function() {
5050

51-
let sqlCreateTab =
51+
const sqlCreateTab =
5252
" BEGIN "
5353
+ " DECLARE "
5454
+ " e_table_missing EXCEPTION; "
@@ -67,7 +67,7 @@ describe('63. autoCommit4nestedExecutes.js', function() {
6767
+ " '); "
6868
+ " END; ";
6969

70-
let sqlCreateProc =
70+
const sqlCreateProc =
7171
" CREATE OR REPLACE PROCEDURE " + procName + "(p_iname IN VARCHAR2, "
7272
+ " p_short_name IN VARCHAR2, p_comments IN VARCHAR2, p_new_id OUT NUMBER, p_status OUT NUMBER, "
7373
+ " p_description OUT VARCHAR2) "
@@ -93,17 +93,13 @@ describe('63. autoCommit4nestedExecutes.js', function() {
9393

9494
it('63.1 nested execute() functions', async function() {
9595

96-
let pool = null,
97-
conn = null;
98-
let result = null;
99-
10096
// sql will be the same for both execute calls
101-
let procSql = "BEGIN " + procName + "(p_iname=>:p_iname, p_short_name=>:p_short_name, "
97+
const procSql = "BEGIN " + procName + "(p_iname=>:p_iname, p_short_name=>:p_short_name, "
10298
+ " p_comments=>:p_comments, p_new_id=>:p_new_id, p_status=>:p_status, "
10399
+ " p_description=>:p_description); END;";
104100

105-
pool = await oracledb.createPool(dbConfig);
106-
conn = await pool.getConnection();
101+
const pool = await oracledb.createPool(dbConfig);
102+
const conn = await pool.getConnection();
107103

108104
await conn.execute(
109105
procSql,
@@ -126,41 +122,40 @@ describe('63. autoCommit4nestedExecutes.js', function() {
126122
},
127123
{ autoCommit: false });
128124

129-
130-
try {
131-
result = await conn.execute(
132-
procSql,
133-
{
134-
p_iname123: "Test iname", // specify wrong bind parameter name to cause an error
135-
p_short_name: "TST",
136-
p_comments: "Test comments",
137-
p_new_id: {
138-
type: oracledb.NUMBER,
139-
dir: oracledb.BIND_OUT
140-
},
141-
p_status: {
142-
type: oracledb.NUMBER,
143-
dir: oracledb.BIND_OUT
144-
},
145-
p_description: {
146-
type: oracledb.STRING,
147-
dir: oracledb.BIND_OUT
148-
}
149-
},
150-
{ autoCommit: false });
151-
} catch (err) {
152-
assert(err);
153-
// ORA-01036: illegal variable name/number
154-
assert.equal(err.message.substring(0, err.message.indexOf(':')), `ORA-01036`);
155-
}
125+
const binds = {
126+
p_iname123: "Test iname", // specify wrong bind parameter name to cause an error
127+
p_short_name: "TST",
128+
p_comments: "Test comments",
129+
p_new_id: {
130+
type: oracledb.NUMBER,
131+
dir: oracledb.BIND_OUT
132+
},
133+
p_status: {
134+
type: oracledb.NUMBER,
135+
dir: oracledb.BIND_OUT
136+
},
137+
p_description: {
138+
type: oracledb.STRING,
139+
dir: oracledb.BIND_OUT
140+
}
141+
};
142+
const options = {
143+
autoCommit: false
144+
};
145+
await assert.rejects(
146+
async () => await conn.execute(procSql, binds, options),
147+
/ORA-01036:/
148+
);
156149

157150
await conn.release();
158151
await pool.terminate();
159152

160-
result = await connection.execute(
153+
const result = await connection.execute(
161154
"SELECT count(*) as amount FROM " + tableName,
162155
[],
163156
{ outFormat: oracledb.OUT_FORMAT_OBJECT });
164157
assert.strictEqual(result.rows[0].AMOUNT, 0);
158+
165159
});
160+
166161
});

test/autoCommitForSelect.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,8 @@ describe('8. autoCommitForSelect.js', function() {
7070
END; ";
7171

7272
before(async function() {
73-
connection = await oracledb.getConnection(
74-
{
75-
user: dbConfig.user,
76-
password: dbConfig.password,
77-
connectString: dbConfig.connectString
78-
});
79-
anotherConnection = await oracledb.getConnection(
80-
{
81-
user: dbConfig.user,
82-
password: dbConfig.password,
83-
connectString: dbConfig.connectString
84-
});
73+
connection = await oracledb.getConnection(dbConfig);
74+
anotherConnection = await oracledb.getConnection(dbConfig);
8575
});
8676

8777
after(async function() {

0 commit comments

Comments
 (0)