-
Notifications
You must be signed in to change notification settings - Fork 49
/
did-metadata-structure.js
55 lines (49 loc) · 2.77 KB
/
did-metadata-structure.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
43
44
45
46
47
48
49
50
51
52
53
54
55
const didMetadataStructureTests = (suiteConfig) => {
suiteConfig.dids.forEach((didExample) => {
describe(didExample, () => {
suiteConfig.supportedContentTypes.forEach((contentType) => {
describe(contentType, () => {
const didDocumentMetadata = suiteConfig[didExample][contentType].didDocumentMetadata;
if (didDocumentMetadata) {
it('7.3 Metadata Structure - ' +
'The structure used to communicate this metadata MUST be a map of properties.', () => {
expect(didDocumentMetadata).toBeInfraMap();
});
it('7.3 Metadata Structure - ' +
'Each property name MUST be a string.', () => {
Object.keys(didDocumentMetadata).forEach((property_name) => {
expect(property_name).toBeString();
});
});
it('7.3 Metadata Structure - ' +
'Each property value MUST be a string, map, list, ordered set, boolean, or null.', () => {
Object.keys(didDocumentMetadata).forEach((property_name) => {
expect(didDocumentMetadata[property_name]).toBeDidDocumentPropertyValueType();
});
});
it('7.3 Metadata Structure - ' +
'The values within any complex data structures such as maps and lists ' +
'MUST be one of these data types as well.', () => {
Object.keys(didDocumentMetadata).forEach((property_name) => {
if (typeof didDocumentMetadata[property_name] == "object") {
expect(didDocumentMetadata[property_name]).toBeDidDocumentMap();
}
});
});
it('7.3 Metadata Structure - ' +
'The entire metadata structure MUST be serializable according to the JSON ' +
'serialization rules in the [INFRA] specification.', () => {
// Checking this by serialize/deserialize to/from JSON, then compare the result
var obj = {};
expect(() => {
obj = JSON.parse(JSON.stringify(didDocumentMetadata));
}).not.toThrow();
expect(didDocumentMetadata).toEqual(obj);
});
}
});
});
});
});
};
module.exports = { didMetadataStructureTests };