manyfest 1.0.2 → 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 +29 -11
- package/package.json +3 -2
- package/source/Manyfest-LogToConsole.js +1 -1
- package/source/Manyfest-ObjectAddressResolver.js +585 -0
- package/source/Manyfest.js +178 -251
- package/test/Manyfest_Object_CheckExistence_tests.js +70 -0
- package/test/Manyfest_Object_Populate_tests.js +140 -0
- package/test/{Manyfest_ObjectAccess_tests.js → Manyfest_Object_Read_tests.js} +73 -51
- package/test/Manyfest_Object_Validate_tests.js +82 -0
- package/test/Manyfest_Object_Write_tests.js +161 -0
- package/test/Manyfest_tests.js +49 -0
- package/test/Manyfest_AdvancedObjectAccess_tests.js +0 -80
|
@@ -0,0 +1,140 @@
|
|
|
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 Population',
|
|
17
|
+
function()
|
|
18
|
+
{
|
|
19
|
+
setup (()=> {} );
|
|
20
|
+
|
|
21
|
+
suite
|
|
22
|
+
(
|
|
23
|
+
'Basic Population',
|
|
24
|
+
()=>
|
|
25
|
+
{
|
|
26
|
+
test
|
|
27
|
+
(
|
|
28
|
+
'Default properties should be auto created on populateDefaults.',
|
|
29
|
+
(fTestComplete)=>
|
|
30
|
+
{
|
|
31
|
+
let animalManyfest = new libManyfest(
|
|
32
|
+
{
|
|
33
|
+
"Scope": "Animal",
|
|
34
|
+
"Descriptors":
|
|
35
|
+
{
|
|
36
|
+
"IDAnimal": { "Name":"Database ID", "Description":"The unique integer-based database identifier for an Animal record.", "DataType":"Integer" },
|
|
37
|
+
"Name": { "Required":true, "Description":"The animal's colloquial species name (e.g. Rabbit, Dog, Bear, Mongoose).", "Default":"Jane Doe" }
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
let tmpDefaultObject = animalManyfest.populateDefaults();
|
|
42
|
+
|
|
43
|
+
Expect(tmpDefaultObject.Name)
|
|
44
|
+
.to.equal('Jane Doe');
|
|
45
|
+
Expect(tmpDefaultObject.hasOwnProperty('IDAnimal'))
|
|
46
|
+
.to.equal(false);
|
|
47
|
+
|
|
48
|
+
fTestComplete();
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
test
|
|
52
|
+
(
|
|
53
|
+
'All properties should be auto created on Populate.',
|
|
54
|
+
(fTestComplete)=>
|
|
55
|
+
{
|
|
56
|
+
let animalManyfest = new libManyfest(
|
|
57
|
+
{
|
|
58
|
+
"Scope": "Animal",
|
|
59
|
+
"Descriptors":
|
|
60
|
+
{
|
|
61
|
+
"IDAnimal": { "Name":"Database ID", "Description":"The unique integer-based database identifier for an Animal record.", "DataType":"Integer" },
|
|
62
|
+
"Name": { "Required":true, "Description":"The animal's colloquial species name (e.g. Rabbit, Dog, Bear, Mongoose).", "Default":"Jane Doe" }
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
let tmpDefaultObject = animalManyfest.populateObject();
|
|
67
|
+
|
|
68
|
+
Expect(tmpDefaultObject.Name)
|
|
69
|
+
.to.equal('Jane Doe');
|
|
70
|
+
Expect(tmpDefaultObject.hasOwnProperty('IDAnimal'))
|
|
71
|
+
.to.equal(true);
|
|
72
|
+
Expect(tmpDefaultObject.IDAnimal)
|
|
73
|
+
.to.equal(0);
|
|
74
|
+
|
|
75
|
+
fTestComplete();
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
test
|
|
79
|
+
(
|
|
80
|
+
'We should be able to pass a custom filter to populate the object.',
|
|
81
|
+
(fTestComplete)=>
|
|
82
|
+
{
|
|
83
|
+
let animalManyfest = new libManyfest(
|
|
84
|
+
{
|
|
85
|
+
"Scope": "Animal",
|
|
86
|
+
"Descriptors":
|
|
87
|
+
{
|
|
88
|
+
"IDAnimal": { "Name":"Database ID", "Description":"The unique integer-based database identifier for an Animal record.", "DataType":"Integer" },
|
|
89
|
+
"Name": { "Required":true, "Description":"The animal's colloquial species name (e.g. Rabbit, Dog, Bear, Mongoose).", "Default":"Jane Doe" }
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
let tmpDefaultObject = animalManyfest.populateObject(undefined, false, (pDescriptor) => { return pDescriptor.Name == 'Database ID' });
|
|
94
|
+
|
|
95
|
+
Expect(tmpDefaultObject.Name)
|
|
96
|
+
.to.equal(undefined);
|
|
97
|
+
Expect(tmpDefaultObject.hasOwnProperty('IDAnimal'))
|
|
98
|
+
.to.equal(true);
|
|
99
|
+
Expect(tmpDefaultObject.IDAnimal)
|
|
100
|
+
.to.equal(0);
|
|
101
|
+
|
|
102
|
+
fTestComplete();
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
test
|
|
106
|
+
(
|
|
107
|
+
'We should be able to force overwrites on properties.',
|
|
108
|
+
(fTestComplete)=>
|
|
109
|
+
{
|
|
110
|
+
let tmpObject = { "Name": "Jennifer" };
|
|
111
|
+
let animalManyfest = new libManyfest(
|
|
112
|
+
{
|
|
113
|
+
"Scope": "Animal",
|
|
114
|
+
"Descriptors":
|
|
115
|
+
{
|
|
116
|
+
"IDAnimal": { "Name":"Database ID", "Description":"The unique integer-based database identifier for an Animal record.", "DataType":"Integer" },
|
|
117
|
+
"Name": { "Required":true, "Description":"The animal's colloquial species name (e.g. Rabbit, Dog, Bear, Mongoose).", "Default":"Jane Doe" }
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
Expect(tmpObject.Name)
|
|
122
|
+
.to.equal("Jennifer");
|
|
123
|
+
|
|
124
|
+
animalManyfest.populateDefaults(tmpObject, true);
|
|
125
|
+
|
|
126
|
+
Expect(tmpObject.hasOwnProperty('IDAnimal'))
|
|
127
|
+
.to.equal(false);
|
|
128
|
+
|
|
129
|
+
// Because we told it to force overwrites, it should overwrite the Name.
|
|
130
|
+
Expect(tmpObject.Name)
|
|
131
|
+
.to.equal("Jane Doe");
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
fTestComplete();
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
);
|
|
@@ -15,43 +15,41 @@ let _SampleDataArchiveOrgFrankenberry = require('./Data-Archive-org-Frankenberry
|
|
|
15
15
|
|
|
16
16
|
suite
|
|
17
17
|
(
|
|
18
|
-
'Manyfest Object
|
|
18
|
+
'Manyfest Object Read',
|
|
19
19
|
function()
|
|
20
20
|
{
|
|
21
21
|
setup (()=> {} );
|
|
22
22
|
|
|
23
23
|
suite
|
|
24
24
|
(
|
|
25
|
-
'
|
|
25
|
+
'Basic Read',
|
|
26
26
|
()=>
|
|
27
27
|
{
|
|
28
28
|
test
|
|
29
29
|
(
|
|
30
|
-
'
|
|
30
|
+
'It should be trivial to access subproperties without a schema.',
|
|
31
31
|
(fTestComplete)=>
|
|
32
32
|
{
|
|
33
|
-
let _Manyfest = new libManyfest({});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
Expect(
|
|
39
|
-
.to.equal(
|
|
33
|
+
let _Manyfest = new libManyfest({ Scope:'Archive.org', Descriptors: {'metadata.creator': {Name:'Creator', Hash:'Creator'}}});
|
|
34
|
+
// Property not in schema:
|
|
35
|
+
let tmpTitle = _Manyfest.getValueAtAddress(_SampleDataArchiveOrgFrankenberry, 'metadata.title');
|
|
36
|
+
Expect(tmpTitle)
|
|
37
|
+
.to.equal('Franken Berry / Count Chocula : Tevevision Commercial 1971');
|
|
38
|
+
Expect(tmpTitle)
|
|
39
|
+
.to.equal(_SampleDataArchiveOrgFrankenberry.metadata.title);
|
|
40
40
|
fTestComplete();
|
|
41
41
|
}
|
|
42
42
|
);
|
|
43
43
|
test
|
|
44
44
|
(
|
|
45
|
-
'It should be trivial to access subproperties with
|
|
45
|
+
'It should be trivial to access subproperties with a schema by hash.',
|
|
46
46
|
(fTestComplete)=>
|
|
47
47
|
{
|
|
48
48
|
let _Manyfest = new libManyfest({ Scope:'Archive.org', Descriptors: {'metadata.creator': {Name:'Creator', Hash:'Creator'}}});
|
|
49
|
-
// Property not
|
|
50
|
-
let tmpTitle = _Manyfest.getValueAtAddress(_SampleDataArchiveOrgFrankenberry, 'metadata.title');
|
|
51
|
-
// Property in schema
|
|
49
|
+
// Property not schema, accessed by hash:
|
|
52
50
|
let tmpCreator = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Creator');
|
|
53
|
-
Expect(
|
|
54
|
-
.to.equal(
|
|
51
|
+
Expect(_SampleDataArchiveOrgFrankenberry.metadata.creator)
|
|
52
|
+
.to.equal(tmpCreator);
|
|
55
53
|
Expect(tmpCreator)
|
|
56
54
|
.to.equal('General Mills');
|
|
57
55
|
fTestComplete();
|
|
@@ -59,7 +57,7 @@ suite
|
|
|
59
57
|
);
|
|
60
58
|
test
|
|
61
59
|
(
|
|
62
|
-
'
|
|
60
|
+
'Exercise more hash accesss scenarios..',
|
|
63
61
|
(fTestComplete)=>
|
|
64
62
|
{
|
|
65
63
|
let animalManyfest = new libManyfest(
|
|
@@ -91,53 +89,77 @@ suite
|
|
|
91
89
|
|
|
92
90
|
fTestComplete();
|
|
93
91
|
}
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
suite
|
|
96
|
+
(
|
|
97
|
+
'Advanced Read (with Arrays and Boxed Property addresses)',
|
|
98
|
+
()=>
|
|
99
|
+
{
|
|
100
|
+
test
|
|
101
|
+
(
|
|
102
|
+
'Access specific array elements',
|
|
103
|
+
(fTestComplete)=>
|
|
104
|
+
{
|
|
105
|
+
let _Manyfest = new libManyfest();
|
|
106
|
+
let tmpDog = _Manyfest.getValueAtAddress({Dogs:['Fido','Spot','Trinity']}, 'Dogs[1]');
|
|
107
|
+
Expect(tmpDog)
|
|
108
|
+
.to.equal('Spot');
|
|
109
|
+
fTestComplete();
|
|
110
|
+
}
|
|
94
111
|
);
|
|
95
112
|
test
|
|
96
113
|
(
|
|
97
|
-
'
|
|
114
|
+
'Access specific boxed properties',
|
|
98
115
|
(fTestComplete)=>
|
|
99
116
|
{
|
|
100
|
-
let
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
117
|
+
let _Manyfest = new libManyfest();
|
|
118
|
+
let tmpDog = _Manyfest.getValueAtAddress({Dogs:{RunnerUp:'Fido',Loser:'Spot',Winner:'Trinity'}}, 'Dogs["Winner"]');
|
|
119
|
+
Expect(tmpDog)
|
|
120
|
+
.to.equal('Trinity');
|
|
115
121
|
fTestComplete();
|
|
116
122
|
}
|
|
117
|
-
);
|
|
123
|
+
);
|
|
118
124
|
test
|
|
119
125
|
(
|
|
120
|
-
'
|
|
126
|
+
'Attempt to access specific boxed properties that do not exist',
|
|
121
127
|
(fTestComplete)=>
|
|
122
128
|
{
|
|
123
|
-
let
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
let tmpValidationResults = animalManyfest.validate({MedicalStats: { Temps: { CET:200 }}});
|
|
134
|
-
|
|
135
|
-
Expect(tmpValidationResults.Error)
|
|
136
|
-
.to.equal(true);
|
|
137
|
-
|
|
129
|
+
let _Manyfest = new libManyfest();
|
|
130
|
+
let tmpDog = _Manyfest.getValueAtAddress({Dogs:{RunnerUp:'Fido',Loser:'Spot',Winner:'Trinity'}}, 'Dogs["Disqualified"]');
|
|
131
|
+
Expect(tmpDog)
|
|
132
|
+
.to.be.an('undefined');
|
|
133
|
+
let tmpWinner = _Manyfest.getValueAtAddress({Dogs:{RunnerUp:'Fido',Loser:'Spot',Winner:'Trinity'}}, 'Dogs["Winner"]');
|
|
134
|
+
Expect(tmpWinner)
|
|
135
|
+
.to.equal('Trinity');
|
|
138
136
|
fTestComplete();
|
|
139
137
|
}
|
|
140
|
-
);
|
|
138
|
+
);
|
|
139
|
+
test
|
|
140
|
+
(
|
|
141
|
+
'Access nested box properties',
|
|
142
|
+
(fTestComplete)=>
|
|
143
|
+
{
|
|
144
|
+
let _Manyfest = new libManyfest();
|
|
145
|
+
let tmpDog = _Manyfest.getValueAtAddress({Dogs:{RunnerUp:{Name:'Fido',Speed:100},Loser:{Name:'Spot'},Winner:{Name:'Trinity'}}}, 'Dogs["RunnerUp"].Name');
|
|
146
|
+
Expect(tmpDog)
|
|
147
|
+
.to.equal('Fido');
|
|
148
|
+
fTestComplete();
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
test
|
|
152
|
+
(
|
|
153
|
+
'Access nested array properties',
|
|
154
|
+
(fTestComplete)=>
|
|
155
|
+
{
|
|
156
|
+
let _Manyfest = new libManyfest();
|
|
157
|
+
let tmpDog = _Manyfest.getValueAtAddress({Kennel:[{Name:'Fido',Speed:100},{Name:'Spot'},{Name:'Trinity'}]}, 'Kennel[1].Name');
|
|
158
|
+
Expect(tmpDog)
|
|
159
|
+
.to.equal('Spot');
|
|
160
|
+
fTestComplete();
|
|
161
|
+
}
|
|
162
|
+
);
|
|
141
163
|
}
|
|
142
164
|
);
|
|
143
165
|
}
|
|
@@ -0,0 +1,82 @@
|
|
|
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 _AnimalManyfestSchema = (
|
|
15
|
+
{
|
|
16
|
+
"Scope": "Animal",
|
|
17
|
+
"Descriptors":
|
|
18
|
+
{
|
|
19
|
+
"IDAnimal": { "Name":"Database ID", "Description":"The unique integer-based database identifier for an Animal record.", "DataType":"Integer" },
|
|
20
|
+
"Name": { "Required":true, "Description":"The animal's colloquial species name (e.g. Rabbit, Dog, Bear, Mongoose)." }
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
suite
|
|
25
|
+
(
|
|
26
|
+
'Manyfest Object Validation',
|
|
27
|
+
function()
|
|
28
|
+
{
|
|
29
|
+
setup (()=> {} );
|
|
30
|
+
|
|
31
|
+
suite
|
|
32
|
+
(
|
|
33
|
+
'Basic Validation',
|
|
34
|
+
()=>
|
|
35
|
+
{
|
|
36
|
+
test
|
|
37
|
+
(
|
|
38
|
+
'Validate should not error when all required elements exist.',
|
|
39
|
+
(fTestComplete)=>
|
|
40
|
+
{
|
|
41
|
+
let animalManyfest = new libManyfest(_AnimalManyfestSchema);
|
|
42
|
+
let tmpValidationResults = animalManyfest.validate({IDAnimal: 100, MedicalStats: { Temps: { CET:200 }},Name:'Froggy'});
|
|
43
|
+
|
|
44
|
+
Expect(tmpValidationResults.Error)
|
|
45
|
+
.to.equal(null);
|
|
46
|
+
|
|
47
|
+
fTestComplete();
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
test
|
|
51
|
+
(
|
|
52
|
+
'Validate should error when required elements do not exist.',
|
|
53
|
+
(fTestComplete)=>
|
|
54
|
+
{
|
|
55
|
+
let animalManyfest = new libManyfest(_AnimalManyfestSchema);
|
|
56
|
+
let tmpValidationResults = animalManyfest.validate({MedicalStats: { Temps: { CET:200 }}});
|
|
57
|
+
|
|
58
|
+
Expect(tmpValidationResults.Error)
|
|
59
|
+
.to.equal(true);
|
|
60
|
+
|
|
61
|
+
fTestComplete();
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
test
|
|
65
|
+
(
|
|
66
|
+
'Validate should be able to test for dates.',
|
|
67
|
+
(fTestComplete)=>
|
|
68
|
+
{
|
|
69
|
+
let animalManyfest = new libManyfest(_AnimalManyfestSchema);
|
|
70
|
+
let tmpValidationResults = animalManyfest.validate({IDAnimal: 100, MedicalStats: { Temps: { CET:200 }}});
|
|
71
|
+
|
|
72
|
+
Expect(tmpValidationResults.Error)
|
|
73
|
+
.to.equal(true);
|
|
74
|
+
|
|
75
|
+
fTestComplete();
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
);
|
|
@@ -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
|
@@ -35,6 +35,17 @@ suite
|
|
|
35
35
|
}
|
|
36
36
|
);
|
|
37
37
|
test
|
|
38
|
+
(
|
|
39
|
+
'The class should print an error message with a bad manifest.',
|
|
40
|
+
(fTestComplete)=>
|
|
41
|
+
{
|
|
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.');
|
|
45
|
+
fTestComplete();
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
test
|
|
38
49
|
(
|
|
39
50
|
'Default properties should be automatically set.',
|
|
40
51
|
(fTestComplete)=>
|
|
@@ -47,6 +58,44 @@ suite
|
|
|
47
58
|
fTestComplete();
|
|
48
59
|
}
|
|
49
60
|
);
|
|
61
|
+
test
|
|
62
|
+
(
|
|
63
|
+
'Exercise the default logging.',
|
|
64
|
+
(fTestComplete)=>
|
|
65
|
+
{
|
|
66
|
+
let _Manyfest = new libManyfest();
|
|
67
|
+
_Manyfest.logError('Error...');
|
|
68
|
+
_Manyfest.logInfo('Info...');
|
|
69
|
+
_Manyfest.logInfo();
|
|
70
|
+
|
|
71
|
+
fTestComplete();
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
test
|
|
75
|
+
(
|
|
76
|
+
'Pass in a custom logger.',
|
|
77
|
+
(fTestComplete)=>
|
|
78
|
+
{
|
|
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);
|
|
95
|
+
|
|
96
|
+
fTestComplete();
|
|
97
|
+
}
|
|
98
|
+
);
|
|
50
99
|
}
|
|
51
100
|
);
|
|
52
101
|
}
|