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.
@@ -0,0 +1,115 @@
1
+ {
2
+ "location": {
3
+ "woeid": 2502265,
4
+ "city": "Sunnyvale",
5
+ "region": " CA",
6
+ "country": "United States",
7
+ "lat": 37.371609,
8
+ "long": -122.038254,
9
+ "timezone_id": "America/Los_Angeles"
10
+ },
11
+ "current_observation": {
12
+ "wind": {
13
+ "chill": 59,
14
+ "direction": 165,
15
+ "speed": 8.7
16
+ },
17
+ "atmosphere": {
18
+ "humidity": 76,
19
+ "visibility": 10,
20
+ "pressure": 29.68
21
+ },
22
+ "astronomy": {
23
+ "sunrise": "7:23 am",
24
+ "sunset": "5:7 pm"
25
+ },
26
+ "condition": {
27
+ "text": "Scattered Showers",
28
+ "code": 39,
29
+ "temperature": 60
30
+ },
31
+ "pubDate": 1546992000
32
+ },
33
+ "forecasts": [
34
+ {
35
+ "day": "Tue",
36
+ "date": 1546934400,
37
+ "low": 52,
38
+ "high": 61,
39
+ "text": "Rain",
40
+ "code": 12
41
+ },
42
+ {
43
+ "day": "Wed",
44
+ "date": 1547020800,
45
+ "low": 51,
46
+ "high": 62,
47
+ "text": "Scattered Showers",
48
+ "code": 39
49
+ },
50
+ {
51
+ "day": "Thu",
52
+ "date": 1547107200,
53
+ "low": 46,
54
+ "high": 60,
55
+ "text": "Mostly Cloudy",
56
+ "code": 28
57
+ },
58
+ {
59
+ "day": "Fri",
60
+ "date": 1547193600,
61
+ "low": 48,
62
+ "high": 61,
63
+ "text": "Showers",
64
+ "code": 11
65
+ },
66
+ {
67
+ "day": "Sat",
68
+ "date": 1547280000,
69
+ "low": 47,
70
+ "high": 62,
71
+ "text": "Rain",
72
+ "code": 12
73
+ },
74
+ {
75
+ "day": "Sun",
76
+ "date": 1547366400,
77
+ "low": 48,
78
+ "high": 58,
79
+ "text": "Rain",
80
+ "code": 12
81
+ },
82
+ {
83
+ "day": "Mon",
84
+ "date": 1547452800,
85
+ "low": 47,
86
+ "high": 58,
87
+ "text": "Rain",
88
+ "code": 12
89
+ },
90
+ {
91
+ "day": "Tue",
92
+ "date": 1547539200,
93
+ "low": 46,
94
+ "high": 59,
95
+ "text": "Scattered Showers",
96
+ "code": 39
97
+ },
98
+ {
99
+ "day": "Wed",
100
+ "date": 1547625600,
101
+ "low": 49,
102
+ "high": 56,
103
+ "text": "Rain",
104
+ "code": 12
105
+ },
106
+ {
107
+ "day": "Thu",
108
+ "date": 1547712000,
109
+ "low": 49,
110
+ "high": 59,
111
+ "text": "Scattered Showers",
112
+ "code": 39
113
+ }
114
+ ]
115
+ }
@@ -0,0 +1,70 @@
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 Check Element Existence',
19
+ function()
20
+ {
21
+ setup (()=> {} );
22
+
23
+ suite
24
+ (
25
+ 'Basic Check Existence',
26
+ ()=>
27
+ {
28
+ test
29
+ (
30
+ 'It should be easy to check if an element exists by address.',
31
+ (fTestComplete)=>
32
+ {
33
+ let _Manyfest = new libManyfest({ Scope:'Archive.org', Descriptors: {'metadata.creator': {Name:'Creator', Hash:'Creator'}}});
34
+ // Property not in schema:
35
+ let tmpTitleExists = _Manyfest.checkAddressExists(_SampleDataArchiveOrgFrankenberry, 'metadata.title');
36
+ Expect(tmpTitleExists)
37
+ .to.equal(true);
38
+ fTestComplete();
39
+ }
40
+ );
41
+ test
42
+ (
43
+ 'If an element does not exist, checkAddressExists should return false.',
44
+ (fTestComplete)=>
45
+ {
46
+ let _Manyfest = new libManyfest({ Scope:'Archive.org', Descriptors: {'metadata.creator': {Name:'Creator', Hash:'Creator'}}});
47
+ // Property not in schema:
48
+ let tmpTitleExists = _Manyfest.checkAddressExists(_SampleDataArchiveOrgFrankenberry, 'metadata.someStrangeProperty');
49
+ Expect(tmpTitleExists)
50
+ .to.equal(false);
51
+ fTestComplete();
52
+ }
53
+ );
54
+ test
55
+ (
56
+ 'It should be trivial to access subproperties with a schema by hash.',
57
+ (fTestComplete)=>
58
+ {
59
+ let _Manyfest = new libManyfest({ Scope:'Archive.org', Descriptors: {'metadata.creator': {Name:'Creator', Hash:'Creator'}}});
60
+ // Property not schema, accessed by hash:
61
+ let tmpCreator = _Manyfest.checkAddressExistsByHash(_SampleDataArchiveOrgFrankenberry, 'Creator');
62
+ Expect(tmpCreator)
63
+ .to.equal(true);
64
+ fTestComplete();
65
+ }
66
+ );
67
+ }
68
+ );
69
+ }
70
+ );
@@ -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
+ );
@@ -0,0 +1,166 @@
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 Read',
19
+ function()
20
+ {
21
+ setup (()=> {} );
22
+
23
+ suite
24
+ (
25
+ 'Basic Read',
26
+ ()=>
27
+ {
28
+ test
29
+ (
30
+ 'It should be trivial to access subproperties without a schema.',
31
+ (fTestComplete)=>
32
+ {
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
+ fTestComplete();
41
+ }
42
+ );
43
+ test
44
+ (
45
+ 'It should be trivial to access subproperties with a schema by hash.',
46
+ (fTestComplete)=>
47
+ {
48
+ let _Manyfest = new libManyfest({ Scope:'Archive.org', Descriptors: {'metadata.creator': {Name:'Creator', Hash:'Creator'}}});
49
+ // Property not schema, accessed by hash:
50
+ let tmpCreator = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Creator');
51
+ Expect(_SampleDataArchiveOrgFrankenberry.metadata.creator)
52
+ .to.equal(tmpCreator);
53
+ Expect(tmpCreator)
54
+ .to.equal('General Mills');
55
+ fTestComplete();
56
+ }
57
+ );
58
+ test
59
+ (
60
+ 'Exercise more hash accesss scenarios..',
61
+ (fTestComplete)=>
62
+ {
63
+ let animalManyfest = new libManyfest(
64
+ {
65
+ "Scope": "Animal",
66
+ "Descriptors":
67
+ {
68
+ "IDAnimal": { "Name":"Database ID", "Description":"The unique integer-based database identifier for an Animal record.", "DataType":"Integer" },
69
+ "Name": { "Description":"The animal's colloquial species name (e.g. Rabbit, Dog, Bear, Mongoose)." },
70
+ "Type": { "Description":"Whether or not the animal is wild, domesticated, agricultural, in a research lab or a part of a zoo.." },
71
+ "MedicalStats":
72
+ {
73
+ "Name":"Medical Statistics", "Description":"Basic medical statistics for this animal"
74
+ },
75
+ "MedicalStats.Temps.MinET": { "Name":"Minimum Environmental Temperature", "NameShort":"MinET", "Description":"Safest minimum temperature for this animal to survive in."},
76
+ "MedicalStats.Temps.MaxET": { "Name":"Maximum Environmental Temperature", "NameShort":"MaxET", "Description":"Safest maximum temperature for this animal to survive in."},
77
+ "MedicalStats.Temps.CET":
78
+ {
79
+ "Name":"Comfortable Environmental Temperature",
80
+ "NameShort":"Comf Env Temp",
81
+ "Hash":"ComfET",
82
+ "Description":"The most comfortable temperature for this animal to survive in."
83
+ }
84
+ }
85
+ });
86
+
87
+ Expect(animalManyfest.getValueByHash({MedicalStats: { Temps: { CET:200 }},Name:'Froggy'}, 'ComfET'))
88
+ .to.equal(200);
89
+
90
+ fTestComplete();
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
+ }
111
+ );
112
+ test
113
+ (
114
+ 'Access specific boxed properties',
115
+ (fTestComplete)=>
116
+ {
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');
121
+ fTestComplete();
122
+ }
123
+ );
124
+ test
125
+ (
126
+ 'Attempt to access specific boxed properties that do not exist',
127
+ (fTestComplete)=>
128
+ {
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');
136
+ fTestComplete();
137
+ }
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
+ );
163
+ }
164
+ );
165
+ }
166
+ );
@@ -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
+ );