-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.js
More file actions
47 lines (38 loc) · 1.41 KB
/
Copy pathindex.test.js
File metadata and controls
47 lines (38 loc) · 1.41 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
44
45
46
47
const IRestore = require('./index');
const pty = require('node-pty');
describe('irestore', () => {
afterEach(() => {
jest.restoreAllMocks();
});
it('exports the correct methods', () => {
const iRestore = new IRestore('xxx');
expect(iRestore.ls).toEqual(expect.any(Function));
expect(iRestore.restore).toEqual(expect.any(Function));
expect(iRestore.unrestore).toEqual(expect.any(Function));
expect(iRestore.dumpKeys).toEqual(expect.any(Function));
expect(iRestore.encryptKeys).toEqual(expect.any(Function));
expect(iRestore.apps).toEqual(expect.any(Function));
});
it('launches a pty if a password is provided', async () => {
const callbacks = {};
const ptyProcess = {
onData: jest.fn((cb) => {
callbacks.data = cb;
}),
onExit: jest.fn((cb) => {
callbacks.exit = cb;
}),
write: jest.fn(),
kill: jest.fn(),
};
jest.spyOn(IRestore.prototype, '_resolveBinaryPath').mockReturnValue('irestore');
jest.spyOn(pty, 'spawn').mockReturnValue(ptyProcess);
const iRestore = new IRestore('xxx', '123');
const pending = iRestore.apps();
expect(pty.spawn).toBeCalledWith('irestore', ['xxx', 'apps'], expect.any(Object));
callbacks.data('Backup Password: ');
expect(ptyProcess.write).toBeCalledWith('123\r');
callbacks.exit({ exitCode: 0 });
await expect(pending).resolves.toContain('Backup Password:');
});
});