Skip to content

Commit

Permalink
group pd test (#367)
Browse files Browse the repository at this point in the history
nitro-neal authored Jan 31, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 2bd93a8 commit 422ba93
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions packages/credentials/tests/presentation-exchange.spec.ts
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ describe('PresentationExchange', () => {
let issuerDid: PortableDid;
let btcCredentialJwt: string;
let presentationDefinition: PresentationDefinitionV2;
let groupPresentationDefinition: PresentationDefinitionV2;

before(async () => {
issuerDid = await DidKeyMethod.create();
@@ -38,6 +39,7 @@ describe('PresentationExchange', () => {

btcCredentialJwt = await vc.sign({did: issuerDid});
presentationDefinition = createPresentationDefinition();
groupPresentationDefinition = createGroupPresentationDefinition();
});

it('should evaluate credentials without any errors or warnings', async () => {
@@ -213,6 +215,27 @@ describe('PresentationExchange', () => {
expect(warnings).to.be.an('array');
expect(warnings?.length).to.equal(0);
});

it('should successfully execute the complete group presentation exchange flow', () => {
const presentationResult = PresentationExchange.createPresentationFromCredentials({
vcJwts : [btcCredentialJwt],
presentationDefinition : groupPresentationDefinition
});

expect(presentationResult).to.exist;
expect(presentationResult.presentationSubmission.definition_id).to.equal(groupPresentationDefinition.id);

const { warnings, errors } = PresentationExchange.evaluatePresentation({
presentationDefinition : groupPresentationDefinition,
presentation : presentationResult.presentation
});

expect(errors).to.be.an('array');
expect(errors?.length).to.equal(0);

expect(warnings).to.be.an('array');
expect(warnings?.length).to.equal(0);
});
});

describe('Web5TestVectorsPresentationExchange', () => {
@@ -252,4 +275,48 @@ function createPresentationDefinition(): PresentationDefinitionV2 {
}
]
};
}

function createGroupPresentationDefinition(): PresentationDefinitionV2 {
return {
'id' : 'test-pd-group-id',
'submission_requirements' : [{
'name' : 'Citizenship Information',
'rule' : 'pick',
'count' : 1,
'from' : 'A'
}],
'name' : 'group PD',
'purpose' : 'group pd for testing',
'input_descriptors' : [
{
'id' : 'whatever-1',
'purpose' : 'id for testing',
'group' : ['A'],
'constraints' : {
'fields': [
{
'path': [
'$.credentialSubject.btcAddress',
]
}
]
}
},
{
'id' : 'whatever-2',
'purpose' : 'id for testing',
'group' : ['A'],
'constraints' : {
'fields': [
{
'path': [
'$.credentialSubject.dob',
]
}
]
}
}
]
};
}

0 comments on commit 422ba93

Please sign in to comment.