Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Commit

Permalink
fix: structure validation functions were receiving plain objects inst…
Browse files Browse the repository at this point in the history
…ead of JSON (#218)
  • Loading branch information
jawid-h authored Aug 18, 2020
1 parent 7f3501c commit 9a75f11
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 4 additions & 2 deletions lib/identity/IdentityFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ class IdentityFactory {
createFromObject(rawIdentity, options = {}) {
const opts = { skipValidation: false, ...options };

const identity = new Identity(rawIdentity);

if (!opts.skipValidation) {
const result = this.validateIdentity(rawIdentity);
const result = this.validateIdentity(identity.toJSON());

if (!result.isValid()) {
throw new InvalidIdentityError(result.getErrors(), rawIdentity);
}
}

return new Identity(rawIdentity);
return identity;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions lib/stateTransition/StateTransitionFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ class StateTransitionFactory {
async createFromObject(rawStateTransition, options = {}) {
const opts = { skipValidation: false, ...options };

// noinspection UnnecessaryLocalVariableJS
const stateTransition = await this.createStateTransition(rawStateTransition, {
fromJSON: false,
});

if (!opts.skipValidation) {
const result = await this.validateStateTransitionStructure(rawStateTransition);
const result = await this.validateStateTransitionStructure(stateTransition.toJSON());

if (!result.isValid()) {
throw new InvalidStateTransitionError(result.getErrors(), rawStateTransition);
}
}

// noinspection UnnecessaryLocalVariableJS
const stateTransition = await this.createStateTransition(rawStateTransition, {
fromJSON: false,
});

return stateTransition;
}

Expand Down
2 changes: 0 additions & 2 deletions test/unit/stateTransition/StateTransitionFactory.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ describe('StateTransitionFactory', () => {
expect(validateStateTransitionStructureMock).to.have.been.calledOnceWith(
rawStateTransition,
);

expect(createStateTransitionMock).to.have.not.been.called();
}
});
});
Expand Down

0 comments on commit 9a75f11

Please sign in to comment.