-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add JSON-LD expansion and validation e2e tests
- Loading branch information
1 parent
524e51d
commit 400ba02
Showing
3 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
e2e/cypress/e2e/untp-playground/jsonld-expansion-validation.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { VCDM_CONTEXT_URLS } from '../../../../packages/untp-playground/constants'; | ||
|
||
describe('JSON-LD Expansion and Validation', () => { | ||
beforeEach(() => { | ||
cy.visit('http://localhost:4000'); | ||
}); | ||
|
||
const validCredential = { | ||
'@context': ['https://www.w3.org/ns/credentials/v2', 'https://test.uncefact.org/vocabulary/untp/dpp/0.5.0/'], | ||
type: ['VerifiableCredential', 'DigitalProductPassport'], | ||
issuer: { | ||
id: 'did:example:123', | ||
name: 'dev', | ||
}, | ||
credentialSubject: { | ||
name: 'John Doe', | ||
id: 'did:example:123', | ||
type: ['Product'], | ||
}, | ||
}; | ||
|
||
const invalidJsonldSyntaxCredential = { | ||
...validCredential, | ||
'@context': [ | ||
'https://www.w3.org/ns/credentials/v2', | ||
'https://test.uncefact.org/vocabulary/untp/dpp/0.5.0/', | ||
{ | ||
'': '', | ||
}, | ||
], | ||
}; | ||
|
||
const unresolvableContextCredential = { | ||
...validCredential, | ||
'@context': ['https://www.invalid.com'], | ||
}; | ||
|
||
const invalidPropertiesCredential = { | ||
...validCredential, | ||
credentialSubject: { | ||
...validCredential.credentialSubject, | ||
invalid: 'invalid-value', | ||
}, | ||
}; | ||
|
||
it('should validate context expansion and validation successfully', () => { | ||
cy.uploadCredential(validCredential); | ||
cy.expandGroup(); | ||
cy.checkValidationStatus('JSON-LD Document Expansion and Context Validation', 'success'); | ||
}); | ||
|
||
it('should show error for invalid JSON-LD syntax', () => { | ||
cy.uploadCredential(invalidJsonldSyntaxCredential); | ||
cy.expandGroup(); | ||
cy.checkValidationStatus('JSON-LD Document Expansion and Context Validation', 'failure'); | ||
|
||
cy.openErrorDetailsByStepName('JSON-LD Document Expansion and Context Validation'); | ||
cy.openValidationDetails('Fix validation error'); | ||
|
||
cy.checkValidationErrorMessages([ | ||
'Conflicting field: unknown', | ||
'Failed to validate JSON-LD syntax.', | ||
'Resolve the conflict by removing the conflicting field or updating it to a unique one.', | ||
]); | ||
}); | ||
|
||
it('should show error for unresolvable context', () => { | ||
cy.uploadCredential(unresolvableContextCredential); | ||
cy.expandGroup(); | ||
cy.checkValidationStatus('JSON-LD Document Expansion and Context Validation', 'failure'); | ||
|
||
cy.openErrorDetailsByStepName('JSON-LD Document Expansion and Context Validation'); | ||
cy.openValidationDetails('Use the correct value'); | ||
|
||
cy.checkValidationErrorMessages([ | ||
'Incorrect value: @context', | ||
'Invalid URL: "https://www.invalid.com". Failed to resolve context url.', | ||
'Update the value(s) to the correct one(s) or remove the field(s).', | ||
]); | ||
}); | ||
|
||
it('should show error for invalid properties', () => { | ||
cy.uploadCredential(invalidPropertiesCredential); | ||
cy.expandGroup(); | ||
cy.checkValidationStatus('JSON-LD Document Expansion and Context Validation', 'failure'); | ||
|
||
cy.openErrorDetailsByStepName('JSON-LD Document Expansion and Context Validation'); | ||
cy.openValidationDetails('Use the correct value'); | ||
|
||
cy.checkValidationErrorMessages([ | ||
'Incorrect value: credentialSubject/invalid', | ||
'Properties "credentialSubject/invalid" are defined in the credential but missing from the context.', | ||
'Update the value(s) to the correct one(s) or remove the field(s).', | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters