forked from gitify-app/gitify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.test.ts
More file actions
43 lines (34 loc) · 1.13 KB
/
storage.test.ts
File metadata and controls
43 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { EVENTS } from '../../shared/events';
import { registerStorageHandlers } from './storage';
const handleMock = vi.fn();
vi.mock('electron', () => ({
ipcMain: {
handle: (...args: unknown[]) => handleMock(...args),
},
safeStorage: {
encryptString: vi.fn((str: string) => Buffer.from(str)),
decryptString: vi.fn((buf: Buffer) => buf.toString()),
},
}));
const logErrorMock = vi.fn();
vi.mock('../../shared/logger', () => ({
logError: (...args: unknown[]) => logErrorMock(...args),
}));
describe('main/handlers/storage.ts', () => {
beforeEach(() => {
vi.clearAllMocks();
});
describe('registerStorageHandlers', () => {
it('registers handlers without throwing', () => {
expect(() => registerStorageHandlers()).not.toThrow();
});
it('registers expected storage IPC event handlers', () => {
registerStorageHandlers();
const registeredHandlers = handleMock.mock.calls.map(
(call: [string]) => call[0],
);
expect(registeredHandlers).toContain(EVENTS.SAFE_STORAGE_ENCRYPT);
expect(registeredHandlers).toContain(EVENTS.SAFE_STORAGE_DECRYPT);
});
});
});