|
| 1 | +import { Store } from '../../../src/store'; |
| 2 | +import FileAction from '../../../src/action/file-mobile'; |
| 3 | +import * as logger from '../../../src/action/log'; |
| 4 | + |
| 5 | +describe('Action File Mobile Unit Tests', () => { |
| 6 | + let store; |
| 7 | + let sandbox; |
| 8 | + let RNFS; |
| 9 | + let Share; |
| 10 | + let file; |
| 11 | + |
| 12 | + beforeEach(() => { |
| 13 | + sandbox = sinon.createSandbox({}); |
| 14 | + sandbox.stub(logger); |
| 15 | + store = new Store(); |
| 16 | + RNFS = { |
| 17 | + DocumentDirectoryPath: '/foo/bar', |
| 18 | + readFile: sinon.stub().resolves('some-logs'), |
| 19 | + unlink: sinon.stub().resolves(), |
| 20 | + }; |
| 21 | + Share = { |
| 22 | + share: sinon.stub().resolves(), |
| 23 | + }; |
| 24 | + file = new FileAction(store, RNFS, Share); |
| 25 | + }); |
| 26 | + |
| 27 | + afterEach(() => { |
| 28 | + sandbox.restore(); |
| 29 | + }); |
| 30 | + |
| 31 | + describe('getLndDir()', () => { |
| 32 | + it('should get lnd directory', () => { |
| 33 | + const path = file.getLndDir(); |
| 34 | + expect(path, 'to equal', '/foo/bar'); |
| 35 | + }); |
| 36 | + }); |
| 37 | + |
| 38 | + describe('readLogs()', () => { |
| 39 | + it('should read log file contents', async () => { |
| 40 | + store.network = 'mainnet'; |
| 41 | + const logs = await file.readLogs(); |
| 42 | + expect(logs, 'to equal', 'some-logs'); |
| 43 | + expect( |
| 44 | + RNFS.readFile, |
| 45 | + 'was called with', |
| 46 | + '/foo/bar/logs/bitcoin/mainnet/lnd.log', |
| 47 | + 'utf8' |
| 48 | + ); |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + describe('shareLogs()', () => { |
| 53 | + beforeEach(() => { |
| 54 | + sandbox.stub(file, 'readLogs'); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should invoke the native share api', async () => { |
| 58 | + file.readLogs.resolves('some-logs'); |
| 59 | + await file.shareLogs(); |
| 60 | + expect(Share.share, 'was called with', { |
| 61 | + title: 'Lightning App logs', |
| 62 | + message: 'some-logs', |
| 63 | + }); |
| 64 | + }); |
| 65 | + |
| 66 | + it('should log error if sharing fails', async () => { |
| 67 | + file.readLogs.rejects(new Error('Boom!')); |
| 68 | + await file.shareLogs(); |
| 69 | + expect(logger.error, 'was called once'); |
| 70 | + }); |
| 71 | + }); |
| 72 | + |
| 73 | + describe('deleteWalletDB()', () => { |
| 74 | + it('should delete wallet db file', async () => { |
| 75 | + await file.deleteWalletDB('mainnet'); |
| 76 | + expect( |
| 77 | + RNFS.unlink, |
| 78 | + 'was called with', |
| 79 | + '/foo/bar/data/chain/bitcoin/mainnet/wallet.db' |
| 80 | + ); |
| 81 | + }); |
| 82 | + |
| 83 | + it('should log error if deleting fails', async () => { |
| 84 | + RNFS.unlink.rejects(new Error('Boom!')); |
| 85 | + await file.deleteWalletDB('mainnet'); |
| 86 | + expect(logger.info, 'was called once'); |
| 87 | + }); |
| 88 | + }); |
| 89 | +}); |
0 commit comments