Remove unused settings.assign function

Change-type: patch
This commit is contained in:
Alexis Svinartchouk 2020-01-30 16:07:55 +01:00
parent 18fdbbaabb
commit 9caa42d257
2 changed files with 6 additions and 54 deletions

View File

@ -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
*/ */

View File

@ -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')