1717 * limitations under the License.
1818 */
1919
20- const util = require ( '../../lib /v1/internal/util.js' ) ;
20+ import * as util from '../../src /v1/internal/util' ;
2121
22- describe ( 'util' , ( ) => {
22+ fdescribe ( 'util' , ( ) => {
2323
2424 it ( 'should check empty objects' , ( ) => {
2525 expect ( util . isEmptyObjectOrNull ( null ) ) . toBeTruthy ( ) ;
@@ -55,6 +55,112 @@ describe('util', () => {
5555 verifyInvalidString ( console . log ) ;
5656 } ) ;
5757
58+ it ( 'should parse scheme' , ( ) => {
59+ verifyScheme ( 'bolt://' , 'bolt://localhost' ) ;
60+ verifyScheme ( 'bolt://' , 'bolt://localhost:7687' ) ;
61+ verifyScheme ( 'bolt://' , 'bolt://neo4j.com' ) ;
62+ verifyScheme ( 'bolt://' , 'bolt://neo4j.com:80' ) ;
63+
64+ verifyScheme ( 'bolt+routing://' , 'bolt+routing://127.0.0.1' ) ;
65+ verifyScheme ( 'bolt+routing://' , 'bolt+routing://127.0.0.1:7687' ) ;
66+ verifyScheme ( 'bolt+routing://' , 'bolt+routing://neo4j.com' ) ;
67+ verifyScheme ( 'bolt+routing://' , 'bolt+routing://neo4j.com:80' ) ;
68+
69+ verifyScheme ( 'wss://' , 'wss://server.com' ) ;
70+ verifyScheme ( 'wss://' , 'wss://server.com:7687' ) ;
71+ verifyScheme ( 'wss://' , 'wss://1.1.1.1' ) ;
72+ verifyScheme ( 'wss://' , 'wss://8.8.8.8:80' ) ;
73+
74+ verifyScheme ( '' , 'invalid url' ) ;
75+ verifyScheme ( '' , 'localhost:7676' ) ;
76+ verifyScheme ( '' , '127.0.0.1' ) ;
77+ } ) ;
78+
79+ it ( 'should fail to parse scheme from non-string argument' , ( ) => {
80+ expect ( ( ) => util . parseScheme ( { } ) ) . toThrowError ( TypeError ) ;
81+ expect ( ( ) => util . parseScheme ( [ 'bolt://localhost:2020' ] ) ) . toThrowError ( TypeError ) ;
82+ expect ( ( ) => util . parseScheme ( ( ) => 'bolt://localhost:8888' ) ) . toThrowError ( TypeError ) ;
83+ } ) ;
84+
85+ it ( 'should parse url' , ( ) => {
86+ verifyUrl ( 'localhost' , 'bolt://localhost' ) ;
87+ verifyUrl ( 'localhost:9090' , 'bolt://localhost:9090' ) ;
88+ verifyUrl ( '127.0.0.1' , 'bolt://127.0.0.1' ) ;
89+ verifyUrl ( '127.0.0.1:7687' , 'bolt://127.0.0.1:7687' ) ;
90+ verifyUrl ( '10.198.20.1' , 'bolt+routing://10.198.20.1' ) ;
91+ verifyUrl ( '15.8.8.9:20004' , 'wss://15.8.8.9:20004' ) ;
92+ } ) ;
93+
94+ it ( 'should fail to parse url from non-string argument' , ( ) => {
95+ expect ( ( ) => util . parseUrl ( { } ) ) . toThrowError ( TypeError ) ;
96+ expect ( ( ) => util . parseUrl ( [ 'bolt://localhost:2020' ] ) ) . toThrowError ( TypeError ) ;
97+ expect ( ( ) => util . parseUrl ( ( ) => 'bolt://localhost:8888' ) ) . toThrowError ( TypeError ) ;
98+ } ) ;
99+
100+ it ( 'should parse host' , ( ) => {
101+ verifyHost ( 'localhost' , 'bolt://localhost' ) ;
102+ verifyHost ( 'neo4j.com' , 'bolt+routing://neo4j.com' ) ;
103+ verifyHost ( 'neo4j.com' , 'bolt+routing://neo4j.com:8080' ) ;
104+ verifyHost ( '127.0.0.1' , 'https://127.0.0.1' ) ;
105+ verifyHost ( '127.0.0.1' , 'ws://127.0.0.1:2020' ) ;
106+ } ) ;
107+
108+ it ( 'should fail to parse host from non-string argument' , ( ) => {
109+ expect ( ( ) => util . parseHost ( { } ) ) . toThrowError ( TypeError ) ;
110+ expect ( ( ) => util . parseHost ( [ 'bolt://localhost:2020' ] ) ) . toThrowError ( TypeError ) ;
111+ expect ( ( ) => util . parseHost ( ( ) => 'bolt://localhost:8888' ) ) . toThrowError ( TypeError ) ;
112+ } ) ;
113+
114+ it ( 'should parse port' , ( ) => {
115+ verifyPort ( '7474' , 'http://localhost:7474' ) ;
116+ verifyPort ( '8080' , 'http://127.0.0.1:8080' ) ;
117+ verifyPort ( '20005' , 'bolt+routing://neo4j.com:20005' ) ;
118+ verifyPort ( '4242' , 'bolt+routing://1.1.1.1:4242' ) ;
119+ verifyPort ( '42' , 'http://10.192.168.5:42' ) ;
120+
121+ verifyPort ( undefined , 'https://localhost' ) ;
122+ verifyPort ( undefined , 'ws://8.8.8.8' ) ;
123+ } ) ;
124+
125+ it ( 'should fail to parse port from non-string argument' , ( ) => {
126+ expect ( ( ) => util . parsePort ( { port : 1515 } ) ) . toThrowError ( TypeError ) ;
127+ expect ( ( ) => util . parsePort ( [ 'bolt://localhost:2020' ] ) ) . toThrowError ( TypeError ) ;
128+ expect ( ( ) => util . parsePort ( ( ) => 'bolt://localhost:8888' ) ) . toThrowError ( TypeError ) ;
129+ } ) ;
130+
131+ it ( 'should parse routing context' , ( ) => {
132+ verifyRoutingContext ( {
133+ name : 'molly' ,
134+ age : '1' ,
135+ color : 'white'
136+ } , 'bolt+routing://localhost:7687/cat?name=molly&age=1&color=white' ) ;
137+
138+ verifyRoutingContext ( {
139+ key1 : 'value1' ,
140+ key2 : 'value2'
141+ } , 'bolt+routing://localhost:7687/?key1=value1&key2=value2' ) ;
142+
143+ verifyRoutingContext ( { key : 'value' } , 'bolt+routing://10.198.12.2:9999?key=value' ) ;
144+
145+ verifyRoutingContext ( { } , 'bolt+routing://localhost:7687?' ) ;
146+ verifyRoutingContext ( { } , 'bolt+routing://localhost:7687/?' ) ;
147+ verifyRoutingContext ( { } , 'bolt+routing://localhost:7687/cat?' ) ;
148+ verifyRoutingContext ( { } , 'bolt+routing://localhost:7687/lala' ) ;
149+ } ) ;
150+
151+ it ( 'should fail to parse routing context from non-string argument' , ( ) => {
152+ expect ( ( ) => util . parseRoutingContext ( { key1 : 'value1' } ) ) . toThrowError ( TypeError ) ;
153+ expect ( ( ) => util . parseRoutingContext ( [ 'bolt://localhost:2020/?key=value' ] ) ) . toThrowError ( TypeError ) ;
154+ expect ( ( ) => util . parseRoutingContext ( ( ) => 'bolt://localhost?key1=value&key2=value2' ) ) . toThrowError ( TypeError ) ;
155+ } ) ;
156+
157+ it ( 'should fail to parse routing context from illegal parameters' , ( ) => {
158+ expect ( ( ) => util . parseRoutingContext ( 'bolt+routing://localhost:7687/?justKey' ) ) . toThrow ( ) ;
159+ expect ( ( ) => util . parseRoutingContext ( 'bolt+routing://localhost:7687/?=value1&key2=value2' ) ) . toThrow ( ) ;
160+ expect ( ( ) => util . parseRoutingContext ( 'bolt+routing://localhost:7687/key1?=value1&key2=' ) ) . toThrow ( ) ;
161+ expect ( ( ) => util . parseRoutingContext ( 'bolt+routing://localhost:7687/?key1=value1&key2=value2&key1=value2' ) ) . toThrow ( ) ;
162+ } ) ;
163+
58164 function verifyValidString ( str ) {
59165 expect ( util . assertString ( str , 'Test string' ) ) . toBe ( str ) ;
60166 }
@@ -63,4 +169,24 @@ describe('util', () => {
63169 expect ( ( ) => util . assertString ( str , 'Test string' ) ) . toThrowError ( TypeError ) ;
64170 }
65171
172+ function verifyScheme ( expectedScheme , url ) {
173+ expect ( util . parseScheme ( url ) ) . toEqual ( expectedScheme ) ;
174+ }
175+
176+ function verifyUrl ( expectedUrl , url ) {
177+ expect ( util . parseUrl ( url ) ) . toEqual ( expectedUrl ) ;
178+ }
179+
180+ function verifyHost ( expectedHost , url ) {
181+ expect ( util . parseHost ( url ) ) . toEqual ( expectedHost ) ;
182+ }
183+
184+ function verifyPort ( expectedPort , url ) {
185+ expect ( util . parsePort ( url ) ) . toEqual ( expectedPort ) ;
186+ }
187+
188+ function verifyRoutingContext ( expectedRoutingContext , url ) {
189+ expect ( util . parseRoutingContext ( url ) ) . toEqual ( expectedRoutingContext ) ;
190+ }
191+
66192} ) ;
0 commit comments