Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Validate credential record state transitions #130

Merged
merged 5 commits into from
Nov 4, 2020
Merged

feat: Validate credential record state transitions #130

merged 5 commits into from
Nov 4, 2020

Conversation

jakubkoci
Copy link
Contributor

I added validation to every credential service method, not sure if it is necessary. I use different parametrized tests than jest.each. I'm aware that's not so simple to read in this way, but I wanted to have just one test for every invalid state. This should fix #123.

I also added two unrelated tests for credential record attributes.

@jakubkoci jakubkoci requested a review from a team as a code owner October 31, 2020 18:24
@@ -266,6 +280,12 @@ export class CredentialService extends EventEmitter {
return this.credentialRepository.find(id);
}

private validateState(current: CredentialState, valid: CredentialState) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call it assertState instead? To me validate state suggests there is some custom validation done in the function, while it basically checks if the first state passed is equal to the second state passed.

Suggested change
private validateState(current: CredentialState, valid: CredentialState) {
private assertState(current: CredentialState, expected: CredentialState) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good point, let's change it. Updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking that we could create another object, something like CredentialStateMachine which would be responsible for such assertions and state transitions. It could simplify tests. I haven't thought through all the details yet.

@@ -167,24 +169,25 @@ export class CredentialService extends EventEmitter {
* @param credentialId Credential record ID
* @param credentialResponseOptions
*/
public async createCredentialResponse(
public async createResponse(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure createResponse is the best name? I'm thinking of createCredential. Then we could also have processCredential

Copy link
Contributor Author

@jakubkoci jakubkoci Nov 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I understand. I also had a problem with this naming. It could be confused with an HTTP request/response. However, now we have consistency at least. Otherwise, we would need to change also other methods, I think. If you look at it from the protocol perspective, this naming is not actually that bad (createRequest, createResponse). Maybe, this message creation and processing stuff could evolve into something called CredentialProtocol calling services to do other tasks (saving credential record, creating protocol attachments, ...)

@jakubkoci jakubkoci merged commit 00d2b1f into openwallet-foundation:master Nov 4, 2020
@jakubkoci jakubkoci deleted the feature/validate-state-transitions branch June 24, 2021 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Before updating credential state to Done we should check if the state is CredentialIssued
2 participants