1 import { getInitialSettings } from '@proton/pass/store/reducers/settings';
3 import { createSettingsService } from './service';
5 describe('createSettingsService', () => {
6 const clear = jest.fn();
7 const resolve = jest.fn();
8 const sync = jest.fn();
16 test('clear method should proxy `options.clear`', async () => {
17 const service = createSettingsService({ clear, resolve, sync });
18 await service.clear();
20 expect(clear).toHaveBeenCalledTimes(1);
23 test('sync method should proxy `options.sync`', async () => {
24 const update = getInitialSettings();
25 const service = createSettingsService({ clear, resolve, sync });
26 await service.sync(update);
28 expect(sync).toHaveBeenCalledTimes(1);
29 expect(sync).toHaveBeenCalledWith(update);
32 test('resolve method should merge initial settings with resolved settings', async () => {
33 const settings = { test_setting: true };
34 resolve.mockResolvedValue(settings);
36 const service = createSettingsService({ clear, resolve, sync });
37 const result = await service.resolve();
39 expect(resolve).toHaveBeenCalledTimes(1);
40 expect(result).toEqual({ ...getInitialSettings(), ...settings });
43 test('resolve should return initial settings when `options.resolve` fails', async () => {
44 resolve.mockRejectedValue(new Error());
45 const service = createSettingsService({ clear, resolve, sync });
46 const result = await service.resolve();
48 expect(resolve).toHaveBeenCalledTimes(1);
49 expect(result).toEqual(getInitialSettings());