This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(unit): test Controller.startLightningWallet
Add unit tests to verify that ZapController.startLightningWallet() behaves as expected.
- Loading branch information
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) | ||
}) | ||
}) |