Skip to content

Commit

Permalink
More tests and examples to improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadraju committed Dec 18, 2024
1 parent 1950872 commit 76a1108
Show file tree
Hide file tree
Showing 13 changed files with 328 additions and 222 deletions.
13 changes: 11 additions & 2 deletions examples/plsqlrowtype.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ async function run() {
let conn;
const table = 'STAFF';
const stmts = [
`DROP TABLE ${table} PURGE`,

`CREATE TABLE ${table} (ID NUMBER, NAME VARCHAR2(25), AGE NUMBER(3) INVISIBLE)`,

`INSERT INTO ${table} VALUES (1, 'ADSA')`,
Expand Down Expand Up @@ -91,10 +93,17 @@ async function run() {
try {
conn = await oracledb.getConnection(dbConfig);
for (const s of stmts) {
await conn.execute(s);
try {
await conn.execute(s);
} catch (e) {
if (e.errorNum != 942)
console.error(e);
}
}
const objClass = await conn.getDbObjectClass("FOO_TEST.FOO_TMP_ARRAY");
const result = await conn.execute(`CALL FOO_TEST.prGetRecords(:out_rec)`, {out_rec: {type: objClass, dir: oracledb.BIND_OUT}});
const result = await conn.execute(`CALL FOO_TEST.prGetRecords(:out_rec)`,
{ out_rec: { type: objClass, dir: oracledb.BIND_OUT } });

for (const val of result.outBinds.out_rec) {
console.log("\nRow contents:");
console.log(val);
Expand Down
4 changes: 4 additions & 0 deletions examples/soda1.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ async function run() {
content = doc.getContentAsString(); // A JSON string
console.log('Retrieved SODA document as a string:');
console.log(content);
content = doc.getContentAsBuffer(); // A Buffer
console.log('Retrieved SODA document as a buffer:');
console.log(content);
console.log('SODA Document Version:', doc.version);

// Replace document contents
content = {name: "Matilda", address: {city: "Sydney"}};
Expand Down
7 changes: 3 additions & 4 deletions test/binding.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2015, 2023, Oracle and/or its affiliates. */
/* Copyright (c) 2015, 2024, Oracle and/or its affiliates. */

/******************************************************************************
*
Expand Down Expand Up @@ -72,8 +72,6 @@ describe('4. binding.js', function() {
{ type: oracledb.STRING, dir: oracledb.BIND_OUT }
]);

// console.log(result);

assert.deepStrictEqual(result.outBinds, ['abcdef']);
await connection.execute("DROP PROCEDURE nodb_bindproc1");

Expand Down Expand Up @@ -276,7 +274,8 @@ describe('4. binding.js', function() {
{sql: 'insert into nodb_binding1 (id, name) values (:1, :2) returning ( id + 2 )into :3', rowsAffected: 1, resultVal: [[3]]},
{sql: 'insert into nodb_binding1 (id, name) values (:1, :2) returning ( id + 2 + 5)into :3', rowsAffected: 1, resultVal: [[8]]},
{sql: 'insert into nodb_binding1 (id, name) values (:1, :2) returning ( id * 2 )into :3', rowsAffected: 1, resultVal: [[2]]},
{sql: 'insert into nodb_binding1 (id, name) values (:1, :2)returning ( id * 2 )into :3', rowsAffected: 1, resultVal: [[2]]}
{sql: 'insert into nodb_binding1 (id, name) values (:1, :2)returning ( id * 2 )into :3', rowsAffected: 1, resultVal: [[2]]},
{sql: 'insert into nodb_binding1 (id, name) values (: 1, : 2)returning ( id * 2 )into :3', rowsAffected: 1, resultVal: [[2]]}
];
for (const sqlObj of sqlStrings) {
const result = await connection.execute(sqlObj.sql, bindsOutNumber);
Expand Down
4 changes: 4 additions & 0 deletions test/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@ describe('1. connection.js', function() {
'); \
END; ";

const commentSQL = "COMMENT ON TABLE nodb_conn_dept1 IS \
'This is a table with information about various departments'";

before(async function() {
connection = await oracledb.getConnection(dbConfig);
await connection.execute(script);
await connection.execute(commentSQL);
});

after(async function() {
Expand Down
2 changes: 1 addition & 1 deletion test/dataTypeXML.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe('181. dataTypeXML.js', function() {
assert.strictEqual(result.rows[0].MYCONTENT, testXMLData);
}); // 181.3

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

Expand Down
7 changes: 4 additions & 3 deletions test/dbObject5.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2019, 2023, Oracle and/or its affiliates. */
/* Copyright (c) 2019, 2024, Oracle and/or its affiliates. */

/******************************************************************************
*
Expand Down Expand Up @@ -26,7 +26,7 @@
* 204. dbObject5.js
*
* DESCRIPTION
* Test the Oracle data type Object on TIMESTAMP WITH LOCAL TIME ZONE.
* Test the Oracle data type Object on DATE.
*
*****************************************************************************/
'use strict';
Expand All @@ -42,7 +42,8 @@ describe('204. dbObject5.js', () => {
const TABLE = 'NODB_TAB_OBJ4';

const proc1 =
`create or replace procedure nodb_getDataCursor1(p_cur out sys_refcursor) is begin
`create or replace procedure nodb_getDataCursor1(p_cur out sys_refcursor) is
begin
open p_cur for
SELECT
* FROM
Expand Down
16 changes: 8 additions & 8 deletions test/dbconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ const config = {

let counter = 0;

if (process.env.NODE_ORACLEDB_DRIVER_MODE === 'thick') {
config.test.mode = 'thick';
console.log("Thick mode selected");
oracledb.initOracleClient({ libDir: config.test.instantClientPath });
} else {
console.log("Thin mode selected");
}

if (process.env.NODE_ORACLEDB_CONNECTIONSTRING) {
config.connectString = process.env.NODE_ORACLEDB_CONNECTIONSTRING;
} else {
Expand Down Expand Up @@ -148,14 +156,6 @@ if (process.env.NODE_ORACLEDB_CLIENT_LIB_DIR) {
config.test.instantClientPath = process.env.NODE_ORACLEDB_CLIENT_LIB_DIR;
}

if (process.env.NODE_ORACLEDB_DRIVER_MODE === 'thick') {
config.test.mode = 'thick';
console.log("Thick mode selected");
oracledb.initOracleClient({ libDir: config.test.instantClientPath });
} else {
console.log("Thin mode selected");
}

config.createUser = () => {
++counter;
return "NJS_" + counter.toString() + config.user;
Expand Down
Loading

0 comments on commit 76a1108

Please sign in to comment.