mirror of
https://github.com/balena-io/etcher.git
synced 2025-08-05 09:27:44 +00:00
Remove unused settings.assign function
Change-type: patch Changelog-entry: Remove unused settings.assign function
This commit is contained in:
parent
3706770322
commit
9ea8a6134e
@ -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<void> {
|
||||
await writeAll(settings);
|
||||
}
|
||||
|
||||
export async function assign(value: any): Promise<void> {
|
||||
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<any> {
|
||||
debug('load');
|
||||
const loadedSettings = await readAll();
|
||||
|
@ -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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user