manyfest 1.0.2 → 1.0.4

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,161 @@
1
+ /**
2
+ * Unit tests for Manyfest
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
+ );
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Unit tests for Meadow
2
+ * Unit tests for Manyfest
3
3
  *
4
4
  * @license MIT
5
5
  *
@@ -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
  }
@@ -1,80 +0,0 @@
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
- let _SampleDataWeather = require('./Data-Yahoo-Weather.json');
16
-
17
- suite
18
- (
19
- 'Advanced Object Access',
20
- function()
21
- {
22
- setup (()=> {} );
23
-
24
- suite
25
- (
26
- 'Advanced Object Reading (with Arrays and Boxed Property addresses)',
27
- ()=>
28
- {
29
- test
30
- (
31
- 'Access specific array elements',
32
- (fTestComplete)=>
33
- {
34
- let _Manyfest = new libManyfest();
35
- let tmpDog = _Manyfest.getValueAtAddress({Dogs:['Fido','Spot','Trinity']}, 'Dogs[1]');
36
- Expect(tmpDog)
37
- .to.equal('Spot');
38
- fTestComplete();
39
- }
40
- );
41
- test
42
- (
43
- 'Access specific boxed properties',
44
- (fTestComplete)=>
45
- {
46
- let _Manyfest = new libManyfest();
47
- let tmpDog = _Manyfest.getValueAtAddress({Dogs:{RunnerUp:'Fido',Loser:'Spot',Winner:'Trinity'}}, 'Dogs["Winner"]');
48
- Expect(tmpDog)
49
- .to.equal('Trinity');
50
- fTestComplete();
51
- }
52
- );
53
- test
54
- (
55
- 'Attempt to access specific boxed properties that do not exist',
56
- (fTestComplete)=>
57
- {
58
- let _Manyfest = new libManyfest();
59
- let tmpDog = _Manyfest.getValueAtAddress({Dogs:{RunnerUp:'Fido',Loser:'Spot',Winner:'Trinity'}}, 'Dogs["Disqualified"]');
60
- Expect(tmpDog)
61
- .to.be.an('undefined');
62
- fTestComplete();
63
- }
64
- );
65
- test
66
- (
67
- 'Access nested box properties',
68
- (fTestComplete)=>
69
- {
70
- let _Manyfest = new libManyfest();
71
- let tmpDog = _Manyfest.getValueAtAddress({Dogs:{RunnerUp:{Name:'Fido',Speed:100},Loser:{Name:'Spot'},Winner:{Name:'Trinity'}}}, 'Dogs["RunnerUp"].Name');
72
- Expect(tmpDog)
73
- .to.equal('Fido');
74
- fTestComplete();
75
- }
76
- );
77
- }
78
- )
79
- }
80
- );