manyfest 1.0.1 → 1.0.3
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 +365 -21
- 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 +4 -3
- package/source/Manyfest-LogToConsole.js +1 -1
- package/source/Manyfest-ObjectAddressResolver.js +585 -0
- package/source/Manyfest.js +182 -112
- package/test/Data-Archive-org-Frankenberry.json +246 -0
- package/test/Data-Yahoo-Weather.json +115 -0
- package/test/Manyfest_Object_CheckExistence_tests.js +70 -0
- package/test/Manyfest_Object_Populate_tests.js +140 -0
- package/test/Manyfest_Object_Read_tests.js +166 -0
- package/test/Manyfest_Object_Validate_tests.js +82 -0
- package/test/Manyfest_Object_Write_tests.js +161 -0
- package/test/Manyfest_tests.js +34 -99
|
@@ -0,0 +1,161 @@
|
|
|
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
|
+
suite
|
|
15
|
+
(
|
|
16
|
+
'Manyfest Object Write',
|
|
17
|
+
function()
|
|
18
|
+
{
|
|
19
|
+
setup (()=> {} );
|
|
20
|
+
|
|
21
|
+
suite
|
|
22
|
+
(
|
|
23
|
+
'Basic Write',
|
|
24
|
+
()=>
|
|
25
|
+
{
|
|
26
|
+
test
|
|
27
|
+
(
|
|
28
|
+
'Properties should be settable without a schema.',
|
|
29
|
+
(fTestComplete)=>
|
|
30
|
+
{
|
|
31
|
+
let _Manyfest = new libManyfest({});
|
|
32
|
+
let _SimpleObject = {Name:'Bob',Age:31,Pets:{Fido:'Dog',Spot:'Cat'}};
|
|
33
|
+
Expect(_Manyfest.getValueAtAddress(_SimpleObject,'Name'))
|
|
34
|
+
.to.equal('Bob');
|
|
35
|
+
_Manyfest.setValueAtAddress(_SimpleObject,'Name','Jim');
|
|
36
|
+
Expect(_Manyfest.getValueAtAddress(_SimpleObject,'Name'))
|
|
37
|
+
.to.equal('Jim');
|
|
38
|
+
Expect(_SimpleObject.Name)
|
|
39
|
+
.to.equal('Jim');
|
|
40
|
+
fTestComplete();
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
test
|
|
44
|
+
(
|
|
45
|
+
'Properties should be settable with a schema by hash.',
|
|
46
|
+
(fTestComplete)=>
|
|
47
|
+
{
|
|
48
|
+
let _Manyfest = new libManyfest({ Scope:'BobsPets', Descriptors: {'Pets.Fido': {Name:'Favorite Pet', Hash:'Favorite'}}});
|
|
49
|
+
let _SimpleObject = {Name:'Bob',Age:31,Pets:{Fido:'Dog',Spot:'Cat'}};
|
|
50
|
+
Expect(_Manyfest.getValueAtAddress(_SimpleObject,'Pets.Fido'))
|
|
51
|
+
.to.equal('Dog');
|
|
52
|
+
// Set the favorite pet to be a Monkey because Monkeys rule
|
|
53
|
+
_Manyfest.setValueByHash(_SimpleObject,'Favorite','Monkey');
|
|
54
|
+
Expect(_Manyfest.getValueAtAddress(_SimpleObject,'Pets.Fido'))
|
|
55
|
+
.to.equal('Monkey');
|
|
56
|
+
Expect(_SimpleObject.Pets.Fido)
|
|
57
|
+
.to.equal('Monkey');
|
|
58
|
+
fTestComplete();
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
test
|
|
62
|
+
(
|
|
63
|
+
'Properties should be settable with a schema by address.',
|
|
64
|
+
(fTestComplete)=>
|
|
65
|
+
{
|
|
66
|
+
let _Manyfest = new libManyfest({ Scope:'BobsPets', Descriptors: {'Pets.Fido': {Name:'Favorite Pet', Hash:'Favorite'}}});
|
|
67
|
+
let _SimpleObject = {Name:'Bob',Age:31,Pets:{Fido:'Dog',Spot:'Cat'}};
|
|
68
|
+
Expect(_Manyfest.getValueAtAddress(_SimpleObject,'Pets.Fido'))
|
|
69
|
+
.to.equal('Dog');
|
|
70
|
+
// Set fido to be a Lemur
|
|
71
|
+
_Manyfest.setValueAtAddress(_SimpleObject,'Pets.Fido','Lemur');
|
|
72
|
+
Expect(_Manyfest.getValueAtAddress(_SimpleObject,'Pets.Fido'))
|
|
73
|
+
.to.equal('Lemur');
|
|
74
|
+
Expect(_SimpleObject.Pets.Fido)
|
|
75
|
+
.to.equal('Lemur');
|
|
76
|
+
fTestComplete();
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
suite
|
|
83
|
+
(
|
|
84
|
+
'Advanced Write (with Arrays and Boxed Property addresses)',
|
|
85
|
+
()=>
|
|
86
|
+
{
|
|
87
|
+
test
|
|
88
|
+
(
|
|
89
|
+
'Write specific array elements.',
|
|
90
|
+
(fTestComplete)=>
|
|
91
|
+
{
|
|
92
|
+
let _Manyfest = new libManyfest();
|
|
93
|
+
let _Object = {Dogs:['Fido','Spot','Trinity']};
|
|
94
|
+
_Manyfest.setValueAtAddress(_Object, 'Dogs[1]', 'Spotty')
|
|
95
|
+
Expect(_Object.Dogs[1])
|
|
96
|
+
.to.equal('Spotty');
|
|
97
|
+
fTestComplete();
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
test
|
|
101
|
+
(
|
|
102
|
+
'Write specific boxed properties.',
|
|
103
|
+
(fTestComplete)=>
|
|
104
|
+
{
|
|
105
|
+
let _Manyfest = new libManyfest();
|
|
106
|
+
let _Object = {Dogs:{RunnerUp:'Fido',Loser:'Spot',Winner:'Trinity'}};
|
|
107
|
+
_Manyfest.setValueAtAddress(_Object, 'Dogs["Loser"]', 'Jimbo');
|
|
108
|
+
Expect(_Object.Dogs.Loser)
|
|
109
|
+
.to.equal('Jimbo');
|
|
110
|
+
fTestComplete();
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
test
|
|
114
|
+
(
|
|
115
|
+
'Write to specific boxed properties that do not exist.',
|
|
116
|
+
(fTestComplete)=>
|
|
117
|
+
{
|
|
118
|
+
let _Manyfest = new libManyfest();
|
|
119
|
+
let _Object = {Dogs:{RunnerUp:'Fido',Loser:'Spot',Winner:'Trinity'}};
|
|
120
|
+
Expect(_Object.Dogs.Judge)
|
|
121
|
+
.to.be.an('undefined');
|
|
122
|
+
_Manyfest.setValueAtAddress(_Object, 'Dogs.Judge', 'Judgy Judy');
|
|
123
|
+
Expect(_Object.Dogs.Judge)
|
|
124
|
+
.to.equal('Judgy Judy');
|
|
125
|
+
fTestComplete();
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
test
|
|
129
|
+
(
|
|
130
|
+
'Write to nested box properties.',
|
|
131
|
+
(fTestComplete)=>
|
|
132
|
+
{
|
|
133
|
+
let _Manyfest = new libManyfest();
|
|
134
|
+
let _Object = {Dogs:{RunnerUp:{Name:'Fido',Speed:100},Loser:{Name:'Spot'},Winner:{Name:'Trinity'}}};
|
|
135
|
+
_Manyfest.setValueAtAddress(_Object, 'Dogs[`RunnerUp`].Speed', 300);
|
|
136
|
+
Expect(_Object.Dogs.RunnerUp.Speed)
|
|
137
|
+
.to.equal(300);
|
|
138
|
+
// Set a value for an address that doesn't exist.
|
|
139
|
+
_Manyfest.setValueAtAddress(_Object, 'Dogs[`Loser`].Speed', 10);
|
|
140
|
+
Expect(_Object.Dogs.Loser.Speed)
|
|
141
|
+
.to.equal(10);
|
|
142
|
+
fTestComplete();
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
test
|
|
146
|
+
(
|
|
147
|
+
'Write nested array properties',
|
|
148
|
+
(fTestComplete)=>
|
|
149
|
+
{
|
|
150
|
+
let _Manyfest = new libManyfest();
|
|
151
|
+
let _Object = {Kennel:[{Name:'Fido',Speed:100},{Name:'Spot'},{Name:'Trinity'}]};
|
|
152
|
+
_Manyfest.setValueAtAddress(_Object, 'Kennel[1].Name', 'Billy');
|
|
153
|
+
Expect(_Object.Kennel[1].Name)
|
|
154
|
+
.to.equal('Billy');
|
|
155
|
+
fTestComplete();
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
);
|
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
|
(
|
|
@@ -42,125 +36,66 @@ suite
|
|
|
42
36
|
);
|
|
43
37
|
test
|
|
44
38
|
(
|
|
45
|
-
'
|
|
39
|
+
'The class should print an error message with a bad manifest.',
|
|
46
40
|
(fTestComplete)=>
|
|
47
41
|
{
|
|
48
|
-
let _Manyfest = new libManyfest({});
|
|
49
|
-
Expect(_Manyfest
|
|
50
|
-
.to.be.
|
|
51
|
-
Expect(_Manyfest.scope)
|
|
52
|
-
.to.equal('DEFAULT', 'Manyfest should default to the Scope DEFAULT.');
|
|
42
|
+
let _Manyfest = new libManyfest({Scope:'BadManifest', Descriptors:'BadDescriptors'});
|
|
43
|
+
Expect(_Manyfest)
|
|
44
|
+
.to.be.an('object', 'Manyfest should initialize as an object with no parameters.');
|
|
53
45
|
fTestComplete();
|
|
54
46
|
}
|
|
55
47
|
);
|
|
56
|
-
}
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
suite
|
|
60
|
-
(
|
|
61
|
-
'Object Access',
|
|
62
|
-
()=>
|
|
63
|
-
{
|
|
64
48
|
test
|
|
65
49
|
(
|
|
66
|
-
'
|
|
50
|
+
'Default properties should be automatically set.',
|
|
67
51
|
(fTestComplete)=>
|
|
68
52
|
{
|
|
69
|
-
let _Manyfest = new libManyfest(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
Expect(_Manyfest.
|
|
73
|
-
.to.equal('
|
|
74
|
-
|
|
75
|
-
_Manyfest.setValueAtAddress(_SimpleObject,'Name','Jim');
|
|
76
|
-
|
|
77
|
-
Expect(_Manyfest.getValueAtAddress(_SimpleObject,'Name'))
|
|
78
|
-
.to.equal('Jim');
|
|
79
|
-
|
|
53
|
+
let _Manyfest = new libManyfest();
|
|
54
|
+
Expect(_Manyfest.scope)
|
|
55
|
+
.to.be.a('string', 'Manyfest should have a scope.');
|
|
56
|
+
Expect(_Manyfest.scope)
|
|
57
|
+
.to.equal('DEFAULT', 'Manyfest should default to the Scope DEFAULT.');
|
|
80
58
|
fTestComplete();
|
|
81
59
|
}
|
|
82
60
|
);
|
|
83
61
|
test
|
|
84
62
|
(
|
|
85
|
-
'
|
|
63
|
+
'Exercise the default logging.',
|
|
86
64
|
(fTestComplete)=>
|
|
87
65
|
{
|
|
88
|
-
let
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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);
|
|
66
|
+
let _Manyfest = new libManyfest();
|
|
67
|
+
_Manyfest.logError('Error...');
|
|
68
|
+
_Manyfest.logInfo('Info...');
|
|
69
|
+
_Manyfest.logInfo();
|
|
114
70
|
|
|
115
71
|
fTestComplete();
|
|
116
72
|
}
|
|
117
73
|
);
|
|
118
74
|
test
|
|
119
75
|
(
|
|
120
|
-
'
|
|
76
|
+
'Pass in a custom logger.',
|
|
121
77
|
(fTestComplete)=>
|
|
122
78
|
{
|
|
123
|
-
let
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
79
|
+
let tmpLogState = [];
|
|
80
|
+
let fWriteLog = (pLogLine, pLogObject) =>
|
|
81
|
+
{
|
|
82
|
+
tmpLogState.push(pLogLine);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
let _Manyfest = new libManyfest(undefined, fWriteLog, fWriteLog);
|
|
86
|
+
_Manyfest.logError('Error...');
|
|
87
|
+
Expect(tmpLogState.length)
|
|
88
|
+
.to.equal(1);
|
|
89
|
+
Expect(tmpLogState[0])
|
|
90
|
+
.to.equal('Error...');
|
|
91
|
+
_Manyfest.logInfo('Info...');
|
|
92
|
+
_Manyfest.logInfo();
|
|
93
|
+
Expect(tmpLogState.length)
|
|
94
|
+
.to.equal(3);
|
|
137
95
|
|
|
138
96
|
fTestComplete();
|
|
139
97
|
}
|
|
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
|
-
);
|
|
98
|
+
);
|
|
164
99
|
}
|
|
165
100
|
);
|
|
166
101
|
}
|