mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-24 11:46:31 +00:00
Remove unused settings.assign function
Change-type: patch
This commit is contained in:
parent
18fdbbaabb
commit
9caa42d257
@ -49,30 +49,6 @@ export async function reset(): Promise<void> {
|
|||||||
return await localSettings.writeAll(settings);
|
return await localSettings.writeAll(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @summary Extend the current settings
|
|
||||||
*/
|
|
||||||
export async function assign(value: _.Dictionary<any>): Promise<void> {
|
|
||||||
debug('assign', value);
|
|
||||||
if (_.isNil(value)) {
|
|
||||||
throw errors.createError({
|
|
||||||
title: 'Missing settings',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_.isPlainObject(value)) {
|
|
||||||
throw errors.createError({
|
|
||||||
title: 'Settings must be an object',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const newSettings = _.assign({}, settings, value);
|
|
||||||
|
|
||||||
const updatedSettings = await localSettings.writeAll(newSettings);
|
|
||||||
// NOTE: Only update in memory settings when successfully written
|
|
||||||
settings = updatedSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @summary Extend the application state with the local settings
|
* @summary Extend the application state with the local settings
|
||||||
*/
|
*/
|
||||||
|
@ -95,34 +95,17 @@ describe('Browser: settings', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('.assign()', function() {
|
describe('.set()', function() {
|
||||||
it('should not override all settings', function() {
|
|
||||||
return settings
|
|
||||||
.assign({
|
|
||||||
foo: 'bar',
|
|
||||||
bar: 'baz',
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
expect(settings.getAll()).to.deep.equal(
|
|
||||||
_.assign({}, DEFAULT_SETTINGS, {
|
|
||||||
foo: 'bar',
|
|
||||||
bar: 'baz',
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should store the settings to the local machine', function() {
|
it('should store the settings to the local machine', function() {
|
||||||
return localSettings
|
return localSettings
|
||||||
.readAll()
|
.readAll()
|
||||||
.then(data => {
|
.then(data => {
|
||||||
expect(data.foo).to.be.undefined;
|
expect(data.foo).to.be.undefined;
|
||||||
expect(data.bar).to.be.undefined;
|
expect(data.bar).to.be.undefined;
|
||||||
|
return settings.set('foo', 'bar');
|
||||||
return settings.assign({
|
})
|
||||||
foo: 'bar',
|
.then(() => {
|
||||||
bar: 'baz',
|
return settings.set('bar', 'baz');
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.then(localSettings.readAll)
|
.then(localSettings.readAll)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
@ -140,7 +123,7 @@ describe('Browser: settings', function() {
|
|||||||
Promise.reject(new Error('localSettings error')),
|
Promise.reject(new Error('localSettings error')),
|
||||||
);
|
);
|
||||||
|
|
||||||
await checkError(settings.assign({ foo: 'baz' }), error => {
|
await checkError(settings.set('foo', 'baz'), error => {
|
||||||
expect(error).to.be.an.instanceof(Error);
|
expect(error).to.be.an.instanceof(Error);
|
||||||
expect(error.message).to.equal('localSettings error');
|
expect(error.message).to.equal('localSettings error');
|
||||||
localSettingsWriteAllStub.restore();
|
localSettingsWriteAllStub.restore();
|
||||||
@ -189,13 +172,6 @@ describe('Browser: settings', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw if setting an array', async function() {
|
|
||||||
await checkError(settings.assign([1, 2, 3]), error => {
|
|
||||||
expect(error).to.be.an.instanceof(Error);
|
|
||||||
expect(error.message).to.equal('Settings must be an object');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should set the key to undefined if no value', function() {
|
it('should set the key to undefined if no value', function() {
|
||||||
return settings
|
return settings
|
||||||
.set('foo', 'bar')
|
.set('foo', 'bar')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user