3
3
const test = require ( 'tap' ) . test
4
4
const plugin = require ( '../plugin' )
5
5
6
- test ( 'creates usable pool from config' , ( t ) => {
6
+ test ( 'creates pool from config' , ( t ) => {
7
7
t . plan ( 6 )
8
8
9
9
const fastify = {
@@ -28,10 +28,59 @@ test('creates usable pool from config', (t) => {
28
28
t . ok ( fastify . oracle )
29
29
fastify . oracle . getConnection ( )
30
30
. then ( ( conn ) => {
31
- conn . execute ( 'select 1 from dual' )
31
+ conn . execute ( 'SELECT 1 AS FOO FROM DUAL' , { } , { outFormat : fastify . oracle . db . OBJECT } )
32
32
. then ( ( result ) => {
33
33
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 , / f a s t i f y \. o r a c l e \. p o o l \. c l o s e / )
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 )
35
84
} )
36
85
. then ( ( ) => conn . close ( ) )
37
86
. catch ( t . threw )
0 commit comments