chore: add test for atomic upsertWithWhere (#1864)
Introduce the new property atomicUpsertWithWhere for connector that implement specific method. See https://github.com/strongloop/loopback-connector-mongodb/pull/563 for mongodb implementation. Signed-off-by: Matteo Padovano <mrbatista@users.noreply.github.com>
This commit is contained in:
parent
261dd1c865
commit
76acf333fd
|
@ -2624,7 +2624,8 @@ describe('manipulation', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('fails the upsertWithWhere operation when multiple instances are ' +
|
||||
bdd.itIf(connectorCapabilities.atomicUpsertWithWhere !== true,
|
||||
'fails the upsertWithWhere operation when multiple instances are ' +
|
||||
'retrieved based on the filter criteria', function(done) {
|
||||
Person.create([
|
||||
{id: '2', name: 'Howie', city: 'Florida'},
|
||||
|
@ -2641,6 +2642,26 @@ describe('manipulation', function() {
|
|||
});
|
||||
});
|
||||
|
||||
bdd.itIf(connectorCapabilities.atomicUpsertWithWhere === true,
|
||||
'upsertWithWhere update the first matching instance when multiple instances are ' +
|
||||
'retrieved based on the filter criteria', async () => {
|
||||
// The first matching instance is determinate from specific connector implementation
|
||||
// For example for mongodb connector the sort parameter is used (default to _id asc)
|
||||
await Person.create([
|
||||
{id: '4', name: 'Howie', city: 'Turin'},
|
||||
{id: '3', name: 'Kevin', city: 'Turin'},
|
||||
]);
|
||||
await Person.upsertWithWhere({city: 'Turin'}, {name: 'Brian'});
|
||||
|
||||
const updatedInstance = await Person.findById('3');
|
||||
should.exist(updatedInstance);
|
||||
updatedInstance.name.should.equal('Brian');
|
||||
|
||||
const notUpdatedInstance = await Person.findById('4');
|
||||
should.exist(notUpdatedInstance);
|
||||
notUpdatedInstance.name.should.equal('Howie');
|
||||
});
|
||||
|
||||
it('updates the record when one matching instance is found ' +
|
||||
'based on the filter criteria', function(done) {
|
||||
Person.create([
|
||||
|
|
Loading…
Reference in New Issue