Skip to content

Commit

Permalink
Merge pull request #17 from blockchain-certificates/fix/auto-verify-null
Browse files Browse the repository at this point in the history
fix(autoVerify): [#16] prevent triggering verification process if certificate is not valid
  • Loading branch information
Julien Fraichot authored Nov 13, 2018
2 parents ede9c24 + 84cbccd commit 466a2b3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/actions/updateCertificateDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ export default function updateCertificateDefinition (definition) {

domain.events.dispatch(CERTIFICATE_EVENTS.CERTIFICATE_LOAD, certificateDefinition);

await dispatch(autoVerify());
if (certificateDefinition != null) {
await dispatch(autoVerify());
}
};
}

function autoVerify () {
return async function (dispatch, getState) {
if (!getDisableAutoVerify(getState())) {
dispatch({
type: 'AUTO_VERIFY'
type: ACTIONS.AUTO_VERIFY
});
await dispatch(verifyCertificate());
}
Expand Down
1 change: 1 addition & 0 deletions src/constants/actionTypes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const AUTO_VERIFY = 'AUTO_VERIFY';
export const INITIALIZE = 'INITIALIZE';
export const UPDATE_CERTIFICATE_DEFINITION = 'UPDATE_CERTIFICATE_DEFINITION';
export const UPLOAD_CERTIFICATE_DEFINITION = 'UPLOAD_CERTIFICATE_DEFINITION';
Expand Down
53 changes: 32 additions & 21 deletions test/application/actions/updateCertificateDefinition.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,27 @@ import notACertificateDefinition from '../../fixtures/not-a-certificate-definiti
import initialValidCertificateStepsAssertions from '../../assertions/initialValidCertificateSteps';
import validCertificateSteps from '../../assertions/validCertificateSteps';
import validCertificate from '../../assertions/validCertificate';
import { getVerificationHasStarted } from '../../../src/selectors/verification';

jest.mock('../../../src/helpers/stepQueue');

describe('updateCertificateDefinition action creator test suite', function () {
let store;
describe('given it is dispatched with a certificate definition', function () {
let store;

beforeEach(function () {
const initialState = getInitialState({ disableAutoVerify: true });
store = configureStore(initialState);
});
beforeEach(function () {
// for convenience we avoid triggering to whole verification process automatically
const apiConfiguration = {
disableAutoVerify: true
};
const initialState = getInitialState(apiConfiguration);
store = configureStore(initialState);
});

afterEach(function () {
store = null;
});
afterEach(function () {
store = null;
});

describe('given it is dispatched with a certificate definition', function () {
it('should set the certificate definition in the state', async function () {
await store.dispatch(updateCertificateDefinition(certificateFixture));
const state = store.getState();
Expand Down Expand Up @@ -62,12 +67,6 @@ describe('updateCertificateDefinition action creator test suite', function () {
});

it('should set the transactionLink in the state', async function () {
const apiConfiguration = {
disableAutoVerify: true
};
const initialState = getInitialState(apiConfiguration);
const store = configureStore(initialState);

await store.dispatch(updateCertificateDefinition(certificateFixture));
const state = store.getState();

Expand All @@ -76,12 +75,6 @@ describe('updateCertificateDefinition action creator test suite', function () {
});

it('should set the chain of the certificate in the state', async function () {
const apiConfiguration = {
disableAutoVerify: true
};
const initialState = getInitialState(apiConfiguration);
const store = configureStore(initialState);

await store.dispatch(updateCertificateDefinition(certificateFixture));
const state = store.getState();

Expand Down Expand Up @@ -121,6 +114,17 @@ describe('updateCertificateDefinition action creator test suite', function () {
});

describe('given it is dispatched with a non-valid certificate definition', function () {
let store;

beforeEach(function () {
const initialState = getInitialState();
store = configureStore(initialState);
});

afterEach(function () {
store = null;
});

it('should not set the definition in the state', async function () {
await store.dispatch(updateCertificateDefinition(notACertificateDefinition));
const state = store.getState();
Expand All @@ -134,5 +138,12 @@ describe('updateCertificateDefinition action creator test suite', function () {

expect(getErrorMessage(state)).toBe('Not a valid Blockcerts definition.');
});

it('should not start the verification process', async function () {
await store.dispatch(updateCertificateDefinition(notACertificateDefinition));
const state = store.getState();

expect(getVerificationHasStarted(state)).toBe(false);
});
});
});

0 comments on commit 466a2b3

Please sign in to comment.