-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathschema-validation.js
42 lines (34 loc) · 1.06 KB
/
schema-validation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Schema } from '@docknetwork/credential-sdk/modules/abstract/schema';
// BOL Schema, its valid
import bolSchema from './schemas/bol.js';
// Invalid example schema
const invalidSchema = {
invalid: true,
};
async function main() {
// Run validation for example BOL schema
console.log('Example schema should be valid:', bolSchema);
// This method would throw an error if its invalid
await Schema.validateSchema(bolSchema);
// Run validation for invalid schema
console.log('Example schema should be invalid:', invalidSchema);
let success = false;
try {
// This method will throw an error as schema is invalid
await Schema.validateSchema(invalidSchema);
} catch (e) {
success = true;
console.log('As expected, schema validation failed with error:', e);
}
if (success === false) {
throw new Error('Invalid schema passed validation, something went wrong!');
}
}
main()
.then(() => {
process.exit(0);
})
.catch((error) => {
console.error('Error occurred somewhere, it was caught!', error);
process.exit(1);
});