Skip to content

Commit

Permalink
Strengthen test assertions on validUntil & validAfter.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 committed Nov 28, 2023
1 parent ca1a90c commit ae641ff
Showing 1 changed file with 53 additions and 23 deletions.
76 changes: 53 additions & 23 deletions test/10-verify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ for(const [version, mockCredential] of versionedCredentials) {
credential.validUntil = '2025-10-31T19:21:25Z';
const now = '2022-06-30T19:21:25Z';
let error;
let result;
let verifiableCredential;
try {
result = await vc.issue({
verifiableCredential = await vc.issue({
credential,
now,
suite,
Expand All @@ -170,9 +170,14 @@ for(const [version, mockCredential] of versionedCredentials) {
}
should.not.exist(error,
'Should not throw error when issuing "validUntil" in future');
should.exist(
result,
'Expected a VC with "validUntil" in the future to be issued'
verifiableCredential.should.exist;
verifiableCredential.should.be.an('object');
verifiableCredential.should.have.property('proof');
verifiableCredential.proof.should.be.an('object');
// ensure validUntil is present and has correct timestamp
verifiableCredential.should.have.property(
'validUntil',
credential.validUntil
);
});
it('should issue "validUntil" in the past', async () => {
Expand All @@ -181,9 +186,9 @@ for(const [version, mockCredential] of versionedCredentials) {
credential.validUntil = '2022-10-31T19:21:25Z';
const now = '2025-06-30T19:21:25Z';
let error;
let result;
let verifiableCredential;
try {
result = await vc.issue({
verifiableCredential = await vc.issue({
credential,
now,
suite,
Expand All @@ -194,9 +199,14 @@ for(const [version, mockCredential] of versionedCredentials) {
}
should.not.exist(error,
'Should not throw error when issuing with "validUntil" in past');
should.exist(
result,
'Expected a VC with "validUntil" in the past to be issued'
verifiableCredential.should.exist;
verifiableCredential.should.be.an('object');
verifiableCredential.should.have.property('proof');
verifiableCredential.proof.should.be.an('object');
// ensure validUntil is present and has correct timestamp
verifiableCredential.should.have.property(
'validUntil',
credential.validUntil
);
});
it('should issue "validFrom" in the past', async () => {
Expand All @@ -205,9 +215,9 @@ for(const [version, mockCredential] of versionedCredentials) {
credential.validFrom = '2022-06-30T19:21:25Z';
const now = '2022-10-30T19:21:25Z';
let error;
let result;
let verifiableCredential;
try {
result = await vc.issue({
verifiableCredential = await vc.issue({
credential,
now,
suite,
Expand All @@ -218,9 +228,14 @@ for(const [version, mockCredential] of versionedCredentials) {
}
should.not.exist(error,
'Should not throw error when issuing "validFrom" in past');
should.exist(
result,
'Expected a VC with "validFrom" in the past to be issued'
verifiableCredential.should.exist;
verifiableCredential.should.be.an('object');
verifiableCredential.should.have.property('proof');
verifiableCredential.proof.should.be.an('object');
// ensure validFrom is present and has correct timestamp
verifiableCredential.should.have.property(
'validFrom',
credential.validFrom
);
});
it('should issue "validFrom" in the future', async () => {
Expand All @@ -229,9 +244,9 @@ for(const [version, mockCredential] of versionedCredentials) {
credential.validFrom = '2022-10-30T19:21:25Z';
const now = '2022-06-30T19:21:25Z';
let error;
let result;
let verifiableCredential;
try {
result = await vc.issue({
verifiableCredential = await vc.issue({
credential,
now,
suite,
Expand All @@ -242,9 +257,14 @@ for(const [version, mockCredential] of versionedCredentials) {
}
should.not.exist(error,
'Should not throw error when issuing "validFrom" in future');
should.exist(
result,
'Expected a VC with "validFrom" in the future to be issued'
verifiableCredential.should.exist;
verifiableCredential.should.be.an('object');
verifiableCredential.should.have.property('proof');
verifiableCredential.proof.should.be.an('object');
// ensure validFrom is present and has correct timestamp
verifiableCredential.should.have.property(
'validFrom',
credential.validFrom
);
});
it('should issue both "validFrom" and "validUntil"', async () => {
Expand All @@ -270,9 +290,19 @@ for(const [version, mockCredential] of versionedCredentials) {
'Should not throw when issuing VC with both "validFrom" and' +
'"validUntil"'
);
should.exist(
verifiableCredential,
'Expected VC to be issued with both "validFrom" and "validUntil"'
verifiableCredential.should.exist;
verifiableCredential.should.be.an('object');
verifiableCredential.should.have.property('proof');
verifiableCredential.proof.should.be.an('object');
// ensure validUntil & validAfter are present
// and have correct timestamps
verifiableCredential.should.have.property(
'validFrom',
credential.validFrom
);
verifiableCredential.should.have.property(
'validUntil',
credential.validUntil
);
});
}
Expand Down

0 comments on commit ae641ff

Please sign in to comment.