Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
readSettings: async (t) => {
const {
endpoints,
mocks: {
"src/electron-main/keytar": {setPassword: setPasswordSpy, deletePassword: deletePasswordSpy},
"src/electron-main/storage-upgrade": {upgradeSettings: upgradeSettingsSpy},
"src/electron-main/session": {initSessionByAccount: initSessionByAccountMock},
},
} = t.context;
t.false(await t.context.ctx.settingsStore.readable(), "settings file does not exist");
t.falsy(t.context.ctx.settingsStore.adapter, "adapter is not set");
const initial = await readConfigAndSettings(endpoints, {password: OPTIONS.masterPassword, savePassword: false});
t.is(0, upgradeSettingsSpy.callCount);
t.is(t.context.ctx.settingsStore.adapter && t.context.ctx.settingsStore.adapter.constructor.name,
EncryptionAdapter.name,
"adapter is an EncryptionAdapter",
);
const initialExpected = {...t.context.ctx.initialStores.settings, ...{_rev: 0}};
t.deepEqual(initial, initialExpected, "checking initial settings file");
t.true(await t.context.ctx.settingsStore.readable(), "settings file exists");
t.is(setPasswordSpy.callCount, 0);
t.is(deletePasswordSpy.callCount, 1);
t.true(deletePasswordSpy.alwaysCalledWithExactly());
t.is(initial.accounts.length, initSessionByAccountMock.callCount);
for (const {login} of initial.accounts) {
t.true(initSessionByAccountMock.calledWithExactly(t.context.ctx, login));
}
const initialUpdated = await t.context.ctx.settingsStore.write(initial);
const initialUpdatedExpected = {...initial, ...initialExpected, ...{_rev: initialExpected._rev + 1}};
t.deepEqual(initialUpdated, initialUpdatedExpected, "saved initial settings file");