summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--test/auth.spec.js41
1 files changed, 13 insertions, 28 deletions
diff --git a/test/auth.spec.js b/test/auth.spec.js
index bdb890a59b..c4330b4559 100644
--- a/test/auth.spec.js
+++ b/test/auth.spec.js
@@ -1,53 +1,38 @@
// @flow
-import { expect } from 'chai';
-import {
- setupIpcAndStore,
- setupBackendAndStore,
- failFast,
- checkNextTick,
-} from './helpers/ipc-helpers';
+import { expect, spy } from 'chai';
+import { setupIpcAndStore, setupBackendAndStore } from './helpers/ipc-helpers';
import { IpcChain } from './helpers/IpcChain';
import { Backend } from '../app/lib/backend';
describe('authentication', () => {
it('authenticates before ipc call if unauthenticated', (done) => {
const { store, mockIpc } = setupIpcAndStore();
- const credentials = {
- sharedSecret: 'foo',
- connectionString: '',
- };
const chain = new IpcChain(mockIpc);
+ chain.onSuccessOrFailure(done);
chain.expect('authenticate').withInputValidation((secret) => {
expect(secret).to.equal(credentials.sharedSecret);
});
-
chain.expect('connect');
- chain.onSuccessOrFailure(done);
-
+ const credentials = {
+ sharedSecret: '',
+ connectionString: '',
+ };
const backend = new Backend(store, credentials, mockIpc);
backend.connect();
});
- it('reauthenticates on reconnect', (done) => {
+ it('reauthenticates on reconnect', async () => {
const { mockIpc, backend } = setupBackendAndStore();
- let authCount = 0;
- mockIpc.authenticate = () => {
- authCount++;
- return Promise.resolve();
- };
-
+ mockIpc.authenticate = spy(mockIpc.authenticate);
mockIpc.killWebSocket();
- failFast(() => {
- expect(authCount).to.equal(0);
- }, done);
- backend.connect();
- checkNextTick(() => {
- expect(authCount).to.equal(1);
- }, done);
+ expect(mockIpc.authenticate).to.not.have.been.called();
+
+ await backend.connect();
+ expect(mockIpc.authenticate).to.have.been.called.once;
});
});