Skip to content

Commit

Permalink
Reduce nesting in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Jul 10, 2024
1 parent 933ebfb commit 12da53d
Show file tree
Hide file tree
Showing 12 changed files with 1,118 additions and 1,152 deletions.
304 changes: 149 additions & 155 deletions test/mocha/30-backwards-compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,173 +114,167 @@ describe('issue APIs - Reference ID `assertionMethod:foo` backwards ' +
should.exist(config.zcaps['assertionMethod:Ed25519']);
}
});
describe('/credentials/issue', () => {
it('issues a valid credential w/no "credentialStatus"', async () => {
const credential = klona(mockCredential);
let error;
let result;
try {
const zcapClient = helpers.createZcapClient({capabilityAgent});
result = await zcapClient.write({
url: `${noStatusListIssuerId}/credentials/issue`,
capability: noStatusListIssuerRootZcap,
json: {
credential
}
});
} catch(e) {
error = e;
}
assertNoError(error);
should.exist(result.data);
should.exist(result.data.verifiableCredential);
const {verifiableCredential} = result.data;
verifiableCredential.should.be.an('object');
should.exist(verifiableCredential['@context']);
should.exist(verifiableCredential.id);
should.exist(verifiableCredential.type);
should.exist(verifiableCredential.issuer);
should.exist(verifiableCredential.issuanceDate);
should.exist(verifiableCredential.credentialSubject);
verifiableCredential.credentialSubject.should.be.an('object');
should.not.exist(verifiableCredential.credentialStatus);
should.exist(verifiableCredential.proof);
verifiableCredential.proof.should.be.an('object');
});
it('issues a valid credential w/ SL 2021 "credentialStatus" and ' +
'suspension status purpose', async () => {
const credential = klona(mockCredential);
let error;
let result;
try {
const zcapClient = helpers.createZcapClient({capabilityAgent});
result = await zcapClient.write({
url: `${sl2021Suspension.issuerId}/credentials/issue`,
capability: sl2021Suspension.rootZcap,
json: {
credential
}
});
} catch(e) {
error = e;
}
assertNoError(error);
should.exist(result.data);
should.exist(result.data.verifiableCredential);
const {verifiableCredential} = result.data;
verifiableCredential.should.be.an('object');
should.exist(verifiableCredential['@context']);
should.exist(verifiableCredential.id);
should.exist(verifiableCredential.type);
should.exist(verifiableCredential.issuer);
should.exist(verifiableCredential.issuanceDate);
should.exist(verifiableCredential.credentialSubject);
verifiableCredential.credentialSubject.should.be.an('object');
should.exist(verifiableCredential.credentialStatus);
should.exist(verifiableCredential.proof);
verifiableCredential.proof.should.be.an('object');
});
it('issues a valid credential w/no "credentialStatus"', async () => {
const credential = klona(mockCredential);
let error;
let result;
try {
const zcapClient = helpers.createZcapClient({capabilityAgent});
result = await zcapClient.write({
url: `${noStatusListIssuerId}/credentials/issue`,
capability: noStatusListIssuerRootZcap,
json: {
credential
}
});
} catch(e) {
error = e;
}
assertNoError(error);
should.exist(result.data);
should.exist(result.data.verifiableCredential);
const {verifiableCredential} = result.data;
verifiableCredential.should.be.an('object');
should.exist(verifiableCredential['@context']);
should.exist(verifiableCredential.id);
should.exist(verifiableCredential.type);
should.exist(verifiableCredential.issuer);
should.exist(verifiableCredential.issuanceDate);
should.exist(verifiableCredential.credentialSubject);
verifiableCredential.credentialSubject.should.be.an('object');
should.not.exist(verifiableCredential.credentialStatus);
should.exist(verifiableCredential.proof);
verifiableCredential.proof.should.be.an('object');
});
it('issues a valid credential w/ SL 2021 "credentialStatus" and ' +
'suspension status purpose', async () => {
const credential = klona(mockCredential);
let error;
let result;
try {
const zcapClient = helpers.createZcapClient({capabilityAgent});
result = await zcapClient.write({
url: `${sl2021Suspension.issuerId}/credentials/issue`,
capability: sl2021Suspension.rootZcap,
json: {
credential
}
});
} catch(e) {
error = e;
}
assertNoError(error);
should.exist(result.data);
should.exist(result.data.verifiableCredential);
const {verifiableCredential} = result.data;
verifiableCredential.should.be.an('object');
should.exist(verifiableCredential['@context']);
should.exist(verifiableCredential.id);
should.exist(verifiableCredential.type);
should.exist(verifiableCredential.issuer);
should.exist(verifiableCredential.issuanceDate);
should.exist(verifiableCredential.credentialSubject);
verifiableCredential.credentialSubject.should.be.an('object');
should.exist(verifiableCredential.credentialStatus);
should.exist(verifiableCredential.proof);
verifiableCredential.proof.should.be.an('object');
});

describe('/credentials/status', () => {
it('updates a StatusList2021 revocation credential status',
async () => {
// first issue VC
const credential = klona(mockCredential);
const zcapClient = helpers.createZcapClient({capabilityAgent});
const {data: {verifiableCredential}} = await zcapClient.write({
url: `${sl2021Revocation.issuerId}/credentials/issue`,
capability: sl2021Revocation.rootZcap,
json: {credential}
});
it('updates a StatusList2021 revocation credential status', async () => {
// first issue VC
const credential = klona(mockCredential);
const zcapClient = helpers.createZcapClient({capabilityAgent});
const {data: {verifiableCredential}} = await zcapClient.write({
url: `${sl2021Revocation.issuerId}/credentials/issue`,
capability: sl2021Revocation.rootZcap,
json: {credential}
});

// get VC status
const statusInfo = await helpers.getCredentialStatus(
{verifiableCredential});
let {status} = statusInfo;
status.should.equal(false);
// get VC status
const statusInfo = await helpers.getCredentialStatus(
{verifiableCredential});
let {status} = statusInfo;
status.should.equal(false);

// then revoke VC
let error;
try {
const {statusListOptions: [{indexAllocator}]} =
sl2021Revocation.issuerConfig;
await zcapClient.write({
url: `${sl2021Revocation.statusId}/credentials/status`,
capability: sl2021Revocation.statusRootZcap,
json: {
credentialId: verifiableCredential.id,
indexAllocator,
credentialStatus: verifiableCredential.credentialStatus,
status: true
}
});
} catch(e) {
error = e;
// then revoke VC
let error;
try {
const {statusListOptions: [{indexAllocator}]} =
sl2021Revocation.issuerConfig;
await zcapClient.write({
url: `${sl2021Revocation.statusId}/credentials/status`,
capability: sl2021Revocation.statusRootZcap,
json: {
credentialId: verifiableCredential.id,
indexAllocator,
credentialStatus: verifiableCredential.credentialStatus,
status: true
}
assertNoError(error);
});
} catch(e) {
error = e;
}
assertNoError(error);

// force refresh of new SLC
await zcapClient.write({
url: `${statusInfo.statusListCredential}?refresh=true`,
capability: sl2021Revocation.statusRootZcap,
json: {}
});
// force refresh of new SLC
await zcapClient.write({
url: `${statusInfo.statusListCredential}?refresh=true`,
capability: sl2021Revocation.statusRootZcap,
json: {}
});

// check status of VC has changed
({status} = await helpers.getCredentialStatus(
{verifiableCredential}));
status.should.equal(true);
});
it('updates a StatusList2021 suspension credential status',
async () => {
// first issue VC
const credential = klona(mockCredential);
const zcapClient = helpers.createZcapClient({capabilityAgent});
const {data: {verifiableCredential}} = await zcapClient.write({
url: `${sl2021Suspension.issuerId}/credentials/issue`,
capability: sl2021Suspension.rootZcap,
json: {credential}
});
// check status of VC has changed
({status} = await helpers.getCredentialStatus(
{verifiableCredential}));
status.should.equal(true);
});
it('updates a StatusList2021 suspension credential status', async () => {
// first issue VC
const credential = klona(mockCredential);
const zcapClient = helpers.createZcapClient({capabilityAgent});
const {data: {verifiableCredential}} = await zcapClient.write({
url: `${sl2021Suspension.issuerId}/credentials/issue`,
capability: sl2021Suspension.rootZcap,
json: {credential}
});

// get VC status
const statusInfo = await helpers.getCredentialStatus(
{verifiableCredential});
let {status} = statusInfo;
status.should.equal(false);
// get VC status
const statusInfo = await helpers.getCredentialStatus(
{verifiableCredential});
let {status} = statusInfo;
status.should.equal(false);

// then revoke VC
let error;
try {
const {statusListOptions: [{indexAllocator}]} =
sl2021Suspension.issuerConfig;
await zcapClient.write({
url: `${sl2021Suspension.statusId}/credentials/status`,
capability: sl2021Suspension.statusRootZcap,
json: {
credentialId: verifiableCredential.id,
indexAllocator,
credentialStatus: verifiableCredential.credentialStatus,
status: true
}
});
} catch(e) {
error = e;
// then revoke VC
let error;
try {
const {statusListOptions: [{indexAllocator}]} =
sl2021Suspension.issuerConfig;
await zcapClient.write({
url: `${sl2021Suspension.statusId}/credentials/status`,
capability: sl2021Suspension.statusRootZcap,
json: {
credentialId: verifiableCredential.id,
indexAllocator,
credentialStatus: verifiableCredential.credentialStatus,
status: true
}
assertNoError(error);
});
} catch(e) {
error = e;
}
assertNoError(error);

// force refresh of new SLC
await zcapClient.write({
url: `${statusInfo.statusListCredential}?refresh=true`,
capability: sl2021Suspension.statusRootZcap,
json: {}
});
// force refresh of new SLC
await zcapClient.write({
url: `${statusInfo.statusListCredential}?refresh=true`,
capability: sl2021Suspension.statusRootZcap,
json: {}
});

// check status of VC has changed
({status} = await helpers.getCredentialStatus(
{verifiableCredential}));
status.should.equal(true);
});
// check status of VC has changed
({status} = await helpers.getCredentialStatus(
{verifiableCredential}));
status.should.equal(true);
});
});
});
Loading

0 comments on commit 12da53d

Please sign in to comment.