From 9ea8a6134e26248774e28cc3af07781b1df9625b Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Fri, 21 Jun 2019 14:44:14 +0200 Subject: [PATCH] Remove unused settings.assign function Change-type: patch Changelog-entry: Remove unused settings.assign function --- lib/gui/app/models/settings.ts | 13 +----- tests/gui/models/settings.spec.js | 67 ------------------------------- 2 files changed, 1 insertion(+), 79 deletions(-) diff --git a/lib/gui/app/models/settings.ts b/lib/gui/app/models/settings.ts index 03ad5090..3f649cf2 100644 --- a/lib/gui/app/models/settings.ts +++ b/lib/gui/app/models/settings.ts @@ -15,7 +15,7 @@ */ import * as debug_ from 'debug'; -import { cloneDeep, isPlainObject } from 'lodash'; +import { cloneDeep } from 'lodash'; import { createError } from '../modules/errors'; import { Dict } from '../modules/utils'; @@ -48,17 +48,6 @@ export async function reset(): Promise { await writeAll(settings); } -export async function assign(value: any): Promise { - debug('assign', value); - if (!isPlainObject(value)) { - throw createError({ title: 'Settings must be an object' }); - } - const newSettings = { ...settings, ...value }; - const updatedSettings = await writeAll(newSettings); - // NOTE: Only update in memory settings when successfully written - settings = updatedSettings; -} - export async function load(): Promise { debug('load'); const loadedSettings = await readAll(); diff --git a/tests/gui/models/settings.spec.js b/tests/gui/models/settings.spec.js index 93a61ee9..21dec4b6 100644 --- a/tests/gui/models/settings.spec.js +++ b/tests/gui/models/settings.spec.js @@ -73,63 +73,6 @@ describe('Browser: settings', function () { }) }) - describe('.assign()', function () { - it('should throw if no settings', async () => { - try { - await settings.assign() - m.chai.expect(true).to.be.false - } catch (error) { - m.chai.expect(error).to.be.an.instanceof(Error) - m.chai.expect(error.message).to.equal('Settings must be an object') - } - }) - - it('should not override all settings', function () { - return settings.assign({ - foo: 'bar', - bar: 'baz' - }).then(() => { - m.chai.expect(settings.getAll()).to.deep.equal(_.assign({}, DEFAULT_SETTINGS, { - foo: 'bar', - bar: 'baz' - })) - }) - }) - - it('should store the settings to the local machine', function () { - return localSettings.readAll().then((data) => { - m.chai.expect(data.foo).to.be.undefined - m.chai.expect(data.bar).to.be.undefined - - return settings.assign({ - foo: 'bar', - bar: 'baz' - }) - }).then(localSettings.readAll).then((data) => { - m.chai.expect(data.foo).to.equal('bar') - m.chai.expect(data.bar).to.equal('baz') - }) - }) - - it('should not change the application state if storing to the local machine results in an error', async () => { - await settings.set('foo', 'bar') - m.chai.expect(settings.get('foo')).to.equal('bar') - - const localSettingsWriteAllStub = m.sinon.stub(localSettings, 'writeAll') - localSettingsWriteAllStub.returns(Promise.reject(new Error('localSettings error'))) - - try { - await settings.assign({ foo: 'baz' }) - m.chai.expect(true).to.be.false - } catch (error) { - m.chai.expect(error).to.be.an.instanceof(Error) - m.chai.expect(error.message).to.equal('localSettings error') - } - localSettingsWriteAllStub.restore() - m.chai.expect(settings.get('foo')).to.equal('bar') - }) - }) - describe('.load()', function () { it('should extend the application state with the local settings content', function () { const object = { @@ -182,16 +125,6 @@ describe('Browser: settings', function () { } }) - it('should throw if setting an array', async () => { - try { - await settings.assign([ 1, 2, 3 ]) - m.chai.expect(true).to.be.false - } catch (error) { - m.chai.expect(error).to.be.an.instanceof(Error) - m.chai.expect(error.message).to.equal('Settings must be an object') - } - }) - it('should set the key to undefined if no value', function () { return settings.set('foo', 'bar').then(() => { m.chai.expect(settings.get('foo')).to.equal('bar')