Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 3bcfdf4

Browse files
committed
Add unit tests for new LogAction functionality.
1 parent a1e1950 commit 3bcfdf4

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

src/action/log.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export function error(...args) {
5757
* @return {string}
5858
*/
5959
export function getLogPath(network) {
60+
if (!_FS) {
61+
throw new Error('Cannot get log path with no FS in action/log.js');
62+
}
6063
const lndDir = _FS.DocumentDirectoryPath;
6164
return `${lndDir}/logs/bitcoin/${network}/lnd.log`;
6265
}
@@ -68,7 +71,7 @@ export function getLogPath(network) {
6871
export function getLogs() {
6972
if (!_FS) {
7073
return Promise.reject(
71-
'Cannot get logs when no filesystem is available in action/log.js'
74+
new Error('Cannot get logs with no FS in action/log.js')
7275
);
7376
}
7477
return _FS.readFile(getLogPath(_store.network), 'utf8');
@@ -81,7 +84,7 @@ export function getLogs() {
8184
export async function shareLogs() {
8285
if (!_Share) {
8386
return Promise.reject(
84-
'Cannot share logs with no Share library in action/log.js'
87+
new Error('Cannot share logs with no Share in action/log.js')
8588
);
8689
}
8790
const logs = await getLogs();

test/unit/action/log.spec.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ describe('Action Logs Unit Tests', () => {
1010
let ipc;
1111
let ipcRenderer;
1212

13+
const RNFS = {
14+
DocumentDirectoryPath: '/foo/bar',
15+
readFile: () => Promise.resolve('logs'),
16+
};
17+
const Share = {
18+
share: () => Promise.resolve(true),
19+
};
20+
1321
beforeEach(() => {
1422
sandbox = sinon.createSandbox({});
1523
ipcRenderer = {
@@ -115,5 +123,38 @@ describe('Action Logs Unit Tests', () => {
115123
expect(store.logs.length, 'to equal', 56);
116124
});
117125
});
126+
127+
describe('getLogPath()', () => {
128+
it('should throw without a FS constructor argument', () => {
129+
expect(() => log.getLogPath(), 'to throw');
130+
});
131+
132+
it('should return a log path with FS constructor argument', () => {
133+
new LogAction(store, ipc, false, RNFS);
134+
expect(log.getLogPath(), 'to be a string');
135+
});
136+
});
137+
138+
describe('getLogs()', () => {
139+
it('should throw without a FS constructor argument', async () => {
140+
await expect(log.getLogs(), 'to be rejected');
141+
});
142+
143+
it('should return logs with an FS constructor argument', async () => {
144+
new LogAction(store, ipc, false, RNFS);
145+
expect(await log.getLogs(), 'to be a string');
146+
});
147+
});
148+
149+
describe('shareLogs()', () => {
150+
it('should throw without a Share or FS constructor argument', async () => {
151+
await expect(log.shareLogs(), 'to be rejected');
152+
});
153+
154+
it('should share the logs with a Share and FS constructor argument', async () => {
155+
new LogAction(store, ipc, false, RNFS, Share);
156+
expect(await log.shareLogs(), 'to be ok');
157+
});
158+
});
118159
});
119160
});

0 commit comments

Comments
 (0)