@@ -5,14 +5,15 @@ const { DocumentController } = require('../../src/controllers/Document');
55const { DocumentSearchResult } = require ( '../../src/core/searchResult/Document' ) ;
66
77describe ( 'Document Controller' , ( ) => {
8- const options = { opt : 'in' } ;
8+ let options ;
99 let kuzzle ;
1010
1111 beforeEach ( ( ) => {
1212 kuzzle = {
1313 query : sinon . stub ( ) . resolves ( )
1414 } ;
1515 kuzzle . document = new DocumentController ( kuzzle ) ;
16+ options = { opt : 'in' } ;
1617 } ) ;
1718
1819 describe ( 'count' , ( ) => {
@@ -118,7 +119,7 @@ describe('Document Controller', () => {
118119 } ) ;
119120 } ) ;
120121
121-
122+
122123 describe ( 'deleteFields' , ( ) => {
123124 it ( 'should call document/deleteFields query and return a Promise which resolves the updated document' , ( ) => {
124125 kuzzle . query . resolves ( { result : { _id : 'document-id' , _source : { foo : 'bar' } } } ) ;
@@ -219,6 +220,7 @@ describe('Document Controller', () => {
219220 } ;
220221 kuzzle . query . resolves ( { result} ) ;
221222 options . silent = true ;
223+ options . strict = true ;
222224
223225 return kuzzle . document . mCreate ( 'index' , 'collection' , [ { _id : 'document-id' , body : { foo : 'bar' } } ] , options )
224226 . then ( res => {
@@ -230,6 +232,7 @@ describe('Document Controller', () => {
230232 index : 'index' ,
231233 collection : 'collection' ,
232234 silent : true ,
235+ strict : true ,
233236 body : { documents : [ { _id : 'document-id' , body : { foo : 'bar' } } ] }
234237 } , options ) ;
235238
@@ -250,6 +253,7 @@ describe('Document Controller', () => {
250253 } ;
251254 kuzzle . query . resolves ( { result} ) ;
252255 options . silent = true ;
256+ options . strict = true ;
253257
254258 return kuzzle . document . mCreateOrReplace ( 'index' , 'collection' , [ { _id : 'document-id' , body : { foo : 'bar' } } ] , options )
255259 . then ( res => {
@@ -261,6 +265,7 @@ describe('Document Controller', () => {
261265 index : 'index' ,
262266 collection : 'collection' ,
263267 silent : true ,
268+ strict : true ,
264269 body : { documents : [ { _id : 'document-id' , body : { foo : 'bar' } } ] }
265270 } , options ) ;
266271
@@ -269,11 +274,44 @@ describe('Document Controller', () => {
269274 } ) ;
270275 } ) ;
271276
277+ describe ( 'upsert' , ( ) => {
278+ it ( 'should call document/upsert query and return a Promise which resolves Kuzzle result' , ( ) => {
279+ const result = {
280+ _id : 'document-1629897817507' ,
281+ _version : 1 ,
282+ created : true
283+ } ;
284+ kuzzle . query . resolves ( { result} ) ;
285+ options . silent = true ;
286+ options . default = { def : 'default' } ;
287+ options . source = true ;
288+
289+ return kuzzle . document . upsert ( 'index' , 'collection' , 'some-id' , { changes : 'changes' } , options )
290+ . then ( res => {
291+ should ( kuzzle . query )
292+ . be . calledOnce ( )
293+ . be . calledWith ( {
294+ controller : 'document' ,
295+ action : 'upsert' ,
296+ index : 'index' ,
297+ collection : 'collection' ,
298+ _id : 'some-id' ,
299+ silent : true ,
300+ source : true ,
301+ body : { changes : { changes : 'changes' } , default : { def : 'default' } } ,
302+ } , options ) ;
303+
304+ should ( res ) . be . equal ( result ) ;
305+ } ) ;
306+ } ) ;
307+ } ) ;
308+
272309 describe ( 'mDelete' , ( ) => {
273310 it ( 'should call document/mDelete query and return a Promise which resolves the list of deleted documents ids' , ( ) => {
274311 const result = [ 'document1' , 'document2' ] ;
275312 kuzzle . query . resolves ( { result} ) ;
276313 options . silent = true ;
314+ options . strict = true ;
277315
278316 return kuzzle . document . mDelete ( 'index' , 'collection' , [ 'document1' , 'document2' ] , options )
279317 . then ( res => {
@@ -285,6 +323,7 @@ describe('Document Controller', () => {
285323 index : 'index' ,
286324 collection : 'collection' ,
287325 silent : true ,
326+ strict : true ,
288327 body : { ids : [ 'document1' , 'document2' ] }
289328 } , options ) ;
290329
@@ -336,6 +375,7 @@ describe('Document Controller', () => {
336375 } ;
337376 kuzzle . query . resolves ( { result} ) ;
338377 options . silent = true ;
378+ options . strict = true ;
339379
340380 return kuzzle . document . mReplace ( 'index' , 'collection' , [ { _id : 'document-id' , body : { foo : 'bar' } } ] , options )
341381 . then ( res => {
@@ -347,6 +387,7 @@ describe('Document Controller', () => {
347387 index : 'index' ,
348388 collection : 'collection' ,
349389 silent : true ,
390+ strict : true ,
350391 body : { documents : [ { _id : 'document-id' , body : { foo : 'bar' } } ] }
351392 } , options ) ;
352393
@@ -367,6 +408,7 @@ describe('Document Controller', () => {
367408 } ;
368409 kuzzle . query . resolves ( { result} ) ;
369410 options . silent = true ;
411+ options . strict = true ;
370412
371413 return kuzzle . document . mUpdate ( 'index' , 'collection' , [ { _id : 'document-id' , body : { foo : 'bar' } } ] , options )
372414 . then ( res => {
@@ -378,6 +420,7 @@ describe('Document Controller', () => {
378420 index : 'index' ,
379421 collection : 'collection' ,
380422 silent : true ,
423+ strict : true ,
381424 body : { documents : [ { _id : 'document-id' , body : { foo : 'bar' } } ] }
382425 } , options ) ;
383426
0 commit comments