Skip to content

Commit

Permalink
test(workflows res-card): change exchangedef to workflowdef
Browse files Browse the repository at this point in the history
Signed-off-by: jrhender <[email protected]>
  • Loading branch information
jrhender committed Oct 30, 2024
1 parent c9de914 commit d50871f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,50 @@ import { WalletClient } from '../../../wallet-client';
import { VerifiablePresentationDto } from '../../../../src/vc-api/credentials/dtos/verifiable-presentation.dto';
import { CredentialDto } from '../../../../src/vc-api/credentials/dtos/credential.dto';
import { Presentation } from '../../../../src/vc-api/exchanges/types/presentation';
import { ExchangeDefinitionDto } from '../../../../src/vc-api/exchanges/dtos/exchange-definition.dto';
import { VpRequestInteractServiceType } from '../../../../src/vc-api/exchanges/types/vp-request-interact-service-type';
import { VpRequestQueryType } from '../../../../src/vc-api/exchanges/types/vp-request-query-type';
import { ProvePresentationOptionsDto } from '../../../../src/vc-api/credentials/dtos/prove-presentation-options.dto';
import { WorkflowConfigDto } from 'src/vc-api/workflows/dtos/create-workflow-request.dto';

export class ResidentCardIssuance {
#exchangeId = 'permanent-resident-card-issuance';
#workflowId = 'permanent-resident-card-issuance';
#callbackUrl: string;
queryType = VpRequestQueryType.didAuth;

constructor(callbackUrl: string) {
this.#callbackUrl = callbackUrl;
}

getExchangeId(): string {
return this.#exchangeId;
getWorkflowId(): string {
return this.#workflowId;
}

getExchangeDefinition(): ExchangeDefinitionDto {
const exchangeDefinition: ExchangeDefinitionDto = {
exchangeId: this.#exchangeId,
query: [
{
type: this.queryType,
credentialQuery: []
getWorkflowDefinition(): WorkflowConfigDto {
const exchangeDefinition: WorkflowConfigDto = {
id: this.#workflowId,
steps: {
intialStep: {
query: [
{
type: this.queryType,
credentialQuery: []
}
],
interactServices: [
{
type: VpRequestInteractServiceType.mediatedPresentation
}
],
callback: [
{
url: this.#callbackUrl
}
]
}
],
interactServices: [
{
type: VpRequestInteractServiceType.mediatedPresentation
}
],
isOneTime: false,
callback: [
{
url: this.#callbackUrl
}
]
},
initialStep: 'initialStep'
};
return plainToClass(ExchangeDefinitionDto, exchangeDefinition);
return plainToClass(WorkflowConfigDto, exchangeDefinition);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ResidentCardPresentation {

getExchangeDefinition(): ExchangeDefinitionDto {
const exchangeDefinition: ExchangeDefinitionDto = {
exchangeId: this.#exchangeId,
id: this.#exchangeId,
query: [
{
type: this.queryType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,31 @@ const callbackUrlBase = 'http://example.com';
const callbackUrlPath = '/endpoint';
const callbackUrl = `${callbackUrlBase}${callbackUrlPath}`;

export const residentCardExchangeSuite = () => {
export const residentCardWorkflowSuite = () => {
it('should support Resident Card issuance and presentation', async () => {
// As issuer, configure credential issuance exchange
// POST /exchanges
// As issuer, configure credential issuance workflow
// POST /workflows
const exchange = new ResidentCardIssuance(callbackUrl);
const numHolderQueriesPriorToIssuance = 2;
const issuanceCallbackScope = nock(callbackUrlBase)
.post(callbackUrlPath)
.times(numHolderQueriesPriorToIssuance)
.reply(201);
await request(app.getHttpServer())
.post(`${vcApiBaseUrl}/exchanges`)
.send(exchange.getExchangeDefinition())
.post(`${vcApiBaseUrl}/workflows`)
.send(exchange.getWorkflowDefinition())
.expect(201);

// As issuer, configure credential issuance exchange
// POST /workflows/{localWorkflowId}/exchanges
await request(app.getHttpServer())
.post(`${vcApiBaseUrl}/workflows/${exchange.getWorkflowId()}/exchanges/`)
.send(exchange.getWorkflowDefinition())
.expect(201);

// As holder, start issuance exchange
// POST /exchanges/{exchangeId}
const issuanceExchangeEndpoint = `${vcApiBaseUrl}/exchanges/${exchange.getExchangeId()}`;
const issuanceExchangeEndpoint = `${vcApiBaseUrl}/exchanges/${exchange.getWorkflowId()}`;
const issuanceVpRequest = await walletClient.startExchange(issuanceExchangeEndpoint, exchange.queryType);
const issuanceExchangeContinuationEndpoint = getContinuationEndpoint(issuanceVpRequest);
expect(issuanceExchangeContinuationEndpoint).toContain(issuanceExchangeEndpoint);
Expand Down Expand Up @@ -67,7 +74,7 @@ export const residentCardExchangeSuite = () => {
// TODO TODO TODO!!! How does the issuer know the transactionId? -> Maybe can rely on notification
const urlComponents = issuanceExchangeContinuationEndpoint.split('/');
const transactionId = urlComponents.pop();
const transaction = await walletClient.getExchangeTransaction(exchange.getExchangeId(), transactionId);
const transaction = await walletClient.getExchangeTransaction(exchange.getWorkflowId(), transactionId);

// As the issuer, check the result of the transaction verification
expect(transaction.presentationSubmission.verificationResult.verified).toBeTruthy();
Expand All @@ -80,7 +87,7 @@ export const residentCardExchangeSuite = () => {
result: ReviewResult.approved,
vp: issuedVP
};
await walletClient.addSubmissionReview(exchange.getExchangeId(), transactionId, submissionReview);
await walletClient.addSubmissionReview(exchange.getWorkflowId(), transactionId, submissionReview);

// As the holder, check for a reviewed submission
const secondContinuationResponse = await walletClient.continueExchange(
Expand Down

0 comments on commit d50871f

Please sign in to comment.