Fixed settings unit tests

refs e04f55cce3

- added `tracker.uninstall()` so that previously set up `tracker.on()` listeners are not called by later tests
- fixed `emits edit events` test which was not correctly mocking the select and update queries
This commit is contained in:
Kevin Ansfield 2020-07-22 22:12:00 +01:00
parent 62c72cb58b
commit 6504b0f6c3

View File

@ -20,17 +20,12 @@ describe('Unit: models/settings', function () {
mockDb.mock(knex);
tracker = mockDb.getTracker();
tracker.install();
});
afterEach(function () {
mockDb.unmock(knex);
});
beforeEach(function () {
eventSpy = sinon.spy(events, 'emit');
});
afterEach(function () {
tracker.uninstall();
mockDb.unmock(knex);
sinon.restore();
});
@ -63,15 +58,15 @@ describe('Unit: models/settings', function () {
it('emits edit events', function () {
tracker.on('query', (query, step) => {
return [
function fetchEditQuery() {
query.response([{
id: 1, // NOTE: `id` imitates existing value for 'edit' event
key: 'description',
value: 'db value'
}]);
}
][step - 1]();
if (query.method === 'select') {
return query.response([{
id: 1, // NOTE: `id` imitates existing value for 'edit' event
key: 'description',
value: 'db value'
}]);
}
return query.response([{}]);
});
return models.Settings.edit({