Skip to content

Commit

Permalink
Merge 92bec07 into 4ce1e3b
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Oct 4, 2019
2 parents 4ce1e3b + 92bec07 commit 1ce3f08
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions lib/models/updateAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ function doRequestV2(action, event, token, callback) {
//
// 2. Apply update to all entities in a batch
//
connection.v2.batchUpdate(changes, { upsert: true }).then(
connection.v2.batchUpdate(changes).then(
(response) => {
// Entities updated successfully
// response.correlator transaction id associated with the server response
Expand Down Expand Up @@ -447,9 +447,10 @@ function doRequestV2(action, event, token, callback) {
var changes = processOptionParams(action, event);
metrics.IncMetrics(event.service, event.subservice, metrics.actionEntityUpdate);
logger.debug('entity to update: %j', changes);
// FIXME: createEntity with upsert true is always updating entity, but is not using params.actionType (append or update)
// Maybe other methods like v2.updateEntityAttributes is more proper ?
connection.v2.createEntity(changes, { upsert: true }).then(
var updateOptions = {
upsert: action.parameters.actionType === 'append' ? true : false
};
connection.v2.createEntity(changes, updateOptions).then(
(response) => {
// response.correlator transaction id associated with the server response
metrics.IncMetrics(event.service, event.subservice, metrics.okActionEntityUpdate);
Expand Down
8 changes: 4 additions & 4 deletions test/unit/updateAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ describe('doIt', function() {
should.equal(request.httpCode, 200);
expectedChanges.id = 'AmbientLightSensor:1_NGSIv2Test';
expectedChanges.type = 'NGSIv2TypesTest';
createEntityMock.should.be.calledOnceWith(expectedChanges, { upsert: true });
createEntityMock.should.be.calledOnceWith(expectedChanges, { upsert: false });
done();
};
action1.parameters.id = '${id}_NGSIv2Test';
Expand Down Expand Up @@ -379,7 +379,7 @@ describe('doIt', function() {
should.equal(request.httpCode, 200);
expectedChanges.id = 'AmbientLightSensor:1';
expectedChanges.type = 'AmbientLightSensor';
createEntityMock.should.be.calledOnceWith(expectedChanges, { upsert: true });
createEntityMock.should.be.calledOnceWith(expectedChanges, { upsert: false });
done();
};
delete action1.parameters.id;
Expand Down Expand Up @@ -419,7 +419,7 @@ describe('doIt', function() {
e.should.be.instanceof(Error);
expectedChanges.id = 'AmbientLightSensor:1_NGSIv2Test';
expectedChanges.type = 'NGSIv2TypesTest';
createEntityMock.should.be.calledOnceWith(expectedChanges, { upsert: true });
createEntityMock.should.be.calledOnceWith(expectedChanges, { upsert: false });
done();
};
action1.parameters.id = '${id}_NGSIv2Test';
Expand Down Expand Up @@ -470,7 +470,7 @@ describe('doIt', function() {
should.equal(request.httpCode, 200);
queryOptions.type = 'NGSIv2TypesTest2';
listEntitiesMock.should.be.calledOnceWith(queryOptions);
batchUpdateMock.should.be.calledOnceWith(expectedChanges2, { upsert: true });
batchUpdateMock.should.be.calledOnceWith(expectedChanges2);
done();
};
action1.parameters.type = 'NGSIv2TypesTest2';
Expand Down

0 comments on commit 1ce3f08

Please sign in to comment.