@@ -17,12 +17,78 @@ const otherThingIds = [
1717 "8727fa2b-610a-4a5c-af26-e558943f71c7" ,
1818] ;
1919
20+ const someObjects = [
21+ {
22+ class : thingClassName ,
23+ id : thingIds [ 0 ] ,
24+ properties : { stringProp : "foo1" } ,
25+ } ,
26+ {
27+ class : thingClassName ,
28+ id : thingIds [ 1 ] ,
29+ properties : { stringProp : "bar1" } ,
30+ } ,
31+ {
32+ class : thingClassName ,
33+ id : thingIds [ 2 ] ,
34+ properties : { stringProp : "foo2" } ,
35+ } ,
36+ {
37+ class : thingClassName ,
38+ id : thingIds [ 3 ] ,
39+ properties : { stringProp : "bar2" } ,
40+ } ,
41+ {
42+ class : otherThingClassName ,
43+ id : otherThingIds [ 0 ] ,
44+ properties : { stringProp : "foo3" } ,
45+ } ,
46+ {
47+ class : otherThingClassName ,
48+ id : otherThingIds [ 1 ] ,
49+ properties : { stringProp : "bar3" } ,
50+ } ,
51+ ] ;
52+
53+ const someReferences = [
54+ {
55+ from : `weaviate://localhost/${ thingClassName } /${ thingIds [ 0 ] } /refProp` ,
56+ to : `weaviate://localhost/${ otherThingClassName } /${ otherThingIds [ 0 ] } ` ,
57+ } ,
58+ {
59+ from : `weaviate://localhost/${ thingClassName } /${ thingIds [ 1 ] } /refProp` ,
60+ to : `weaviate://localhost/${ otherThingClassName } /${ otherThingIds [ 1 ] } ` ,
61+ } ,
62+ {
63+ from : `weaviate://localhost/${ thingClassName } /${ thingIds [ 2 ] } /refProp` ,
64+ to : `weaviate://localhost/${ otherThingClassName } /${ otherThingIds [ 1 ] } ` ,
65+ } ,
66+ {
67+ from : `weaviate://localhost/${ thingClassName } /${ thingIds [ 3 ] } /refProp` ,
68+ to : `weaviate://localhost/${ otherThingClassName } /${ otherThingIds [ 1 ] } ` ,
69+ }
70+ ] ;
71+
2072describe ( "batch importing" , ( ) => {
2173 const client = weaviate . client ( {
2274 scheme : "http" ,
2375 host : "localhost:8080" ,
2476 } ) ;
2577
78+ it ( "can add objects with different methods" , ( ) => {
79+ const batcher = client . batch . objectsBatcher ( )
80+ . withObject ( someObjects [ 0 ] )
81+ . withObjects ( someObjects [ 1 ] )
82+ . withObjects ( someObjects [ 2 ] , someObjects [ 3 ] )
83+ . withObjects ( [ someObjects [ 4 ] , someObjects [ 5 ] ] ) ;
84+
85+ expect ( batcher . objects ) . toHaveLength ( someObjects . length ) ;
86+ batcher . objects . forEach ( ( obj , i ) => {
87+ expect ( obj . class ) . toBe ( someObjects [ i ] . class ) ;
88+ expect ( obj . id ) . toBe ( someObjects [ i ] . id ) ;
89+ } )
90+ } ) ;
91+
2692 it ( "sets up" , ( ) => setup ( client ) ) ;
2793
2894 describe ( "import thing objects" , ( ) => {
@@ -81,8 +147,7 @@ describe("batch importing", () => {
81147 it ( "imports them" , ( ) => {
82148 client . batch
83149 . objectsBatcher ( )
84- . withObject ( toImport [ 0 ] )
85- . withObject ( toImport [ 1 ] )
150+ . withObjects ( toImport [ 0 ] , toImport [ 1 ] )
86151 . do ( )
87152 . then ( )
88153 . catch ( ( e ) => fail ( "it should not have error'd " + e ) ) ;
@@ -119,8 +184,7 @@ describe("batch importing", () => {
119184 it ( "imports them" , ( ) => {
120185 client . batch
121186 . objectsBatcher ( )
122- . withObject ( toImport [ 0 ] )
123- . withObject ( toImport [ 1 ] )
187+ . withObjects ( [ toImport [ 0 ] , toImport [ 1 ] ] )
124188 . do ( )
125189 . then ( )
126190 . catch ( ( e ) => fail ( "it should not have error'd " + e ) ) ;
@@ -140,6 +204,19 @@ describe("batch importing", () => {
140204 } ) ;
141205
142206 describe ( "batch reference between the thing and otherThing objects" , ( ) => {
207+ it ( "can add references with different methods" , ( ) => {
208+ const batcher = client . batch . referencesBatcher ( )
209+ . withReference ( someReferences [ 0 ] )
210+ . withReferences ( someReferences [ 1 ] , someReferences [ 2 ] )
211+ . withReferences ( [ someReferences [ 3 ] ] ) ;
212+
213+ expect ( batcher . references ) . toHaveLength ( someReferences . length ) ;
214+ batcher . references . forEach ( ( ref , i ) => {
215+ expect ( ref . from ) . toBe ( someReferences [ i ] . from ) ;
216+ expect ( ref . to ) . toBe ( someReferences [ i ] . to ) ;
217+ } )
218+ } ) ;
219+
143220 it ( "imports the refs with raw objects" , ( ) => {
144221 return client . batch
145222 . referencesBatcher ( )
@@ -161,28 +238,25 @@ describe("batch importing", () => {
161238 } ) ;
162239
163240 it ( "imports more refs with a builder pattern" , ( ) => {
241+ const reference1 = client . batch
242+ . referencePayloadBuilder ( )
243+ . withFromClassName ( thingClassName )
244+ . withFromRefProp ( "refProp" )
245+ . withFromId ( thingIds [ 2 ] )
246+ . withToId ( otherThingIds [ 0 ] )
247+ . withToClassName ( otherThingClassName )
248+ . payload ( ) ;
249+ const reference2 = client . batch
250+ . referencePayloadBuilder ( )
251+ . withFromClassName ( thingClassName )
252+ . withFromRefProp ( "refProp" )
253+ . withFromId ( thingIds [ 3 ] )
254+ . withToId ( otherThingIds [ 1 ] )
255+ . withToClassName ( otherThingClassName )
256+ . payload ( ) ;
164257 return client . batch
165258 . referencesBatcher ( )
166- . withReference (
167- client . batch
168- . referencePayloadBuilder ( )
169- . withFromClassName ( thingClassName )
170- . withFromRefProp ( "refProp" )
171- . withFromId ( thingIds [ 2 ] )
172- . withToId ( otherThingIds [ 0 ] )
173- . withToClassName ( otherThingClassName )
174- . payload ( )
175- )
176- . withReference (
177- client . batch
178- . referencePayloadBuilder ( )
179- . withFromClassName ( thingClassName )
180- . withFromRefProp ( "refProp" )
181- . withFromId ( thingIds [ 3 ] )
182- . withToId ( otherThingIds [ 1 ] )
183- . withToClassName ( otherThingClassName )
184- . payload ( )
185- )
259+ . withReferences ( reference1 , reference2 )
186260 . do ( )
187261 . then ( ( res ) => {
188262 res . forEach ( ( elem ) => {
@@ -453,47 +527,9 @@ const setup = async (client) => {
453527} ;
454528
455529const setupData = ( client ) => {
456- const toImport = [
457- {
458- class : thingClassName ,
459- id : thingIds [ 0 ] ,
460- properties : { stringProp : "foo1" } ,
461- } ,
462- {
463- class : thingClassName ,
464- id : thingIds [ 1 ] ,
465- properties : { stringProp : "bar1" } ,
466- } ,
467- {
468- class : thingClassName ,
469- id : thingIds [ 2 ] ,
470- properties : { stringProp : "foo2" } ,
471- } ,
472- {
473- class : thingClassName ,
474- id : thingIds [ 3 ] ,
475- properties : { stringProp : "bar2" } ,
476- } ,
477- {
478- class : otherThingClassName ,
479- id : otherThingIds [ 0 ] ,
480- properties : { stringProp : "foo3" } ,
481- } ,
482- {
483- class : otherThingClassName ,
484- id : otherThingIds [ 1 ] ,
485- properties : { stringProp : "bar3" } ,
486- } ,
487- ] ;
488-
489530 return client . batch
490531 . objectsBatcher ( )
491- . withObject ( toImport [ 0 ] )
492- . withObject ( toImport [ 1 ] )
493- . withObject ( toImport [ 2 ] )
494- . withObject ( toImport [ 3 ] )
495- . withObject ( toImport [ 4 ] )
496- . withObject ( toImport [ 5 ] )
532+ . withObjects ( someObjects )
497533 . do ( ) ;
498534}
499535
0 commit comments