Skip to content

Commit 2d2fce0

Browse files
committed
Refactor and add tests
1 parent 07750b4 commit 2d2fce0

28 files changed

+1413
-1568
lines changed

test/binding.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ describe('4. binding.js', function() {
392392

393393
before(async function() {
394394
connection = await oracledb.getConnection(dbConfig);
395-
await assist.createTable(connection, tableName);
395+
await connection.execute(assist.sqlCreateTable(tableName));
396396
});
397397

398398
after(async function() {

test/dataTypeBinaryDouble.js

+52-64
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2022, Oracle and/or its affiliates. */
1+
/* Copyright (c) 2015, 2023, Oracle and/or its affiliates. */
22

33
/******************************************************************************
44
*
@@ -38,112 +38,100 @@ const dbConfig = require('./dbconfig.js');
3838

3939
describe('31. dataTypeBinaryDouble.js', function() {
4040

41-
var connection = null;
42-
var tableName = "nodb_double";
41+
let connection = null;
42+
let tableName = "nodb_double";
4343

44-
before('get one connection', function(done) {
45-
oracledb.getConnection(dbConfig,
46-
function(err, conn) {
47-
assert.ifError(err);
48-
connection = conn;
49-
done();
50-
}
51-
);
44+
before('get one connection', async function() {
45+
connection = await oracledb.getConnection(dbConfig);
5246
});
5347

54-
after('release connection', function(done) {
55-
connection.release(function(err) {
56-
assert.ifError(err);
57-
done();
58-
});
48+
after('release connection', async function() {
49+
await connection.close();
5950
});
6051

6152
describe('31.1 testing BINARY_DOUBLE data', function() {
6253

63-
var numbers = assist.data.numbersForBinaryFloat.concat(assist.data.numbersForBinaryDouble);
54+
let numbers = assist.data.numbersForBinaryFloat.concat(assist.data.numbersForBinaryDouble);
6455

65-
before('create table, insert data', function(done) {
66-
assist.setUp(connection, tableName, numbers, done);
56+
before('create table, insert data', async function() {
57+
await new Promise((resolve) => {
58+
assist.setUp(connection, tableName, numbers, resolve);
59+
});
6760
});
6861

69-
after(function(done) {
62+
after(async function() {
7063
oracledb.fetchAsString = [];
71-
connection.execute(
72-
"DROP table " + tableName + " PURGE",
73-
function(err) {
74-
assert.ifError(err);
75-
done();
76-
}
77-
);
64+
await connection.execute(`DROP table ` + tableName + ` PURGE`);
7865
});
7966

80-
it('31.1.1 works well with SELECT query', function(done) {
81-
assist.dataTypeSupport(connection, tableName, numbers, done);
67+
it('31.1.1 works well with SELECT query', async function() {
68+
await new Promise((resolve) => {
69+
assist.dataTypeSupport(connection, tableName, numbers, resolve);
70+
});
8271
});
8372

84-
it('31.1.2 works well with result set', function(done) {
85-
assist.verifyResultSet(connection, tableName, numbers, done);
73+
it('31.1.2 works well with result set', async function() {
74+
await new Promise((resolve) => {
75+
assist.verifyResultSet(connection, tableName, numbers, resolve);
76+
});
8677
});
8778

88-
it('31.1.3 works well with REF Cursor', function(done) {
89-
assist.verifyRefCursor(connection, tableName, numbers, done);
79+
it('31.1.3 works well with REF Cursor', async function() {
80+
await new Promise((resolve) => {
81+
assist.verifyRefCursor(connection, tableName, numbers, resolve);
82+
});
9083
});
9184

92-
it('31.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', function(done) {
93-
assist.verifyRefCursorWithFetchInfo(connection, tableName, numbers, done);
85+
it('31.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', async function() {
86+
await new Promise((resolve) => {
87+
assist.verifyRefCursorWithFetchInfo(connection, tableName, numbers, resolve);
88+
});
9489
});
9590

96-
it('31.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', function(done) {
91+
it('31.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', async function() {
9792
oracledb.fetchAsString = [ oracledb.NUMBER ];
98-
assist.verifyRefCursorWithFetchAsString(connection, tableName, numbers, done);
93+
await new Promise((resolve) => {
94+
assist.verifyRefCursorWithFetchAsString(connection, tableName, numbers, resolve);
95+
});
9996
});
10097

10198
});
10299

103100
describe('31.2 stores null value correctly', function() {
104-
it('31.2.1 testing Null, Empty string and Undefined', function(done) {
105-
assist.verifyNullValues(connection, tableName, done);
101+
it('31.2.1 testing Null, Empty string and Undefined', async function() {
102+
await new Promise((resolve) => {
103+
assist.verifyNullValues(connection, tableName, resolve);
104+
});
106105
});
107106
});
108107

109108
describe('31.3 testing floating-point numbers which can be precisely represent', function() {
110-
var nums =
109+
let nums =
111110
[
112111
0.0000000000000000000123,
113112
98.7654321
114113
];
115114

116-
before('create table, insert data', function(done) {
117-
assist.setUp(connection, tableName, nums, done);
115+
before('create table, insert data', async function() {
116+
await new Promise((resolve) => {
117+
assist.setUp(connection, tableName, nums, resolve);
118+
});
118119
});
119120

120-
after(function(done) {
121-
connection.execute(
122-
"DROP table " + tableName + " PURGE",
123-
function(err) {
124-
assert.ifError(err);
125-
done();
126-
}
127-
);
121+
after(async function() {
122+
await connection.execute(`DROP table ` + tableName + ` PURGE`);
128123
});
129124

130-
it('31.3.1 testing floating-point numbers', function(done) {
131-
connection.execute(
125+
it('31.3.1 testing floating-point numbers', async function() {
126+
let result = await connection.execute(
132127
"SELECT * FROM " + tableName,
133128
[],
134-
{ outFormat: oracledb.OUT_FORMAT_OBJECT },
135-
function(err, result) {
136-
assert.ifError(err);
137-
138-
for (var i = 0; i < nums.length; i++) {
139-
result.rows[i].CONTENT.should.be.exactly(nums[result.rows[i].NUM]);
140-
}
141-
done();
142-
}
143-
);
129+
{ outFormat: oracledb.OUT_FORMAT_OBJECT });
130+
131+
for (let i = 0; i < nums.length; i++) {
132+
assert.strictEqual(result.rows[i].CONTENT, nums[result.rows[i].NUM]);
133+
}
144134
});
145135

146136
}); // 31.3
147-
148-
149137
});

test/dataTypeBinaryFloat.js

+55-65
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2022, Oracle and/or its affiliates. */
1+
/* Copyright (c) 2015, 2023, Oracle and/or its affiliates. */
22

33
/******************************************************************************
44
*
@@ -38,116 +38,106 @@ const dbConfig = require('./dbconfig.js');
3838

3939
describe('30. dataTypeBinaryFloat.js', function() {
4040

41-
var connection = null;
42-
var tableName = "nodb_binary_float";
41+
let connection = null;
42+
let tableName = "nodb_binary_float";
4343

44-
before('get one connection', function(done) {
45-
oracledb.getConnection(dbConfig,
46-
function(err, conn) {
47-
assert.ifError(err);
48-
connection = conn;
49-
done();
50-
}
51-
);
44+
before('get one connection', async function() {
45+
connection = await oracledb.getConnection(dbConfig);
5246
});
5347

54-
after('release connection', function(done) {
55-
connection.release(function(err) {
56-
assert.ifError(err);
57-
done();
58-
});
48+
after('release connection', async function() {
49+
await connection.close();
5950
});
6051

6152
describe('30.1 testing BINARY_FLOAT data', function() {
6253

63-
var numbers = assist.data.numbersForBinaryFloat;
54+
let numbers = assist.data.numbersForBinaryFloat;
6455

65-
before('create table, insert data', function(done) {
66-
assist.setUp(connection, tableName, numbers, done);
56+
before('create table, insert data', async function() {
57+
await new Promise((resolve) => {
58+
assist.setUp(connection, tableName, numbers, resolve);
59+
});
6760
});
6861

69-
after(function(done) {
62+
after(async function() {
7063
oracledb.fetchAsString = [];
71-
connection.execute(
72-
"DROP table " + tableName + " PURGE",
73-
function(err) {
74-
assert.ifError(err);
75-
done();
76-
}
77-
);
64+
await connection.execute(`DROP table ` + tableName + ` PURGE`);
7865
});
7966

80-
it('30.1.1 works well with SELECT query', function(done) {
81-
assist.dataTypeSupport(connection, tableName, numbers, done);
67+
it('30.1.1 works well with SELECT query', async function() {
68+
await new Promise((resolve) => {
69+
assist.dataTypeSupport(connection, tableName, numbers, resolve);
70+
});
8271
});
8372

84-
it('30.1.2 works well with result set', function(done) {
85-
assist.verifyResultSet(connection, tableName, numbers, done);
73+
it('30.1.2 works well with result set', async function() {
74+
await new Promise((resolve) => {
75+
assist.verifyResultSet(connection, tableName, numbers, resolve);
76+
});
8677
});
8778

88-
it('30.1.3 works well with REF Cursor', function(done) {
89-
assist.verifyRefCursor(connection, tableName, numbers, done);
79+
it('30.1.3 works well with REF Cursor', async function() {
80+
await new Promise((resolve) => {
81+
assist.verifyRefCursor(connection, tableName, numbers, resolve);
82+
});
9083
});
9184

92-
it('30.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', function(done) {
93-
assist.verifyRefCursorWithFetchInfo(connection, tableName, numbers, done);
85+
it('30.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', async function() {
86+
await new Promise((resolve) => {
87+
assist.verifyRefCursorWithFetchInfo(connection, tableName, numbers, resolve);
88+
});
9489
});
9590

96-
it('30.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', function(done) {
91+
it('30.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', async function() {
9792
oracledb.fetchAsString = [ oracledb.NUMBER ];
98-
assist.verifyRefCursorWithFetchAsString(connection, tableName, numbers, done);
93+
await new Promise((resolve) => {
94+
assist.verifyRefCursorWithFetchAsString(connection, tableName, numbers, resolve);
95+
});
9996
});
10097

10198
}); // 30.1
10299

103100
describe('30.2 stores null value correctly', function() {
104-
it('30.2.1 testing Null, Empty string and Undefined', function(done) {
105-
assist.verifyNullValues(connection, tableName, done);
101+
it('30.2.1 testing Null, Empty string and Undefined', async function() {
102+
await new Promise((resolve) => {
103+
assist.verifyNullValues(connection, tableName, resolve);
104+
});
106105
});
107106
});
108107

109108
describe('30.3 testing floating-point numbers which cannot be precisely represent', function() {
110-
var nums =
109+
let nums =
111110
[
112111
2345.67,
113112
9876.54321,
114113
0.01234,
115114
0.00000123
116115
];
117116

118-
before('create table, insert data', function(done) {
119-
assist.setUp(connection, tableName, nums, done);
117+
before('create table, insert data', async function() {
118+
await new Promise((resolve) => {
119+
assist.setUp(connection, tableName, nums, resolve);
120+
});
120121
});
121122

122-
after(function(done) {
123-
connection.execute(
124-
"DROP table " + tableName + " PURGE",
125-
function(err) {
126-
assert.ifError(err);
127-
done();
128-
}
129-
);
123+
after(async function() {
124+
await connection.execute(`DROP table ` + tableName + ` PURGE`);
130125
});
131126

132-
it('30.3.1 rounding numbers', function(done) {
133-
connection.execute(
134-
"SELECT * FROM " + tableName,
127+
it('30.3.1 rounding numbers', async function() {
128+
let result = await connection.execute(
129+
`SELECT * FROM ` + tableName,
135130
[],
136-
{ outFormat: oracledb.OUT_FORMAT_OBJECT },
137-
function(err, result) {
138-
assert.ifError(err);
139-
140-
for (var i = 0; i < nums.length; i++) {
141-
result.rows[i].CONTENT.should.not.be.exactly(nums[result.rows[i].NUM]);
142-
approxeq(result.rows[i].CONTENT, nums[result.rows[i].NUM]).should.be.ok();
143-
}
144-
done();
145-
}
146-
);
131+
{ outFormat: oracledb.OUT_FORMAT_OBJECT });
132+
133+
for (let i = 0; i < nums.length; i++) {
134+
assert.notStrictEqual(result.rows[i].CONTENT, nums[result.rows[i].NUM]);
135+
assert(approxeq(result.rows[i].CONTENT, nums[result.rows[i].NUM]));
136+
}
147137
});
148138

149139
function approxeq(v1, v2) {
150-
var precision = 0.001;
140+
let precision = 0.001;
151141
return Math.abs(v1 - v2) < precision;
152142
}
153143
}); // 30.3

0 commit comments

Comments
 (0)