/
oracledb.js
109 lines (94 loc) · 2.73 KB
/
oracledb.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// global it, describe
'use strict';
const _ = require('lodash');
const expect = require('chai').expect;
const knex = require('../../../knex');
const config = require('../../knexfile');
const sinon = require('sinon');
describe('OracleDb externalAuth', function() {
const knexInstance = knex({
client: 'oracledb',
connection: {
user: 'user',
password: 'password',
connectString: 'connect-string',
externalAuth: true,
host: 'host',
database: 'database',
},
});
let spy;
before(function() {
spy = sinon.spy(knexInstance.client.driver, 'getConnection');
});
it('externalAuth and connectString should be sent to the getConnection', function() {
const connectionWithExternalAuth = {
connectString: 'connect-string',
externalAuth: true,
};
knexInstance.client
.acquireRawConnection()
.then(function(resolve) {}, function(reject) {});
expect(spy).to.have.callCount(1);
expect(spy).to.have.been.calledWith(connectionWithExternalAuth);
});
after(function() {
knexInstance.client.driver.getConnection.restore();
});
});
describe('OracleDb parameters', function() {
describe('with fetchAsString parameter ', function() {
let knexClient;
before(function() {
const conf = _.clone(config.oracledb);
conf.fetchAsString = ['number', 'DATE', 'cLOb'];
knexClient = knex(conf);
return knexClient;
});
it('on float', function() {
return knexClient
.raw('select 7.329 as "field" from dual')
.then(function(result) {
expect(result[0]).to.be.ok;
expect(result[0].field).to.be.a('string');
});
});
it('on date', function() {
return knexClient
.raw('select CURRENT_DATE as "field" from dual')
.then(function(result) {
expect(result[0]).to.be.ok;
expect(result[0].field).to.be.a('string');
});
});
after(function() {
return knexClient.destroy();
});
});
describe('without fetchAsString parameter', function() {
let knexClient;
before(function() {
knexClient = knex(config.oracledb);
return knexClient;
});
it('on float', function() {
return knexClient
.raw('select 7.329 as "field" from dual')
.then(function(result) {
expect(result[0]).to.be.ok;
expect(result[0].field).to.not.be.a('string');
});
});
it('on date', function() {
return knexClient
.raw('select CURRENT_DATE as "field" from dual')
.then(function(result) {
expect(result[0]).to.be.ok;
expect(result[0].field).to.not.be.a('string');
});
});
after(function() {
return knexClient.destroy();
});
});
});