Deleted SettingsService, as the task is not transparently handled by a redux middleware

This commit is contained in:
Alejandro Celaya 2020-04-26 19:07:47 +02:00
parent 86bf1515d4
commit 7dd6a31609
3 changed files with 0 additions and 64 deletions

View file

@ -1,14 +0,0 @@
const SETTINGS_STORAGE_KEY = 'settings';
export default class SettingsService {
constructor(storage) {
this.storage = storage;
}
loadSettings = () => this.storage.get(SETTINGS_STORAGE_KEY) || {};
updateSettings = (settingsToUpdate) => this.storage.set(SETTINGS_STORAGE_KEY, {
...this.loadSettings(),
...settingsToUpdate,
})
}

View file

@ -1,7 +1,6 @@
import RealTimeUpdates from '../RealTimeUpdates';
import Settings from '../Settings';
import { setRealTimeUpdates } from '../reducers/settings';
import SettingsService from './SettingsService';
const provideServices = (bottle, connect) => {
// Components
@ -10,9 +9,6 @@ const provideServices = (bottle, connect) => {
bottle.serviceFactory('RealTimeUpdates', () => RealTimeUpdates);
bottle.decorator('RealTimeUpdates', connect([ 'settings' ], [ 'setRealTimeUpdates' ]));
// Services
bottle.service('SettingsService', SettingsService, 'Storage');
// Actions
bottle.serviceFactory('setRealTimeUpdates', () => setRealTimeUpdates);
};

View file

@ -1,46 +0,0 @@
import SettingsService from '../../../src/settings/services/SettingsService';
describe('SettingsService', () => {
const settings = { foo: 'bar' };
const createService = (withSettings = true) => {
const storageMock = {
set: jest.fn(),
get: jest.fn(() => withSettings ? settings : undefined),
};
const service = new SettingsService(storageMock);
return [ service, storageMock ];
};
afterEach(jest.resetAllMocks);
describe('loadSettings', () => {
it.each([
[ false, {}],
[ true, settings ],
])('returns result if found in storage', (withSettings, expectedResult) => {
const [ service, storageMock ] = createService(withSettings);
const result = service.loadSettings();
expect(result).toEqual(expectedResult);
expect(storageMock.get).toHaveBeenCalledTimes(1);
expect(storageMock.set).not.toHaveBeenCalled();
});
});
describe('updateSettings', () => {
it.each([
[ false, { hi: 'goodbye' }, { hi: 'goodbye' }],
[ true, { hi: 'goodbye' }, { foo: 'bar', hi: 'goodbye' }],
[ true, { foo: 'goodbye' }, { foo: 'goodbye' }],
])('appends provided data to existing settings', (withSettings, settingsToUpdate, expectedResult) => {
const [ service, storageMock ] = createService(withSettings);
service.updateSettings(settingsToUpdate);
expect(storageMock.get).toHaveBeenCalledTimes(1);
expect(storageMock.set).toHaveBeenCalledWith(expect.anything(), expectedResult);
});
});
});