manyfest 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.config/configstore/update-notifier-npm.json +1 -1
- package/README.md +336 -10
- package/examples/chocula/Chocula.js +8 -0
- package/examples/chocula/Data-Archive-org-Frankenberry.json +246 -0
- package/examples/chocula/Schema-Archive-org-Item.json +47 -0
- package/package.json +2 -2
- package/source/Manyfest.js +146 -3
- package/test/Data-Archive-org-Frankenberry.json +246 -0
- package/test/Data-Yahoo-Weather.json +115 -0
- package/test/Manyfest_AdvancedObjectAccess_tests.js +80 -0
- package/test/Manyfest_ObjectAccess_tests.js +144 -0
- package/test/Manyfest_tests.js +2 -116
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for Meadow
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
*
|
|
6
|
+
* @author Steven Velozo <steven@velozo.com>
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
var Chai = require("chai");
|
|
10
|
+
var Expect = Chai.expect;
|
|
11
|
+
|
|
12
|
+
let libManyfest = require('../source/Manyfest.js');
|
|
13
|
+
|
|
14
|
+
let _SampleDataArchiveOrgFrankenberry = require('./Data-Archive-org-Frankenberry.json');
|
|
15
|
+
|
|
16
|
+
suite
|
|
17
|
+
(
|
|
18
|
+
'Manyfest Object Access',
|
|
19
|
+
function()
|
|
20
|
+
{
|
|
21
|
+
setup (()=> {} );
|
|
22
|
+
|
|
23
|
+
suite
|
|
24
|
+
(
|
|
25
|
+
'Object Property Manipulation',
|
|
26
|
+
()=>
|
|
27
|
+
{
|
|
28
|
+
test
|
|
29
|
+
(
|
|
30
|
+
'Properties should be gettable and settable without a schema.',
|
|
31
|
+
(fTestComplete)=>
|
|
32
|
+
{
|
|
33
|
+
let _Manyfest = new libManyfest({});
|
|
34
|
+
let _SimpleObject = {Name:'Bob',Age:31,Pets:{Fido:'Dog',Spot:'Cat'}};
|
|
35
|
+
Expect(_Manyfest.getValueAtAddress(_SimpleObject,'Name'))
|
|
36
|
+
.to.equal('Bob');
|
|
37
|
+
_Manyfest.setValueAtAddress(_SimpleObject,'Name','Jim');
|
|
38
|
+
Expect(_Manyfest.getValueAtAddress(_SimpleObject,'Name'))
|
|
39
|
+
.to.equal('Jim');
|
|
40
|
+
fTestComplete();
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
test
|
|
44
|
+
(
|
|
45
|
+
'It should be trivial to access subproperties with or without schema.',
|
|
46
|
+
(fTestComplete)=>
|
|
47
|
+
{
|
|
48
|
+
let _Manyfest = new libManyfest({ Scope:'Archive.org', Descriptors: {'metadata.creator': {Name:'Creator', Hash:'Creator'}}});
|
|
49
|
+
// Property not in schema:
|
|
50
|
+
let tmpTitle = _Manyfest.getValueAtAddress(_SampleDataArchiveOrgFrankenberry, 'metadata.title');
|
|
51
|
+
// Property in schema
|
|
52
|
+
let tmpCreator = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Creator');
|
|
53
|
+
Expect(tmpTitle)
|
|
54
|
+
.to.equal('Franken Berry / Count Chocula : Tevevision Commercial 1971');
|
|
55
|
+
Expect(tmpCreator)
|
|
56
|
+
.to.equal('General Mills');
|
|
57
|
+
fTestComplete();
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
test
|
|
61
|
+
(
|
|
62
|
+
'Properties should be accessible via Hash.',
|
|
63
|
+
(fTestComplete)=>
|
|
64
|
+
{
|
|
65
|
+
let animalManyfest = new libManyfest(
|
|
66
|
+
{
|
|
67
|
+
"Scope": "Animal",
|
|
68
|
+
"Descriptors":
|
|
69
|
+
{
|
|
70
|
+
"IDAnimal": { "Name":"Database ID", "Description":"The unique integer-based database identifier for an Animal record.", "DataType":"Integer" },
|
|
71
|
+
"Name": { "Description":"The animal's colloquial species name (e.g. Rabbit, Dog, Bear, Mongoose)." },
|
|
72
|
+
"Type": { "Description":"Whether or not the animal is wild, domesticated, agricultural, in a research lab or a part of a zoo.." },
|
|
73
|
+
"MedicalStats":
|
|
74
|
+
{
|
|
75
|
+
"Name":"Medical Statistics", "Description":"Basic medical statistics for this animal"
|
|
76
|
+
},
|
|
77
|
+
"MedicalStats.Temps.MinET": { "Name":"Minimum Environmental Temperature", "NameShort":"MinET", "Description":"Safest minimum temperature for this animal to survive in."},
|
|
78
|
+
"MedicalStats.Temps.MaxET": { "Name":"Maximum Environmental Temperature", "NameShort":"MaxET", "Description":"Safest maximum temperature for this animal to survive in."},
|
|
79
|
+
"MedicalStats.Temps.CET":
|
|
80
|
+
{
|
|
81
|
+
"Name":"Comfortable Environmental Temperature",
|
|
82
|
+
"NameShort":"Comf Env Temp",
|
|
83
|
+
"Hash":"ComfET",
|
|
84
|
+
"Description":"The most comfortable temperature for this animal to survive in."
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
Expect(animalManyfest.getValueByHash({MedicalStats: { Temps: { CET:200 }},Name:'Froggy'}, 'ComfET'))
|
|
90
|
+
.to.equal(200);
|
|
91
|
+
|
|
92
|
+
fTestComplete();
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
test
|
|
96
|
+
(
|
|
97
|
+
'Validate should check that required elements exist',
|
|
98
|
+
(fTestComplete)=>
|
|
99
|
+
{
|
|
100
|
+
let animalManyfest = new libManyfest(
|
|
101
|
+
{
|
|
102
|
+
"Scope": "Animal",
|
|
103
|
+
"Descriptors":
|
|
104
|
+
{
|
|
105
|
+
"IDAnimal": { "Name":"Database ID", "Description":"The unique integer-based database identifier for an Animal record.", "DataType":"Integer" },
|
|
106
|
+
"Name": { "Required":true, "Description":"The animal's colloquial species name (e.g. Rabbit, Dog, Bear, Mongoose)." }
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
let tmpValidationResults = animalManyfest.validate({MedicalStats: { Temps: { CET:200 }},Name:'Froggy'});
|
|
111
|
+
|
|
112
|
+
Expect(tmpValidationResults.Error)
|
|
113
|
+
.to.equal(null);
|
|
114
|
+
|
|
115
|
+
fTestComplete();
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
test
|
|
119
|
+
(
|
|
120
|
+
'Validate should error when required elements do not exist',
|
|
121
|
+
(fTestComplete)=>
|
|
122
|
+
{
|
|
123
|
+
let animalManyfest = new libManyfest(
|
|
124
|
+
{
|
|
125
|
+
"Scope": "Animal",
|
|
126
|
+
"Descriptors":
|
|
127
|
+
{
|
|
128
|
+
"IDAnimal": { "Name":"Database ID", "Description":"The unique integer-based database identifier for an Animal record.", "DataType":"Integer" },
|
|
129
|
+
"Name": { "Required":true, "Description":"The animal's colloquial species name (e.g. Rabbit, Dog, Bear, Mongoose)." }
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
let tmpValidationResults = animalManyfest.validate({MedicalStats: { Temps: { CET:200 }}});
|
|
134
|
+
|
|
135
|
+
Expect(tmpValidationResults.Error)
|
|
136
|
+
.to.equal(true);
|
|
137
|
+
|
|
138
|
+
fTestComplete();
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
);
|
package/test/Manyfest_tests.js
CHANGED
|
@@ -16,13 +16,7 @@ suite
|
|
|
16
16
|
'Manyfest Basic',
|
|
17
17
|
function()
|
|
18
18
|
{
|
|
19
|
-
setup
|
|
20
|
-
(
|
|
21
|
-
()=>
|
|
22
|
-
{
|
|
23
|
-
// No custom per-test spool-up required
|
|
24
|
-
}
|
|
25
|
-
);
|
|
19
|
+
setup (()=> {} );
|
|
26
20
|
|
|
27
21
|
suite
|
|
28
22
|
(
|
|
@@ -45,7 +39,7 @@ suite
|
|
|
45
39
|
'Default properties should be automatically set.',
|
|
46
40
|
(fTestComplete)=>
|
|
47
41
|
{
|
|
48
|
-
let _Manyfest = new libManyfest(
|
|
42
|
+
let _Manyfest = new libManyfest();
|
|
49
43
|
Expect(_Manyfest.scope)
|
|
50
44
|
.to.be.a('string', 'Manyfest should have a scope.');
|
|
51
45
|
Expect(_Manyfest.scope)
|
|
@@ -55,113 +49,5 @@ suite
|
|
|
55
49
|
);
|
|
56
50
|
}
|
|
57
51
|
);
|
|
58
|
-
|
|
59
|
-
suite
|
|
60
|
-
(
|
|
61
|
-
'Object Access',
|
|
62
|
-
()=>
|
|
63
|
-
{
|
|
64
|
-
test
|
|
65
|
-
(
|
|
66
|
-
'Properties should be gettable and settable without a schema.',
|
|
67
|
-
(fTestComplete)=>
|
|
68
|
-
{
|
|
69
|
-
let _Manyfest = new libManyfest({});
|
|
70
|
-
let _SimpleObject = {Name:'Bob',Age:31,Pets:{Fido:'Dog',Spot:'Cat'}};
|
|
71
|
-
|
|
72
|
-
Expect(_Manyfest.getValueAtAddress(_SimpleObject,'Name'))
|
|
73
|
-
.to.equal('Bob');
|
|
74
|
-
|
|
75
|
-
_Manyfest.setValueAtAddress(_SimpleObject,'Name','Jim');
|
|
76
|
-
|
|
77
|
-
Expect(_Manyfest.getValueAtAddress(_SimpleObject,'Name'))
|
|
78
|
-
.to.equal('Jim');
|
|
79
|
-
|
|
80
|
-
fTestComplete();
|
|
81
|
-
}
|
|
82
|
-
);
|
|
83
|
-
test
|
|
84
|
-
(
|
|
85
|
-
'Properties should be accessible via Hash.',
|
|
86
|
-
(fTestComplete)=>
|
|
87
|
-
{
|
|
88
|
-
let animalManyfest = new libManyfest(
|
|
89
|
-
{
|
|
90
|
-
"Scope": "Animal",
|
|
91
|
-
"Descriptors":
|
|
92
|
-
{
|
|
93
|
-
"IDAnimal": { "Name":"Database ID", "Description":"The unique integer-based database identifier for an Animal record.", "DataType":"Integer" },
|
|
94
|
-
"Name": { "Description":"The animal's colloquial species name (e.g. Rabbit, Dog, Bear, Mongoose)." },
|
|
95
|
-
"Type": { "Description":"Whether or not the animal is wild, domesticated, agricultural, in a research lab or a part of a zoo.." },
|
|
96
|
-
"MedicalStats":
|
|
97
|
-
{
|
|
98
|
-
"Name":"Medical Statistics", "Description":"Basic medical statistics for this animal"
|
|
99
|
-
},
|
|
100
|
-
"MedicalStats.Temps.MinET": { "Name":"Minimum Environmental Temperature", "NameShort":"MinET", "Description":"Safest minimum temperature for this animal to survive in."},
|
|
101
|
-
"MedicalStats.Temps.MaxET": { "Name":"Maximum Environmental Temperature", "NameShort":"MaxET", "Description":"Safest maximum temperature for this animal to survive in."},
|
|
102
|
-
"MedicalStats.Temps.CET":
|
|
103
|
-
{
|
|
104
|
-
"Name":"Comfortable Environmental Temperature",
|
|
105
|
-
"NameShort":"Comf Env Temp",
|
|
106
|
-
"Hash":"ComfET",
|
|
107
|
-
"Description":"The most comfortable temperature for this animal to survive in."
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
Expect(animalManyfest.getValueByHash({MedicalStats: { Temps: { CET:200 }},Name:'Froggy'}, 'ComfET'))
|
|
113
|
-
.to.equal(200);
|
|
114
|
-
|
|
115
|
-
fTestComplete();
|
|
116
|
-
}
|
|
117
|
-
);
|
|
118
|
-
test
|
|
119
|
-
(
|
|
120
|
-
'Validate should check that required elements exist',
|
|
121
|
-
(fTestComplete)=>
|
|
122
|
-
{
|
|
123
|
-
let animalManyfest = new libManyfest(
|
|
124
|
-
{
|
|
125
|
-
"Scope": "Animal",
|
|
126
|
-
"Descriptors":
|
|
127
|
-
{
|
|
128
|
-
"IDAnimal": { "Name":"Database ID", "Description":"The unique integer-based database identifier for an Animal record.", "DataType":"Integer" },
|
|
129
|
-
"Name": { "Required":true, "Description":"The animal's colloquial species name (e.g. Rabbit, Dog, Bear, Mongoose)." }
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
let tmpValidationResults = animalManyfest.validate({MedicalStats: { Temps: { CET:200 }},Name:'Froggy'});
|
|
134
|
-
|
|
135
|
-
Expect(tmpValidationResults.Error)
|
|
136
|
-
.to.equal(null);
|
|
137
|
-
|
|
138
|
-
fTestComplete();
|
|
139
|
-
}
|
|
140
|
-
);
|
|
141
|
-
test
|
|
142
|
-
(
|
|
143
|
-
'Validate should error when required elements do not exist',
|
|
144
|
-
(fTestComplete)=>
|
|
145
|
-
{
|
|
146
|
-
let animalManyfest = new libManyfest(
|
|
147
|
-
{
|
|
148
|
-
"Scope": "Animal",
|
|
149
|
-
"Descriptors":
|
|
150
|
-
{
|
|
151
|
-
"IDAnimal": { "Name":"Database ID", "Description":"The unique integer-based database identifier for an Animal record.", "DataType":"Integer" },
|
|
152
|
-
"Name": { "Required":true, "Description":"The animal's colloquial species name (e.g. Rabbit, Dog, Bear, Mongoose)." }
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
let tmpValidationResults = animalManyfest.validate({MedicalStats: { Temps: { CET:200 }}});
|
|
157
|
-
|
|
158
|
-
Expect(tmpValidationResults.Error)
|
|
159
|
-
.to.equal(true);
|
|
160
|
-
|
|
161
|
-
fTestComplete();
|
|
162
|
-
}
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
);
|
|
166
52
|
}
|
|
167
53
|
);
|