Skip to content

Commit 89f38f4

Browse files
authored
Merge pull request #12 from cemremengu/more-tests
Added more tests
2 parents 9975351 + e3a0959 commit 89f38f4

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

test/client.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const oracledb = require('oracledb')
55
const plugin = require('../plugin')
66

77
test('accepts singleton client', (t) => {
8-
t.plan(4)
8+
t.plan(5)
99
oracledb.createPool({
1010
user: 'travis',
1111
password: 'travis',
@@ -15,6 +15,7 @@ test('accepts singleton client', (t) => {
1515
const fastify = {
1616
decorate (name, obj) {
1717
t.is(name, 'oracle')
18+
t.is(obj.db, oracledb)
1819
t.is(obj.pool, pool)
1920
},
2021

@@ -32,7 +33,7 @@ test('accepts singleton client', (t) => {
3233
})
3334

3435
test('retrieves a cached pool', (t) => {
35-
t.plan(4)
36+
t.plan(5)
3637
oracledb.createPool({
3738
user: 'travis',
3839
password: 'travis',
@@ -43,6 +44,7 @@ test('retrieves a cached pool', (t) => {
4344
const fastify = {
4445
decorate (name, obj) {
4546
t.is(name, 'oracle')
47+
t.is(obj.db, oracledb)
4648
t.is(obj.pool, pool)
4749
},
4850

test/pool.test.js

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const test = require('tap').test
44
const plugin = require('../plugin')
55

6-
test('creates usable pool from config', (t) => {
6+
test('creates pool from config', (t) => {
77
t.plan(6)
88

99
const fastify = {
@@ -28,10 +28,59 @@ test('creates usable pool from config', (t) => {
2828
t.ok(fastify.oracle)
2929
fastify.oracle.getConnection()
3030
.then((conn) => {
31-
conn.execute('select 1 from dual')
31+
conn.execute('SELECT 1 AS FOO FROM DUAL', { }, { outFormat: fastify.oracle.db.OBJECT })
3232
.then((result) => {
3333
t.is(result.rows.length, 1)
34-
t.is(result.rows[0][0], 1)
34+
t.is(result.rows[0].FOO, 1)
35+
})
36+
.then(() => conn.close())
37+
.catch(t.threw)
38+
})
39+
.catch(t.threw)
40+
})
41+
})
42+
43+
test('creates named pool from config', (t) => {
44+
t.plan(8)
45+
46+
const fastify = {
47+
decorate (name, obj) {
48+
t.is(name, 'oracle')
49+
this[name] = obj
50+
},
51+
52+
addHook (name, fn) {
53+
t.is(name, 'onClose')
54+
t.match(fn, /fastify\.oracle\.pool\.close/)
55+
}
56+
}
57+
58+
const opts = {
59+
user: 'travis',
60+
password: 'travis',
61+
connectString: 'localhost/xe'
62+
}
63+
plugin(fastify, { pool: opts, name: 'testdb' }, (err) => {
64+
if (err) t.threw(err)
65+
t.ok(fastify.oracle)
66+
fastify.oracle.getConnection()
67+
.then((conn) => {
68+
conn.execute('SELECT 1 AS FOO FROM DUAL', { }, { outFormat: fastify.oracle.db.OBJECT })
69+
.then((result) => {
70+
t.is(result.rows.length, 1)
71+
t.is(result.rows[0].FOO, 1)
72+
})
73+
.then(() => conn.close())
74+
.catch(t.threw)
75+
})
76+
.catch(t.threw)
77+
78+
fastify.oracle.testdb.getConnection()
79+
.then((conn) => {
80+
conn.execute('SELECT 1 AS FOO FROM DUAL', { }, { outFormat: fastify.oracle.db.OBJECT })
81+
.then((result) => {
82+
t.is(result.rows.length, 1)
83+
t.is(result.rows[0].FOO, 1)
3584
})
3685
.then(() => conn.close())
3786
.catch(t.threw)

0 commit comments

Comments
 (0)