1- 'use strict'
2-
3- const chai = require ( 'chai' )
1+ import chai from 'chai'
42const expect = chai . expect
53chai . should ( )
64
7- const { parse, toClientConfig, parseIntoClientConfig } = require ( '../' )
5+ import { parse , toClientConfig , parseIntoClientConfig } from '../'
86
97describe ( 'toClientConfig' , function ( ) {
108 it ( 'converts connection info' , function ( ) {
119 const config = parse ( 'postgres://brian:pw@boom:381/lala' )
1210 const clientConfig = toClientConfig ( config )
1311
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' )
1917 } )
2018
2119 it ( 'converts query params' , function ( ) {
@@ -24,45 +22,47 @@ describe('toClientConfig', function () {
2422 )
2523 const clientConfig = toClientConfig ( config )
2624
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' )
3129 } )
3230
3331 it ( 'converts SSL boolean' , function ( ) {
3432 const config = parse ( 'pg:///?ssl=true' )
3533 const clientConfig = toClientConfig ( config )
3634
37- clientConfig . ssl . should . equal ( true )
35+ clientConfig . ssl ? .should . equal ( true )
3836 } )
3937
4038 it ( 'converts sslmode=disable' , function ( ) {
4139 const config = parse ( 'pg:///?sslmode=disable' )
4240 const clientConfig = toClientConfig ( config )
4341
44- clientConfig . ssl . should . equal ( false )
42+ clientConfig . ssl ? .should . equal ( false )
4543 } )
4644
4745 it ( 'converts sslmode=noverify' , function ( ) {
4846 const config = parse ( 'pg:///?sslmode=no-verify' )
4947 const clientConfig = toClientConfig ( config )
5048
51- clientConfig . ssl . rejectUnauthorized . should . equal ( false )
49+ clientConfig . ssl ?. should . deep . equal ( {
50+ rejectUnauthorized : false ,
51+ } )
5252 } )
5353
5454 it ( 'converts other sslmode options' , function ( ) {
5555 const config = parse ( 'pg:///?sslmode=verify-ca' )
5656 const clientConfig = toClientConfig ( config )
5757
58- clientConfig . ssl . should . deep . equal ( { } )
58+ clientConfig . ssl ? .should . deep . equal ( { } )
5959 } )
6060
6161 it ( 'converts other sslmode options' , function ( ) {
6262 const config = parse ( 'pg:///?sslmode=verify-ca' )
6363 const clientConfig = toClientConfig ( config )
6464
65- clientConfig . ssl . should . deep . equal ( { } )
65+ clientConfig . ssl ? .should . deep . equal ( { } )
6666 } )
6767
6868 it ( 'converts ssl cert options' , function ( ) {
@@ -77,7 +77,7 @@ describe('toClientConfig', function () {
7777 const config = parse ( connectionString )
7878 const clientConfig = toClientConfig ( config )
7979
80- clientConfig . ssl . should . deep . equal ( {
80+ clientConfig . ssl ? .should . deep . equal ( {
8181 ca : 'example ca\n' ,
8282 cert : 'example cert\n' ,
8383 key : 'example key\n' ,
@@ -87,9 +87,9 @@ describe('toClientConfig', function () {
8787 it ( 'converts unix domain sockets' , function ( ) {
8888 const config = parse ( 'socket:/some path/?db=my[db]&encoding=utf8&client_encoding=bogus' )
8989 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' )
9393 } )
9494
9595 it ( 'handles invalid port' , function ( ) {
@@ -106,20 +106,20 @@ describe('toClientConfig', function () {
106106
107107 const clientConfig = toClientConfig ( config )
108108
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 ( { } )
112112 } )
113113} )
114114
115115describe ( 'parseIntoClientConfig' , function ( ) {
116116 it ( 'converts url' , function ( ) {
117117 const clientConfig = parseIntoClientConfig ( 'postgres://brian:pw@boom:381/lala' )
118118
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' )
124124 } )
125125} )
0 commit comments