Skip to content

Commit 76a1108

Browse files
committed
More tests and examples to improve code coverage
1 parent 1950872 commit 76a1108

File tree

13 files changed

+328
-222
lines changed

13 files changed

+328
-222
lines changed

examples/plsqlrowtype.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ async function run() {
6464
let conn;
6565
const table = 'STAFF';
6666
const stmts = [
67+
`DROP TABLE ${table} PURGE`,
68+
6769
`CREATE TABLE ${table} (ID NUMBER, NAME VARCHAR2(25), AGE NUMBER(3) INVISIBLE)`,
6870

6971
`INSERT INTO ${table} VALUES (1, 'ADSA')`,
@@ -91,10 +93,17 @@ async function run() {
9193
try {
9294
conn = await oracledb.getConnection(dbConfig);
9395
for (const s of stmts) {
94-
await conn.execute(s);
96+
try {
97+
await conn.execute(s);
98+
} catch (e) {
99+
if (e.errorNum != 942)
100+
console.error(e);
101+
}
95102
}
96103
const objClass = await conn.getDbObjectClass("FOO_TEST.FOO_TMP_ARRAY");
97-
const result = await conn.execute(`CALL FOO_TEST.prGetRecords(:out_rec)`, {out_rec: {type: objClass, dir: oracledb.BIND_OUT}});
104+
const result = await conn.execute(`CALL FOO_TEST.prGetRecords(:out_rec)`,
105+
{ out_rec: { type: objClass, dir: oracledb.BIND_OUT } });
106+
98107
for (const val of result.outBinds.out_rec) {
99108
console.log("\nRow contents:");
100109
console.log(val);

examples/soda1.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ async function run() {
126126
content = doc.getContentAsString(); // A JSON string
127127
console.log('Retrieved SODA document as a string:');
128128
console.log(content);
129+
content = doc.getContentAsBuffer(); // A Buffer
130+
console.log('Retrieved SODA document as a buffer:');
131+
console.log(content);
132+
console.log('SODA Document Version:', doc.version);
129133

130134
// Replace document contents
131135
content = {name: "Matilda", address: {city: "Sydney"}};

test/binding.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2023, Oracle and/or its affiliates. */
1+
/* Copyright (c) 2015, 2024, Oracle and/or its affiliates. */
22

33
/******************************************************************************
44
*
@@ -72,8 +72,6 @@ describe('4. binding.js', function() {
7272
{ type: oracledb.STRING, dir: oracledb.BIND_OUT }
7373
]);
7474

75-
// console.log(result);
76-
7775
assert.deepStrictEqual(result.outBinds, ['abcdef']);
7876
await connection.execute("DROP PROCEDURE nodb_bindproc1");
7977

@@ -276,7 +274,8 @@ describe('4. binding.js', function() {
276274
{sql: 'insert into nodb_binding1 (id, name) values (:1, :2) returning ( id + 2 )into :3', rowsAffected: 1, resultVal: [[3]]},
277275
{sql: 'insert into nodb_binding1 (id, name) values (:1, :2) returning ( id + 2 + 5)into :3', rowsAffected: 1, resultVal: [[8]]},
278276
{sql: 'insert into nodb_binding1 (id, name) values (:1, :2) returning ( id * 2 )into :3', rowsAffected: 1, resultVal: [[2]]},
279-
{sql: 'insert into nodb_binding1 (id, name) values (:1, :2)returning ( id * 2 )into :3', rowsAffected: 1, resultVal: [[2]]}
277+
{sql: 'insert into nodb_binding1 (id, name) values (:1, :2)returning ( id * 2 )into :3', rowsAffected: 1, resultVal: [[2]]},
278+
{sql: 'insert into nodb_binding1 (id, name) values (: 1, : 2)returning ( id * 2 )into :3', rowsAffected: 1, resultVal: [[2]]}
280279
];
281280
for (const sqlObj of sqlStrings) {
282281
const result = await connection.execute(sqlObj.sql, bindsOutNumber);

test/connection.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,13 @@ describe('1. connection.js', function() {
7171
'); \
7272
END; ";
7373

74+
const commentSQL = "COMMENT ON TABLE nodb_conn_dept1 IS \
75+
'This is a table with information about various departments'";
76+
7477
before(async function() {
7578
connection = await oracledb.getConnection(dbConfig);
7679
await connection.execute(script);
80+
await connection.execute(commentSQL);
7781
});
7882

7983
after(async function() {

test/dataTypeXML.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ describe('181. dataTypeXML.js', function() {
157157
assert.strictEqual(result.rows[0].MYCONTENT, testXMLData);
158158
}); // 181.3
159159

160-
it('181.4 Negative - try to insert Null', async () => {
160+
it('181.4 Negative - try to insert empty XML', async () => {
161161
const ID = 20;
162162
const XML = '';
163163

test/dbObject5.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019, 2023, Oracle and/or its affiliates. */
1+
/* Copyright (c) 2019, 2024, Oracle and/or its affiliates. */
22

33
/******************************************************************************
44
*
@@ -26,7 +26,7 @@
2626
* 204. dbObject5.js
2727
*
2828
* DESCRIPTION
29-
* Test the Oracle data type Object on TIMESTAMP WITH LOCAL TIME ZONE.
29+
* Test the Oracle data type Object on DATE.
3030
*
3131
*****************************************************************************/
3232
'use strict';
@@ -42,7 +42,8 @@ describe('204. dbObject5.js', () => {
4242
const TABLE = 'NODB_TAB_OBJ4';
4343

4444
const proc1 =
45-
`create or replace procedure nodb_getDataCursor1(p_cur out sys_refcursor) is begin
45+
`create or replace procedure nodb_getDataCursor1(p_cur out sys_refcursor) is
46+
begin
4647
open p_cur for
4748
SELECT
4849
* FROM

test/dbconfig.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ const config = {
6060

6161
let counter = 0;
6262

63+
if (process.env.NODE_ORACLEDB_DRIVER_MODE === 'thick') {
64+
config.test.mode = 'thick';
65+
console.log("Thick mode selected");
66+
oracledb.initOracleClient({ libDir: config.test.instantClientPath });
67+
} else {
68+
console.log("Thin mode selected");
69+
}
70+
6371
if (process.env.NODE_ORACLEDB_CONNECTIONSTRING) {
6472
config.connectString = process.env.NODE_ORACLEDB_CONNECTIONSTRING;
6573
} else {
@@ -148,14 +156,6 @@ if (process.env.NODE_ORACLEDB_CLIENT_LIB_DIR) {
148156
config.test.instantClientPath = process.env.NODE_ORACLEDB_CLIENT_LIB_DIR;
149157
}
150158

151-
if (process.env.NODE_ORACLEDB_DRIVER_MODE === 'thick') {
152-
config.test.mode = 'thick';
153-
console.log("Thick mode selected");
154-
oracledb.initOracleClient({ libDir: config.test.instantClientPath });
155-
} else {
156-
console.log("Thin mode selected");
157-
}
158-
159159
config.createUser = () => {
160160
++counter;
161161
return "NJS_" + counter.toString() + config.user;

0 commit comments

Comments
 (0)