diff options
| author | Erik Larkö <erik@mullvad.net> | 2017-07-12 12:40:08 +0200 |
|---|---|---|
| committer | Erik Larkö <erik@mullvad.net> | 2017-07-12 12:40:08 +0200 |
| commit | 3c90223a90edd20aafbc042c54922c9f92fb6ad1 (patch) | |
| tree | 12fb3b99804212b39f2c36d380b854a8f451e65a | |
| parent | 431ea108879abd1254420ba58ef7aeab94054abd (diff) | |
| parent | e69586ccaa640278a19914883e1aa54e318eb1fe (diff) | |
| download | mullvadvpn-3c90223a90edd20aafbc042c54922c9f92fb6ad1.tar.xz mullvadvpn-3c90223a90edd20aafbc042c54922c9f92fb6ad1.zip | |
Merge branch 'refactor-ipcchain'
| -rw-r--r-- | test/autologin.spec.js | 8 | ||||
| -rw-r--r-- | test/connect.spec.js | 8 | ||||
| -rw-r--r-- | test/helpers/IpcChain.js | 9 | ||||
| -rw-r--r-- | test/login.spec.js | 8 | ||||
| -rw-r--r-- | test/logout.spec.js | 7 |
5 files changed, 25 insertions, 15 deletions
diff --git a/test/autologin.spec.js b/test/autologin.spec.js index 43e5bfa333..b8d4aa8356 100644 --- a/test/autologin.spec.js +++ b/test/autologin.spec.js @@ -11,17 +11,19 @@ describe('autologin', () => { const randomAccountNumber = '12345'; - const chain = new IpcChain(mockIpc, done); - chain.addRequiredStep('getAccount') + const chain = new IpcChain(mockIpc); + chain.require('getAccount') .withReturnValue(randomAccountNumber) .done(); - chain.addRequiredStep('getAccountData') + chain.require('getAccountData') .withInputValidation((num) => { expect(num).to.equal(randomAccountNumber); }) .done(); + chain.onSuccessOrFailure(done); + backend.autologin(); }); diff --git a/test/connect.spec.js b/test/connect.spec.js index 13f4bef78a..6f7069f2c0 100644 --- a/test/connect.spec.js +++ b/test/connect.spec.js @@ -10,16 +10,18 @@ describe('connect', () => { it('should invoke set_country and then connect in the backend', (done) => { const { store, mockIpc, backend } = setupBackendAndStore(); - const chain = new IpcChain(mockIpc, done); - chain.addRequiredStep('setCountry') + const chain = new IpcChain(mockIpc); + chain.require('setCountry') .withInputValidation( (country) => expect(country).to.equal('example.com') ) .done(); - chain.addRequiredStep('connect') + chain.require('connect') .done(); + chain.onSuccessOrFailure(done); + store.dispatch(connectionActions.connect(backend, 'example.com')); }); diff --git a/test/helpers/IpcChain.js b/test/helpers/IpcChain.js index 247ea0526b..a7916e1e9f 100644 --- a/test/helpers/IpcChain.js +++ b/test/helpers/IpcChain.js @@ -9,14 +9,13 @@ export class IpcChain { _mockIpc: {}; _done: (*) => void; - constructor(mockIpc: {}, done: (*) => void) { + constructor(mockIpc: {}) { this._expectedCalls = []; this._recordedCalls = []; this._mockIpc = mockIpc; - this._done = done; } - addRequiredStep(ipcCall: string): StepBuilder { + require(ipcCall: string): StepBuilder { this._expectedCalls.push(ipcCall); return new StepBuilder(ipcCall, this._addStep.bind(this)); } @@ -55,6 +54,10 @@ export class IpcChain { _registerCall(ipcCall: string) { this._recordedCalls.push(ipcCall); } + + onSuccessOrFailure(done: (*) => void) { + this._done = done; + } } class StepBuilder { diff --git a/test/login.spec.js b/test/login.spec.js index 3d7a1ed0d1..f220eb25a7 100644 --- a/test/login.spec.js +++ b/test/login.spec.js @@ -10,19 +10,21 @@ describe('Logging in', () => { it('should validate the account number and then set it in the backend', (done) => { const { store, mockIpc, backend } = setupBackendAndStore(); - const chain = new IpcChain(mockIpc, done); - chain.addRequiredStep('getAccountData') + const chain = new IpcChain(mockIpc); + chain.require('getAccountData') .withInputValidation((an) => { expect(an).to.equal('123'); }) .done(); - chain.addRequiredStep('setAccount') + chain.require('setAccount') .withInputValidation((an) => { expect(an).to.equal('123'); }) .done(); + chain.onSuccessOrFailure(done); + const action: any = accountActions.login(backend, '123'); store.dispatch(action); }); diff --git a/test/logout.spec.js b/test/logout.spec.js index c3f51e6c4f..f88df1bbc6 100644 --- a/test/logout.spec.js +++ b/test/logout.spec.js @@ -10,14 +10,15 @@ describe('logging out', () => { it('should set the account to the empty string and then disconnect', (done) => { const { mockIpc, backend } = setupBackendAndStore(); - const chain = new IpcChain(mockIpc, done); - chain.addRequiredStep('setAccount') + const chain = new IpcChain(mockIpc); + chain.require('setAccount') .withInputValidation((num) => { expect(num).to.equal(''); }) .done(); - chain.addRequiredStep('disconnect') + chain.require('disconnect') .done(); + chain.onSuccessOrFailure(done); backend.logout(); }); |
