1
- 'use strict'
2
-
3
- const chai = require ( 'chai' )
1
+ import chai from 'chai'
4
2
const expect = chai . expect
5
3
chai . should ( )
6
4
7
- const { parse, toClientConfig, parseIntoClientConfig } = require ( '../' )
5
+ import { parse , toClientConfig , parseIntoClientConfig } from '../'
8
6
9
7
describe ( 'toClientConfig' , function ( ) {
10
8
it ( 'converts connection info' , function ( ) {
11
9
const config = parse ( 'postgres://brian:pw@boom:381/lala' )
12
10
const clientConfig = toClientConfig ( config )
13
11
14
- clientConfig . user . should . equal ( 'brian' )
15
- clientConfig . password . should . equal ( 'pw' )
16
- clientConfig . host . should . equal ( 'boom' )
17
- clientConfig . port . should . equal ( 381 )
18
- clientConfig . database . should . equal ( 'lala' )
12
+ clientConfig . user ? .should . equal ( 'brian' )
13
+ clientConfig . password ? .should . equal ( 'pw' )
14
+ clientConfig . host ? .should . equal ( 'boom' )
15
+ clientConfig . port ? .should . equal ( 381 )
16
+ clientConfig . database ? .should . equal ( 'lala' )
19
17
} )
20
18
21
19
it ( 'converts query params' , function ( ) {
@@ -24,45 +22,47 @@ describe('toClientConfig', function () {
24
22
)
25
23
const clientConfig = toClientConfig ( config )
26
24
27
- clientConfig . application_name . should . equal ( 'TheApp' )
28
- clientConfig . fallback_application_name . should . equal ( 'TheAppFallback' )
29
- clientConfig . client_encoding . should . equal ( 'utf8' )
30
- clientConfig . options . should . equal ( '-c geqo=off' )
25
+ clientConfig . application_name ? .should . equal ( 'TheApp' )
26
+ clientConfig . fallback_application_name ? .should . equal ( 'TheAppFallback' )
27
+ clientConfig . client_encoding ? .should . equal ( 'utf8' )
28
+ clientConfig . options ? .should . equal ( '-c geqo=off' )
31
29
} )
32
30
33
31
it ( 'converts SSL boolean' , function ( ) {
34
32
const config = parse ( 'pg:///?ssl=true' )
35
33
const clientConfig = toClientConfig ( config )
36
34
37
- clientConfig . ssl . should . equal ( true )
35
+ clientConfig . ssl ? .should . equal ( true )
38
36
} )
39
37
40
38
it ( 'converts sslmode=disable' , function ( ) {
41
39
const config = parse ( 'pg:///?sslmode=disable' )
42
40
const clientConfig = toClientConfig ( config )
43
41
44
- clientConfig . ssl . should . equal ( false )
42
+ clientConfig . ssl ? .should . equal ( false )
45
43
} )
46
44
47
45
it ( 'converts sslmode=noverify' , function ( ) {
48
46
const config = parse ( 'pg:///?sslmode=no-verify' )
49
47
const clientConfig = toClientConfig ( config )
50
48
51
- clientConfig . ssl . rejectUnauthorized . should . equal ( false )
49
+ clientConfig . ssl ?. should . deep . equal ( {
50
+ rejectUnauthorized : false ,
51
+ } )
52
52
} )
53
53
54
54
it ( 'converts other sslmode options' , function ( ) {
55
55
const config = parse ( 'pg:///?sslmode=verify-ca' )
56
56
const clientConfig = toClientConfig ( config )
57
57
58
- clientConfig . ssl . should . deep . equal ( { } )
58
+ clientConfig . ssl ? .should . deep . equal ( { } )
59
59
} )
60
60
61
61
it ( 'converts other sslmode options' , function ( ) {
62
62
const config = parse ( 'pg:///?sslmode=verify-ca' )
63
63
const clientConfig = toClientConfig ( config )
64
64
65
- clientConfig . ssl . should . deep . equal ( { } )
65
+ clientConfig . ssl ? .should . deep . equal ( { } )
66
66
} )
67
67
68
68
it ( 'converts ssl cert options' , function ( ) {
@@ -77,7 +77,7 @@ describe('toClientConfig', function () {
77
77
const config = parse ( connectionString )
78
78
const clientConfig = toClientConfig ( config )
79
79
80
- clientConfig . ssl . should . deep . equal ( {
80
+ clientConfig . ssl ? .should . deep . equal ( {
81
81
ca : 'example ca\n' ,
82
82
cert : 'example cert\n' ,
83
83
key : 'example key\n' ,
@@ -87,9 +87,9 @@ describe('toClientConfig', function () {
87
87
it ( 'converts unix domain sockets' , function ( ) {
88
88
const config = parse ( 'socket:/some path/?db=my[db]&encoding=utf8&client_encoding=bogus' )
89
89
const clientConfig = toClientConfig ( config )
90
- clientConfig . host . should . equal ( '/some path/' )
91
- clientConfig . database . should . equal ( 'my[db]' , 'must to be escaped and unescaped through "my%5Bdb%5D"' )
92
- clientConfig . client_encoding . should . equal ( 'utf8' )
90
+ clientConfig . host ? .should . equal ( '/some path/' )
91
+ clientConfig . database ? .should . equal ( 'my[db]' , 'must to be escaped and unescaped through "my%5Bdb%5D"' )
92
+ clientConfig . client_encoding ? .should . equal ( 'utf8' )
93
93
} )
94
94
95
95
it ( 'handles invalid port' , function ( ) {
@@ -106,20 +106,20 @@ describe('toClientConfig', function () {
106
106
107
107
const clientConfig = toClientConfig ( config )
108
108
109
- clientConfig . host . should . equal ( 'boom' )
110
- clientConfig . database . should . equal ( 'lala' )
111
- clientConfig . ssl . should . deep . equal ( { } )
109
+ clientConfig . host ? .should . equal ( 'boom' )
110
+ clientConfig . database ? .should . equal ( 'lala' )
111
+ clientConfig . ssl ? .should . deep . equal ( { } )
112
112
} )
113
113
} )
114
114
115
115
describe ( 'parseIntoClientConfig' , function ( ) {
116
116
it ( 'converts url' , function ( ) {
117
117
const clientConfig = parseIntoClientConfig ( 'postgres://brian:pw@boom:381/lala' )
118
118
119
- clientConfig . user . should . equal ( 'brian' )
120
- clientConfig . password . should . equal ( 'pw' )
121
- clientConfig . host . should . equal ( 'boom' )
122
- clientConfig . port . should . equal ( 381 )
123
- clientConfig . database . should . equal ( 'lala' )
119
+ clientConfig . user ? .should . equal ( 'brian' )
120
+ clientConfig . password ? .should . equal ( 'pw' )
121
+ clientConfig . host ? .should . equal ( 'boom' )
122
+ clientConfig . port ? .should . equal ( 381 )
123
+ clientConfig . database ? .should . equal ( 'lala' )
124
124
} )
125
125
} )
0 commit comments