2
2
import Observable from 'any-observable' ;
3
3
import { Dictionary , each } from 'lodash' ;
4
4
import { tap } from 'rxjs/operators' ;
5
- import { SinonSpy , spy } from 'sinon' ;
6
5
import { v1 as neo4j } from 'neo4j-driver' ;
7
- import { AuthToken , Config } from 'neo4j-driver/types/v1/driver' ;
8
6
import { Driver } from 'neo4j-driver/types/v1' ;
7
+ import { AuthToken , Config } from 'neo4j-driver/types/v1/driver' ;
8
+ import { SinonSpy , spy } from 'sinon' ;
9
9
import { Connection , Node , Query } from '../src' ;
10
10
import { NodePattern } from '../src/clauses' ;
11
11
import { expect } from '../test-setup' ;
@@ -108,15 +108,15 @@ describe('Connection', () => {
108
108
} ) ;
109
109
110
110
describe ( '#run' , ( ) => {
111
- it ( 'should throw if there are no clauses in the query' , ( ) => {
112
- const run = ( ) => connection . run ( connection . query ( ) ) ;
113
- expect ( run ) . to . throw ( Error , 'no clauses' ) ;
111
+ it ( 'should reject if there are no clauses in the query' , ( ) => {
112
+ const promise = connection . run ( connection . query ( ) ) ;
113
+ expect ( promise ) . to . be . rejectedWith ( Error , 'no clauses' ) ;
114
114
} ) ;
115
115
116
- it ( 'should throw if the connection has been closed' , ( ) => {
116
+ it ( 'should reject if the connection has been closed' , ( ) => {
117
117
connection . close ( ) ;
118
- const run = ( ) => connection . run ( connection . query ( ) . matchNode ( 'node' ) ) ;
119
- expect ( run ) . to . throw ( Error , 'connection is not open' ) ;
118
+ const promise = connection . run ( connection . query ( ) . matchNode ( 'node' ) ) ;
119
+ expect ( promise ) . to . be . rejectedWith ( Error , 'connection is not open' ) ;
120
120
} ) ;
121
121
122
122
it ( 'should run the query through a session' , ( ) => {
@@ -171,15 +171,33 @@ describe('Connection', () => {
171
171
connection . close ( ) ;
172
172
} ) ;
173
173
174
- it ( 'should throw if there are no clauses in the query' , ( ) => {
175
- const stream = ( ) => connection . stream ( connection . query ( ) ) ;
176
- expect ( stream ) . to . throw ( Error , 'no clauses' ) ;
174
+ it ( 'should return errored observable if there are no clauses in the query' , ( ) => {
175
+ const observable = connection . stream ( connection . query ( ) ) ;
176
+ expect ( observable ) . to . be . an . instanceOf ( Observable ) ;
177
+
178
+ observable . subscribe ( {
179
+ next : ( ) => expect . fail ( null , null , 'Observable should not emit anything' ) ,
180
+ error ( error ) {
181
+ expect ( error ) . to . be . instanceOf ( Error ) ;
182
+ expect ( error . message ) . to . include ( 'no clauses' ) ;
183
+ } ,
184
+ complete : ( ) => expect . fail ( null , null , 'Observable should not complete successfully' ) ,
185
+ } ) ;
177
186
} ) ;
178
187
179
- it ( 'should throw if the connection has been closed' , ( ) => {
188
+ it ( 'should return errored observable if the connection has been closed' , ( ) => {
180
189
connection . close ( ) ;
181
- const stream = ( ) => connection . stream ( query ) ;
182
- expect ( stream ) . to . throw ( Error , 'connection is not open' ) ;
190
+ const observable = connection . stream ( query ) ;
191
+ expect ( observable ) . to . be . an . instanceOf ( Observable ) ;
192
+
193
+ observable . subscribe ( {
194
+ next : ( ) => expect . fail ( null , null , 'Observable should not emit anything' ) ,
195
+ error ( error ) {
196
+ expect ( error ) . to . be . instanceOf ( Error ) ;
197
+ expect ( error . message ) . to . include ( 'connection is not open' ) ;
198
+ } ,
199
+ complete : ( ) => expect . fail ( null , null , 'Observable should not complete successfully' ) ,
200
+ } ) ;
183
201
} ) ;
184
202
185
203
it ( 'should run the query through a session' , ( ) => {
@@ -216,7 +234,7 @@ describe('Connection', () => {
216
234
expect ( observable ) . to . be . an . instanceOf ( Observable ) ;
217
235
observable . subscribe ( {
218
236
next : ( ) => expect . fail ( null , null , 'Observable should not emit any items' ) ,
219
- error : ( ) => {
237
+ error ( ) {
220
238
expect ( sessionCloseSpy . calledOnce ) ;
221
239
done ( ) ;
222
240
} ,
@@ -227,32 +245,41 @@ describe('Connection', () => {
227
245
228
246
describe ( 'query methods' , ( ) => {
229
247
const methods : Dictionary < Function > = {
230
- query : ( ) => connection . query ( ) ,
231
- matchNode : ( ) => connection . matchNode ( 'Node' ) ,
232
- match : ( ) => connection . match ( new NodePattern ( 'Node' ) ) ,
233
- optionalMatch : ( ) => connection . optionalMatch ( new NodePattern ( 'Node' ) ) ,
234
248
create : ( ) => connection . create ( new NodePattern ( 'Node' ) ) ,
235
- createUnique : ( ) => connection . createUnique ( new NodePattern ( 'Node' ) ) ,
236
249
createNode : ( ) => connection . createNode ( 'Node' ) ,
250
+ createUnique : ( ) => connection . createUnique ( new NodePattern ( 'Node' ) ) ,
237
251
createUniqueNode : ( ) => connection . createUniqueNode ( 'Node' ) ,
238
- return : ( ) => connection . return ( 'node' ) ,
239
- returnDistinct : ( ) => connection . returnDistinct ( 'node' ) ,
252
+ delete : ( ) => connection . delete ( 'node' ) ,
253
+ detachDelete : ( ) => connection . detachDelete ( 'node' ) ,
254
+ limit : ( ) => connection . limit ( 1 ) ,
255
+ match : ( ) => connection . match ( new NodePattern ( 'Node' ) ) ,
256
+ matchNode : ( ) => connection . matchNode ( 'Node' ) ,
257
+ merge : ( ) => connection . merge ( new NodePattern ( 'Node' ) ) ,
258
+ onCreateSet : ( ) => connection . onCreate . set ( { } , { merge : false } ) ,
259
+ onCreateSetLabels : ( ) => connection . onCreate . setLabels ( { } ) ,
260
+ onCreateSetValues : ( ) => connection . onCreate . setValues ( { } ) ,
261
+ onCreateSetVariables : ( ) => connection . onCreate . setVariables ( { } , false ) ,
262
+ onMatchSet : ( ) => connection . onMatch . set ( { } , { merge : false } ) ,
263
+ onMatchSetLabels : ( ) => connection . onMatch . setLabels ( { } ) ,
264
+ onMatchSetValues : ( ) => connection . onMatch . setValues ( { } ) ,
265
+ onMatchSetVariables : ( ) => connection . onMatch . setVariables ( { } , false ) ,
266
+ optionalMatch : ( ) => connection . optionalMatch ( new NodePattern ( 'Node' ) ) ,
267
+ orderBy : ( ) => connection . orderBy ( 'name' ) ,
268
+ query : ( ) => connection . query ( ) ,
269
+ raw : ( ) => connection . raw ( 'name' ) ,
240
270
remove : ( ) => connection . remove ( { properties : { node : [ 'prop1' , 'prop2' ] } } ) ,
241
271
removeProperties : ( ) => connection . removeProperties ( { node : [ 'prop1' , 'prop2' ] } ) ,
242
272
removeLabels : ( ) => connection . removeLabels ( { node : 'label' } ) ,
243
- with : ( ) => connection . with ( 'node' ) ,
244
- unwind : ( ) => connection . unwind ( [ 1 , 2 , 3 ] , 'number' ) ,
245
- delete : ( ) => connection . delete ( 'node' ) ,
246
- detachDelete : ( ) => connection . detachDelete ( 'node' ) ,
273
+ return : ( ) => connection . return ( 'node' ) ,
274
+ returnDistinct : ( ) => connection . returnDistinct ( 'node' ) ,
247
275
set : ( ) => connection . set ( { } , { merge : false } ) ,
248
276
setLabels : ( ) => connection . setLabels ( { } ) ,
249
277
setValues : ( ) => connection . setValues ( { } ) ,
250
278
setVariables : ( ) => connection . setVariables ( { } , false ) ,
251
279
skip : ( ) => connection . skip ( 1 ) ,
252
- limit : ( ) => connection . limit ( 1 ) ,
280
+ unwind : ( ) => connection . unwind ( [ 1 , 2 , 3 ] , 'number' ) ,
253
281
where : ( ) => connection . where ( [ ] ) ,
254
- orderBy : ( ) => connection . orderBy ( 'name' ) ,
255
- raw : ( ) => connection . raw ( 'name' ) ,
282
+ with : ( ) => connection . with ( 'node' ) ,
256
283
} ;
257
284
258
285
each ( methods , ( fn , name ) => {
0 commit comments