Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #736 from mrfelton/fix/show-connection-errors
Browse files Browse the repository at this point in the history
fix(grpc): ensure connection errors show onscreen
  • Loading branch information
JimmyMow authored Sep 4, 2018
2 parents addce36 + e8dd544 commit 994d361
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/lib/zap/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class ZapController {
this.sendMessage('lightningGrpcActive')
} catch (err) {
mainLog.warn('Unable to connect to Lighitnng gRPC interface: %o', err)
throw err
}
}

Expand Down
5 changes: 4 additions & 1 deletion test/unit/__mocks__/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ module.exports = {
},
remote: jest.fn(),
dialog: jest.fn(),
BrowserWindow: jest.fn()
BrowserWindow: jest.fn(),
ipcMain: {
on: jest.fn()
}
}
54 changes: 54 additions & 0 deletions test/unit/zap/controller.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import ZapController from 'lib/zap/controller'
import LndConfig from 'lib/lnd/config'

jest.mock('lib/lnd/lightning')
const Lightning = require('lib/lnd/lightning')

describe('ZapController', function() {
describe('Constructor', () => {
beforeAll(() => {
this.controller = new ZapController()
})

describe('initial values', () => {
it('should set the "lndConfig" property to a new LndConfig instance', () => {
expect(this.controller.lndConfig).toBeInstanceOf(LndConfig)
})
it('should set the "splashScreenTime" property to 500', () => {
expect(this.controller.splashScreenTime).toEqual(500)
})
it('should set the "mainWindow" property to undefined', () => {
expect(this.controller.mainWindow).toBeUndefined()
})
})
})

describe('.startLightningWallet', () => {
describe('successful connection', () => {
beforeEach(() => {
Lightning.mockImplementation(() => ({
subscribe: jest.fn(),
connect: jest.fn().mockResolvedValue()
}))
this.controller = new ZapController()
})
it('should resolve with undefined', async () => {
await expect(this.controller.startLightningWallet()).resolves.toBeUndefined()
expect(this.controller.lightning.subscribe).toHaveBeenCalled()
})
})
describe('unsuccessful connection', () => {
beforeEach(() => {
Lightning.mockImplementation(() => ({
subscribe: jest.fn(),
connect: jest.fn().mockRejectedValue(new Error('Async error'))
}))
this.controller = new ZapController()
})
it('should reject an error', async () => {
await expect(this.controller.startLightningWallet()).rejects.toThrow('Async error')
expect(this.controller.lightning.subscribe).not.toHaveBeenCalled()
})
})
})
})

0 comments on commit 994d361

Please sign in to comment.