Skip to content

Commit

Permalink
wrapped remove into multiRemove
Browse files Browse the repository at this point in the history
  • Loading branch information
Nataniel López committed Sep 27, 2019
1 parent 5a38ebe commit 3afc954
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/mysql.js
Expand Up @@ -297,6 +297,17 @@ class MySQL {

}

/**
* Multi remove by fields and values
* @async
* @param {Model} model Model instance
* @param {Object} params The fields to use in where clause, invalid fields will be ignored
* @returns {Number} number of rows deleted
*/
multiRemove(model, params) {
return this.remove(model, params);
}

/**
* No need to create indexes in this Database
*/
Expand Down
21 changes: 21 additions & 0 deletions tests/mysql-test.js
Expand Up @@ -555,6 +555,27 @@ describe('MySQL module', function() {

await assert.rejects(mysql.remove(dummyModel, params), { code: MySQLError.codes.INVALID_REMOVE });
});

it('should call remove() method when multiRemove is called', async function() {
stubRemove.callsFake(() => [{ affectedRows: 1 }]);

const results = await mysql.multiRemove(dummyModel, {
filters: { id: 1 }
});

assert.strictEqual(results, 1);
sandbox.assert.calledOnce(stubRemove);
});

it('should throw when remove() rejects when mutliRemove is called', async function() {
stubRemove.rejects();

const params = {
filters: { id: 1 }
};

await assert.rejects(mysql.multiRemove(dummyModel, params), { code: MySQLError.codes.INVALID_REMOVE });
});
});

});

0 comments on commit 3afc954

Please sign in to comment.