@@ -30,8 +30,8 @@ const logger = {
30
30
const addSyncOnAttribute = function ( ) { } ;
31
31
32
32
describe ( 'Test libNgsildUpdates' , function ( ) {
33
- it ( 'Should post body with correct path and token for nonOverwrite update' , async function ( ) {
34
- let updatePropertiesCalled = false ;
33
+ it ( 'Should post entities with correct path and token for nonOverwrite update using batchMerge ' , async function ( ) {
34
+ let batchMergeCalled = false ;
35
35
const config = {
36
36
ngsildUpdates : {
37
37
clientSecretVariable : 'CLIENT_SECRET' ,
@@ -66,19 +66,20 @@ describe('Test libNgsildUpdates', function () {
66
66
} ;
67
67
const Ngsild = function ( ) {
68
68
return {
69
- updateProperties : function ( { id, body, isOverwrite } , { headers } ) {
70
- updatePropertiesCalled = true ;
71
- id . should . equal ( 'id' ) ;
72
- assert . deepEqual ( body , { id : 'id' , type : 'type' } ) ;
73
- isOverwrite . should . equal ( false ) ;
69
+ batchMerge : function ( entities , { headers } ) {
70
+ batchMergeCalled = true ;
71
+ assert . deepEqual ( entities , body . entities ) ;
74
72
assert . deepEqual ( headers , expHeaders ) ;
75
73
return new Promise ( function ( resolve ) {
76
74
resolve ( {
77
75
statusCode : 204
78
76
} ) ;
79
77
} ) ;
80
78
} ,
79
+ // Stub updateProperties if needed
80
+ updateProperties : function ( ) { } ,
81
81
replaceEntities : function ( ) {
82
+
82
83
}
83
84
} ;
84
85
} ;
@@ -108,11 +109,11 @@ describe('Test libNgsildUpdates', function () {
108
109
ToTest . __set__ ( 'addSyncOnAttribute' , addSyncOnAttribute ) ;
109
110
const ngsildUpdates = new ToTest ( config ) ;
110
111
await ngsildUpdates . ngsildUpdates ( body ) ;
111
- updatePropertiesCalled . should . equal ( true ) ;
112
+ batchMergeCalled . should . equal ( true ) ;
112
113
revert ( ) ;
113
114
} ) ;
114
- it ( 'Should post body and filter out datasetId === "@none"' , async function ( ) {
115
- let updatePropertiesCalled = false ;
115
+ it ( 'Should post entities and filter out datasetId === "@none"' , async function ( ) {
116
+ let batchMergeCalled = false ;
116
117
const config = {
117
118
ngsildUpdates : {
118
119
clientSecretVariable : 'CLIENT_SECRET' ,
@@ -151,19 +152,24 @@ describe('Test libNgsildUpdates', function () {
151
152
} ;
152
153
const Ngsild = function ( ) {
153
154
return {
154
- updateProperties : function ( { id, body, isOverwrite } , { headers } ) {
155
- updatePropertiesCalled = true ;
156
- id . should . equal ( 'id' ) ;
157
- assert . deepEqual ( body , { id : 'id' , type : 'type' , attribute : { value : 'value' } } ) ;
158
- isOverwrite . should . equal ( false ) ;
155
+ batchMerge : function ( entities , { headers } ) {
156
+ batchMergeCalled = true ;
157
+ entities . forEach ( entity => {
158
+ // Check top-level properties
159
+ assert . equal ( entity . id , 'id' ) ;
160
+ assert . equal ( entity . type , 'type' ) ;
161
+
162
+ // Check attribute properties
163
+ assert . isUndefined ( entity . attribute . datasetId , 'datasetId should be filtered out' ) ;
164
+ assert . property ( entity . attribute , 'value' ) ;
165
+ assert . equal ( entity . attribute . value , 'value' ) ;
166
+ } ) ;
159
167
assert . deepEqual ( headers , expHeaders ) ;
160
168
return new Promise ( function ( resolve ) {
161
169
resolve ( {
162
170
statusCode : 204
163
171
} ) ;
164
172
} ) ;
165
- } ,
166
- replaceEntities : function ( ) {
167
173
}
168
174
} ;
169
175
} ;
@@ -192,11 +198,11 @@ describe('Test libNgsildUpdates', function () {
192
198
ToTest . __set__ ( 'addSyncOnAttribute' , addSyncOnAttribute ) ;
193
199
const ngsildUpdates = new ToTest ( config ) ;
194
200
await ngsildUpdates . ngsildUpdates ( body ) ;
195
- updatePropertiesCalled . should . equal ( true ) ;
201
+ batchMergeCalled . should . equal ( true ) ;
196
202
revert ( ) ;
197
203
} ) ;
198
204
it ( 'Should post body and filter out datasetId === "@none" from attribute array' , async function ( ) {
199
- let updatePropertiesCalled = false ;
205
+ let batchMergeCalled = false ;
200
206
const config = {
201
207
ngsildUpdates : {
202
208
clientSecretVariable : 'CLIENT_SECRET' ,
@@ -241,11 +247,12 @@ describe('Test libNgsildUpdates', function () {
241
247
} ;
242
248
const Ngsild = function ( ) {
243
249
return {
244
- updateProperties : function ( { id, body, isOverwrite } , { headers } ) {
245
- updatePropertiesCalled = true ;
246
- id . should . equal ( 'id' ) ;
247
- assert . deepEqual ( body , { id : 'id' , type : 'type' , attribute : [ { value : 'value' } , { value : 'value2' , datasetId : 'http://example.com#source10' } ] } ) ;
248
- isOverwrite . should . equal ( false ) ;
250
+ batchMerge : function ( entities , { headers } ) {
251
+ batchMergeCalled = true ;
252
+ entities . forEach ( entity => {
253
+ assert . deepEqual ( entity . id , 'id' ) ;
254
+ assert . deepEqual ( entity , { id : 'id' , type : 'type' , attribute : [ { value : 'value' } , { value : 'value2' , datasetId : 'http://example.com#source10' } ] } ) ;
255
+ } ) ;
249
256
assert . deepEqual ( headers , expHeaders ) ;
250
257
return new Promise ( function ( resolve ) {
251
258
resolve ( {
@@ -282,11 +289,11 @@ describe('Test libNgsildUpdates', function () {
282
289
ToTest . __set__ ( 'addSyncOnAttribute' , addSyncOnAttribute ) ;
283
290
const ngsildUpdates = new ToTest ( config ) ;
284
291
await ngsildUpdates . ngsildUpdates ( body ) ;
285
- updatePropertiesCalled . should . equal ( true ) ;
292
+ batchMergeCalled . should . equal ( true ) ;
286
293
revert ( ) ;
287
294
} ) ;
288
- it ( 'Should post body and not filter out datasetId !== "@none"' , async function ( ) {
289
- let updatePropertiesCalled = false ;
295
+ it ( 'Should post entities and not filter out datasetId !== "@none"' , async function ( ) {
296
+ let batchMergeCalled = false ;
290
297
const config = {
291
298
ngsildUpdates : {
292
299
clientSecretVariable : 'CLIENT_SECRET' ,
@@ -325,11 +332,9 @@ describe('Test libNgsildUpdates', function () {
325
332
} ;
326
333
const Ngsild = function ( ) {
327
334
return {
328
- updateProperties : function ( { id, body, isOverwrite } , { headers } ) {
329
- updatePropertiesCalled = true ;
330
- id . should . equal ( 'id' ) ;
331
- assert . deepEqual ( body , { id : 'id' , type : 'type' , attribute : { datasetId : 'https://example.com/source1' , value : 'value' } } ) ;
332
- isOverwrite . should . equal ( false ) ;
335
+ batchMerge : function ( entities , { headers } ) {
336
+ batchMergeCalled = true ;
337
+ assert . deepEqual ( entities , body . entities ) ;
333
338
assert . deepEqual ( headers , expHeaders ) ;
334
339
return new Promise ( function ( resolve ) {
335
340
resolve ( {
@@ -366,7 +371,7 @@ describe('Test libNgsildUpdates', function () {
366
371
ToTest . __set__ ( 'addSyncOnAttribute' , addSyncOnAttribute ) ;
367
372
const ngsildUpdates = new ToTest ( config ) ;
368
373
await ngsildUpdates . ngsildUpdates ( body ) ;
369
- updatePropertiesCalled . should . equal ( true ) ;
374
+ batchMergeCalled . should . equal ( true ) ;
370
375
revert ( ) ;
371
376
} ) ;
372
377
it ( 'Should post body with correct path and token for nonOverwrite upsert' , async function ( ) {
@@ -446,7 +451,7 @@ describe('Test libNgsildUpdates', function () {
446
451
revert ( ) ;
447
452
} ) ;
448
453
it ( 'Should post body with string entity' , async function ( ) {
449
- let updatePropertiesCalled = false ;
454
+ let batchMergeCalled = false ;
450
455
const config = {
451
456
ngsildUpdates : {
452
457
clientSecretVariable : 'CLIENT_SECRET' ,
@@ -481,11 +486,12 @@ describe('Test libNgsildUpdates', function () {
481
486
} ;
482
487
const Ngsild = function ( ) {
483
488
return {
484
- updateProperties : function ( { id, body, isOverwrite } , { headers } ) {
485
- updatePropertiesCalled = true ;
486
- id . should . equal ( 'id' ) ;
487
- assert . deepEqual ( body , { id : 'id' , type : 'type' } ) ;
488
- isOverwrite . should . equal ( false ) ;
489
+ batchMerge : function ( entities , { headers } ) {
490
+ batchMergeCalled = true ;
491
+ entities . forEach ( entity => {
492
+ assert . deepEqual ( entity . id , 'id' ) ;
493
+ assert . deepEqual ( entity , { id : 'id' , type : 'type' } ) ;
494
+ } ) ;
489
495
assert . deepEqual ( headers , expHeaders ) ;
490
496
return new Promise ( function ( resolve ) {
491
497
resolve ( {
@@ -524,7 +530,7 @@ describe('Test libNgsildUpdates', function () {
524
530
const ngsildUpdates = new ToTest ( config ) ;
525
531
body . entities = JSON . stringify ( body . entities ) ;
526
532
await ngsildUpdates . ngsildUpdates ( body ) ;
527
- updatePropertiesCalled . should . equal ( true ) ;
533
+ batchMergeCalled . should . equal ( true ) ;
528
534
revert ( ) ;
529
535
} ) ;
530
536
} ) ;
0 commit comments