Skip to content

Commit

Permalink
Move issue both validFrom and validUntil to issue section of test suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 committed Nov 27, 2023
1 parent 4254390 commit 6fcf01c
Showing 1 changed file with 49 additions and 50 deletions.
99 changes: 49 additions & 50 deletions test/10-verify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,27 @@ for(const [version, mockCredential] of versionedCredentials) {
verifiableCredential.should.have.property('proof');
verifiableCredential.proof.should.be.an('object');
});
it('should throw an error on missing verificationMethod', async () => {
const suite = new Ed25519Signature2018({
// Note no key id or verificationMethod passed to suite
key: await Ed25519VerificationKey2018.generate()
});
let error;
try {
await vc.issue({
credential: jsonld.clone(mockCredential),
suite
});
} catch(e) {
error = e;
}

should.exist(error,
'Should throw error when "verificationMethod" property missing');
error.should.be.instanceof(TypeError);
error.message.should
.contain('"suite.verificationMethod" property is required.');
});
if(version === 1.0) {
it('should issue an expired verifiable credential', async () => {
const keyPair = await Ed25519VerificationKey2018.generate();
Expand Down Expand Up @@ -129,28 +150,6 @@ for(const [version, mockCredential] of versionedCredentials) {
verifiableCredential.proof.should.be.an('object');
});
}

it('should throw an error on missing verificationMethod', async () => {
const suite = new Ed25519Signature2018({
// Note no key id or verificationMethod passed to suite
key: await Ed25519VerificationKey2018.generate()
});
let error;
try {
await vc.issue({
credential: jsonld.clone(mockCredential),
suite
});
} catch(e) {
error = e;
}

should.exist(error,
'Should throw error when "verificationMethod" property missing');
error.should.be.instanceof(TypeError);
error.message.should
.contain('"suite.verificationMethod" property is required.');
});
if(version === 2.0) {
it('should issue "validUntil" in the future', async () => {
const credential = jsonld.clone(mockCredential);
Expand Down Expand Up @@ -248,6 +247,34 @@ for(const [version, mockCredential] of versionedCredentials) {
'Expected a VC with "validFrom" in the future to be issued'
);
});
it('should issue both "validFrom" and "validUntil"', async () => {
const credential = jsonld.clone(mockCredential);
credential.issuer = 'did:example:12345';
credential.validFrom = '2022-05-30T19:21:25Z';
credential.validUntil = '2025-05-30T19:21:25Z';
const now = '2022-06-30T19:21:25Z';
let error;
let verifiableCredential;
try {
verifiableCredential = await vc.issue({
credential,
suite,
documentLoader,
now
});
} catch(e) {
error = e;
}
should.not.exist(
error,
'Should not throw when issuing VC with both "validFrom" and' +
'"validUntil"'
);
should.exist(
verifiableCredential,
'Expected VC to be issued with both "validFrom" and "validUntil"'
);
});
}
});

Expand Down Expand Up @@ -803,34 +830,6 @@ for(const [version, mockCredential] of versionedCredentials) {
should.not.exist(error,
'Should not throw error when "issuanceDate" is valid');
});
it('should issue both "validFrom" and "validUntil"', async () => {
const credential = jsonld.clone(mockCredential);
credential.issuer = 'did:example:12345';
credential.validFrom = '2022-05-30T19:21:25Z';
credential.validUntil = '2025-05-30T19:21:25Z';
const now = '2022-06-30T19:21:25Z';
let error;
let verifiableCredential;
try {
verifiableCredential = await vc.issue({
credential,
suite,
documentLoader,
now
});
} catch(e) {
error = e;
}
should.not.exist(
error,
'Should not throw when issuing VC with both "validFrom" and' +
'"validUntil"'
);
should.exist(
verifiableCredential,
'Expected VC to be issued with both "validFrom" and "validUntil"'
);
});
it('should verify if "validFrom" is before "validUntil"', () => {
const credential = jsonld.clone(mockCredential);
credential.issuer = 'did:example:12345';
Expand Down

0 comments on commit 6fcf01c

Please sign in to comment.