Skip to content

Commit 677c8ec

Browse files
committed
feat(account): replace store service with disk cache service and update account service methods
1 parent 3cfc147 commit 677c8ec

File tree

5 files changed

+176
-224
lines changed

5 files changed

+176
-224
lines changed

electron/main/account/__tests__/account-instance.test.ts

+26-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
import { afterEach, describe, expect, it, vi } from 'vitest';
22
import { AccountServiceImpl } from '../account.service.js';
33

4-
const { mockStoreService, mockGetStoreForPath } = await vi.hoisted(async () => {
5-
const storeServiceMockModule = await import(
6-
'../../store/__mocks__/store-service.mock.js'
7-
);
4+
const { mockCacheService, mockCacheServiceConstructorSpy } = await vi.hoisted(
5+
async () => {
6+
const cacheServiceMockModule = await import(
7+
'../../cache/__mocks__/cache-service.mock.js'
8+
);
9+
10+
const mockCacheService = new cacheServiceMockModule.CacheServiceMockImpl();
11+
12+
return {
13+
mockCacheService,
14+
mockCacheServiceConstructorSpy: vi.fn(),
15+
};
16+
}
17+
);
18+
19+
vi.mock('../../cache/disk-cache.service.js', async () => {
20+
class MyDiskCacheService {
21+
constructor(...args: any) {
22+
mockCacheServiceConstructorSpy(...args);
23+
return mockCacheService;
24+
}
25+
}
826

9-
const mockStoreService = new storeServiceMockModule.StoreServiceMockImpl();
10-
11-
const mockGetStoreForPath = vi.fn();
12-
13-
return { mockStoreService, mockGetStoreForPath };
14-
});
15-
16-
vi.mock('../../store/store.instance.ts', () => {
1727
return {
18-
getStoreForPath: mockGetStoreForPath.mockReturnValue(mockStoreService),
28+
DiskCacheServiceImpl: MyDiskCacheService,
1929
};
2030
});
2131

@@ -40,6 +50,8 @@ describe('account-instance', () => {
4050

4151
expect(Accounts).toBeInstanceOf(AccountServiceImpl);
4252

43-
expect(mockGetStoreForPath).toHaveBeenCalledWith('userData/accounts.json');
53+
expect(mockCacheServiceConstructorSpy).toHaveBeenCalledWith({
54+
filePath: 'userData/accounts.json',
55+
});
4456
});
4557
});

0 commit comments

Comments
 (0)