Skip to content

Commit

Permalink
fix:(wf-exchange.entity): replace current step reference after mutating
Browse files Browse the repository at this point in the history
Signed-off-by: jrhender <john.henderson@energyweb.org>
  • Loading branch information
jrhender committed Jan 21, 2025
1 parent 508cb66 commit 4db0c92
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion apps/vc-api/docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@
"tags": ["vc-api"]
}
},
"/v1/vc-api/workflows/{localWorkflowId}/exchanges/{localExchangeId}/step/{localStepId}": {
"/v1/vc-api/workflows/{localWorkflowId}/exchanges/{localExchangeId}/steps/{localStepId}": {
"get": {
"operationId": "VcApiController_getExchangeStep",
"summary": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export class WfExchangeEntity {
public async participateInExchange(
presentation: VerifiablePresentation,
verifier: SubmissionVerifier,
currentStep: QueryExchangeStep | IssuanceExchangeStep,
nextStep: WorkflowStepDefinitionDto,
nextStepId: string,
baseUrl: string
Expand All @@ -66,9 +65,10 @@ export class WfExchangeEntity {
// set the state to active
this.state = ExchangeState.active;
// Get current step
// const currentStep = this.getCurrentStep();
const currentStep = this.getCurrentStep();
// Pass presentation to current step to process
const { errors, verificationResult } = await currentStep.processPresentation(presentation, verifier);
this.updateCurrentStep(currentStep);
// If step processing has errors, return errors
if (errors.length > 0) {
return {
Expand Down Expand Up @@ -116,6 +116,10 @@ export class WfExchangeEntity {
}
}

private updateCurrentStep(step: QueryExchangeStep | IssuanceExchangeStep): void {
this.steps[this.steps.length - 1] = step;
}

/**
* Convert from a workflow step definition to an instantiated step for an exchange
* @param baseUrl
Expand Down
3 changes: 0 additions & 3 deletions apps/vc-api/src/vc-api/workflows/workflow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export class WorkflowService {
const exchangeRepsonse = await exchange.participateInExchange(
presentation,
this.vpSubmissionVerifierService,
currentStep,
nextStepDefinition,
nextStepId,
this.baseUrlWithControllerPath
Expand All @@ -142,8 +141,6 @@ export class WorkflowService {
throw new BadRequestException(exchangeRepsonse.errors);
}

const stepIndex = exchange.steps.findIndex((step) => step.stepId === currentStep.stepId);
exchange.steps[stepIndex] = currentStep;
await this.exchangeRepository.save(exchange);
const stepResult = exchange.getStep(currentStep.stepId);
const body = CallbackDto.toDto(stepResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,14 @@ export const residentCardWorkflowSuite = () => {
didAuthStepId
);


// As the issuer, check the result of the step verification

// TODO: revisit the isComplete test
// expect(stepSubmission.step.isComplete).toBeTruthy();

if (stepSubmission.step.type === 'QueryExchangeStep') {
const queryExchaneStep = stepSubmission.step as QueryExchangeStep;
expect(queryExchaneStep.presentationSubmission?.verificationResult?.errors).toHaveLength(0);
const queryExchangeStep = stepSubmission.step as QueryExchangeStep;
expect(queryExchangeStep.presentationSubmission.verificationResult.errors).toHaveLength(0);
}
// expect(stepSubmission.stepResponse.verificationResult.verified).toBeTruthy();

Expand Down

0 comments on commit 4db0c92

Please sign in to comment.