Skip to content

Commit

Permalink
fix(verifiable-credentials): check errors in exchange initiating
Browse files Browse the repository at this point in the history
  • Loading branch information
JGiter committed Jun 3, 2022
1 parent 706391f commit 1bc8626
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
10 changes: 1 addition & 9 deletions e2e/verifiable-credentials.service.e2e.ts
Expand Up @@ -409,21 +409,13 @@ describe('Verifiable credentials tests', () => {
]);
(axios as jest.Mocked<typeof axios>).post.mockImplementation((url) => {
return Promise.resolve({
data: url === exchangeUrl ? vpRequest : '',
data: url === exchangeUrl ? { errors: [], vpRequest } : '',
});
});
getClaimsBySubject.mockResolvedValue([{ vp }]);
});

test('initiateExchange() should return presentation matching presentation request', async () => {
(axios as jest.Mocked<typeof axios>).post.mockImplementationOnce(
(url) => {
return Promise.resolve({
data: url === exchangeUrl ? vpRequest : '',
});
}
);

const {
selections: [{ selectResults }],
} = await verifiableCredentialsService.initiateExchange({
Expand Down
Expand Up @@ -157,7 +157,12 @@ export abstract class VerifiableCredentialsServiceBase {
throw new Error('Only VC-API exchange is supported');
}

const { data: vpRequest } = await axios.post<VpRequest>(url);
const {
data: { errors, vpRequest },
} = await axios.post<{ errors: string[]; vpRequest: VpRequest }>(url);
if (errors.length > 0) {
throw new Error(`Error initiating exchange: ${JSON.stringify(errors)}`);
}
const credentialQuery = vpRequest.query.find(
(q) => q.type === VpRequestQueryType.presentationDefinition
)?.credentialQuery as VpRequestPresentationDefinitionQuery[];
Expand Down

0 comments on commit 1bc8626

Please sign in to comment.