Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nataniel López committed Sep 11, 2019
1 parent da716f0 commit ee91320
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,37 @@ describe('Model', () => {
sandbox.assert.calledOnce(DBDriver.get);
sandbox.assert.calledWithExactly(DBDriver.get, myClientModel, { readonly: true });
});

[
'insert',
'multiInsert',
'update',
'save',
'multiSave',
'remove',
'multiRemove'

].forEach(async method => {

it(`should call DBDriver using write DB when ${method} is executed after a readonly get`, async () => {

const myClientModel = new clientModel(); // eslint-disable-line

myClientModel.client = client;

await myClientModel.get({ readonly: true });

// for debug use: DatabaseDispatcher.getDatabaseByClient.getCall(0).args
sandbox.assert.calledOnce(DatabaseDispatcher.getDatabaseByClient);
sandbox.assert.calledWithExactly(DatabaseDispatcher.getDatabaseByClient, client, true);

await myClientModel[method]({ foo: 'bar' });

// for debug use: DatabaseDispatcher.getDatabaseByClient.getCall(2).args
sandbox.assert.calledTwice(DatabaseDispatcher.getDatabaseByClient);
sandbox.assert.calledWithExactly(DatabaseDispatcher.getDatabaseByClient, client, false);
});
});
});

it('should admit object result from model', async function() {
Expand Down

0 comments on commit ee91320

Please sign in to comment.