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,166 @@
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
+ let _SampleDataArchiveOrgFrankenberry = require('./Data-Archive-org-Frankenberry.json');
15
+
16
+ suite
17
+ (
18
+ 'Manyfest Hash Translations',
19
+ function()
20
+ {
21
+ setup (()=> {} );
22
+
23
+ suite
24
+ (
25
+ 'Translation Operations',
26
+ ()=>
27
+ {
28
+ test
29
+ (
30
+ 'A simple hash translation.',
31
+ (fTestComplete)=>
32
+ {
33
+ let _Manyfest = new libManyfest({ Scope:'Archive.org', Descriptors: {'metadata.creator': {Name:'Creator', Hash:'Creator'}}});
34
+ // Property not schema, accessed by hash:
35
+ let tmpCreator = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Creator');
36
+ Expect(tmpCreator)
37
+ .to.equal('General Mills');
38
+ // Create a translation between "Creator" and "Director"
39
+ _Manyfest.hashTranslations.addTranslation({"Director":"Creator"});
40
+ // Creator should still work
41
+ tmpCreator = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Creator');
42
+ Expect(tmpCreator)
43
+ .to.equal('General Mills');
44
+ // Director should also work
45
+ tmpCreator = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Director');
46
+ Expect(tmpCreator)
47
+ .to.equal('General Mills');
48
+
49
+ fTestComplete();
50
+ }
51
+ );
52
+ test
53
+ (
54
+ 'Multiple translations.',
55
+ (fTestComplete)=>
56
+ {
57
+ let _Manyfest = new libManyfest({ Scope:'Archive.org', Descriptors: {'metadata.creator': {Name:'Creator', Hash:'Creator'}}});
58
+ // Property not schema, accessed by hash:
59
+ let tmpCreator = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Creator');
60
+ Expect(tmpCreator).to.equal('General Mills');
61
+ // Create a translation between "Creator" and "Director" as well as "Author"
62
+ _Manyfest.hashTranslations.addTranslation({"Director":"Creator", "Author":"Creator"});
63
+ // Creator should still work
64
+ tmpCreator = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Creator');
65
+ Expect(tmpCreator).to.equal('General Mills');
66
+ // Director should also work
67
+ Expect(_Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Director')).to.equal('General Mills');
68
+ // And Author!
69
+ Expect(_Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Author')).to.equal('General Mills');
70
+
71
+ fTestComplete();
72
+ }
73
+ );
74
+ test
75
+ (
76
+ 'Remove a translation.',
77
+ (fTestComplete)=>
78
+ {
79
+ let _Manyfest = new libManyfest({ Scope:'Archive.org', Descriptors: {'metadata.creator': {Name:'Creator', Hash:'Creator'}}});
80
+ // Property not schema, accessed by hash:
81
+ let tmpCreator = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Creator');
82
+ Expect(tmpCreator).to.equal('General Mills');
83
+ // Create a translation between "Creator" and "Director" as well as "Author"
84
+ _Manyfest.hashTranslations.addTranslation({"Director":"Creator", "Author":"Creator"});
85
+ Expect(tmpCreator).to.equal('General Mills');
86
+ // Director should also work
87
+ Expect(_Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Director')).to.equal('General Mills');
88
+ // And Author!
89
+ Expect(_Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Author')).to.equal('General Mills');
90
+ // Now remove Director
91
+ _Manyfest.hashTranslations.removeTranslation('Director');
92
+ Expect(_Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Author')).to.equal('General Mills');
93
+ Expect(_Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Director')).to.equal(undefined);
94
+
95
+ fTestComplete();
96
+ }
97
+ );
98
+ test
99
+ (
100
+ 'Remove multiple translations.',
101
+ (fTestComplete)=>
102
+ {
103
+ let _Manyfest = new libManyfest({ Scope:'Archive.org', Descriptors: {'metadata.creator': {Name:'Creator', Hash:'Creator'}}});
104
+ // Property not schema, accessed by hash:
105
+ let tmpCreator = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Creator');
106
+ Expect(tmpCreator).to.equal('General Mills');
107
+ // Create a translation between "Creator" and "Director" as well as "Author"
108
+ _Manyfest.hashTranslations.addTranslation({"Director":"Creator", "Author":"Creator", "Songwriter":"Creator"});
109
+ Expect(tmpCreator).to.equal('General Mills');
110
+ // Director should also work
111
+ Expect(_Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Director')).to.equal('General Mills');
112
+ // And Author!
113
+ Expect(_Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Author')).to.equal('General Mills');
114
+ // Now remove Director
115
+ _Manyfest.hashTranslations.removeTranslation({'Director':true,'Author':'TheseValuesDontMatter'});
116
+ Expect(_Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Author')).to.equal(undefined);
117
+ Expect(_Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Director')).to.equal(undefined);
118
+ Expect(_Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Songwriter')).to.equal('General Mills');
119
+
120
+ fTestComplete();
121
+ }
122
+ );
123
+ test
124
+ (
125
+ 'Remove all translations.',
126
+ (fTestComplete)=>
127
+ {
128
+ let _Manyfest = new libManyfest({ Scope:'Archive.org', Descriptors: {'metadata.creator': {Name:'Creator', Hash:'Creator'}}});
129
+ // Property not schema, accessed by hash:
130
+ let tmpCreator = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Creator');
131
+ Expect(tmpCreator).to.equal('General Mills');
132
+ // Create a translation between "Creator" and "Director" as well as "Author"
133
+ _Manyfest.hashTranslations.addTranslation({"Director":"Creator", "Author":"Creator", "Songwriter":"Creator"});
134
+ Expect(tmpCreator).to.equal('General Mills');
135
+ // Director should also work
136
+ Expect(_Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Director')).to.equal('General Mills');
137
+ // And Author!
138
+ Expect(_Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Author')).to.equal('General Mills');
139
+ // Now remove Director
140
+ _Manyfest.hashTranslations.clearTranslations();
141
+ Expect(_Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Author')).to.equal(undefined);
142
+ Expect(_Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Director')).to.equal(undefined);
143
+ Expect(_Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Songwriter')).to.equal(undefined);
144
+ Expect(_Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'Creator')).to.equal('General Mills');
145
+
146
+ fTestComplete();
147
+ }
148
+ );
149
+ test
150
+ (
151
+ 'Add a bogus translation.',
152
+ (fTestComplete)=>
153
+ {
154
+ let _Manyfest = new libManyfest({ Scope:'Archive.org', Descriptors: {'metadata.creator': {Name:'Creator', Hash:'Creator'}}});
155
+
156
+ Expect(_Manyfest.hashTranslations.addTranslation('THIS SHOULD BE AN OBJECT')).to.equal(false);
157
+
158
+ Expect(_Manyfest.hashTranslations.translationCount()).to.equal(0);
159
+
160
+ fTestComplete();
161
+ }
162
+ );
163
+ }
164
+ );
165
+ }
166
+ );
@@ -0,0 +1,140 @@
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 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
+ );
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Unit tests for Meadow
2
+ * Unit tests for Manyfest
3
3
  *
4
4
  * @license MIT
5
5
  *
@@ -15,43 +15,41 @@ let _SampleDataArchiveOrgFrankenberry = require('./Data-Archive-org-Frankenberry
15
15
 
16
16
  suite
17
17
  (
18
- 'Manyfest Object Access',
18
+ 'Manyfest Object Read',
19
19
  function()
20
20
  {
21
21
  setup (()=> {} );
22
22
 
23
23
  suite
24
24
  (
25
- 'Object Property Manipulation',
25
+ 'Basic Read',
26
26
  ()=>
27
27
  {
28
28
  test
29
29
  (
30
- 'Properties should be gettable and settable without a schema.',
30
+ 'It should be trivial to access subproperties without a schema.',
31
31
  (fTestComplete)=>
32
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');
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 or without schema.',
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 in schema:
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(tmpTitle)
54
- .to.equal('Franken Berry / Count Chocula : Tevevision Commercial 1971');
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
- 'Properties should be accessible via Hash.',
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
- 'Validate should check that required elements exist',
114
+ 'Access specific boxed properties',
98
115
  (fTestComplete)=>
99
116
  {
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
-
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
- 'Validate should error when required elements do not exist',
126
+ 'Attempt to access specific boxed properties that do not exist',
121
127
  (fTestComplete)=>
122
128
  {
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
-
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,93 @@
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
+ let _SampleDataArchiveOrgFrankenberry = require('./Data-Archive-org-Frankenberry.json');
15
+
16
+ suite
17
+ (
18
+ 'Manyfest Schema Manipulation',
19
+ function()
20
+ {
21
+ setup (()=> {} );
22
+
23
+ suite
24
+ (
25
+ 'Address Mapping Resolution',
26
+ ()=>
27
+ {
28
+ test
29
+ (
30
+ 'We should be able to remap properties in place.',
31
+ (fTestComplete)=>
32
+ {
33
+ let tmpSchemaDescriptors = (
34
+ {
35
+ "a": { "Hash": "a", "Type": "Number" },
36
+ "b": { "Hash": "b", "Type": "Number" }
37
+ });
38
+
39
+ let tmpTranslationTable = (
40
+ {
41
+ "a": "CarrotCost",
42
+ "b": "AppleCost"
43
+ });
44
+
45
+ Expect(tmpSchemaDescriptors.a.Hash).to.equal('a');
46
+
47
+ let _Manyfest = new libManyfest();
48
+ // Now remap the schema (in-place)
49
+ _Manyfest.schemaManipulations.resolveAddressMappings(tmpSchemaDescriptors, tmpTranslationTable);
50
+
51
+ // The schema should be fundamentally altered to point these addresses to the old hashes
52
+ Expect(tmpSchemaDescriptors.CarrotCost.Hash).to.equal('a');
53
+ Expect(tmpSchemaDescriptors.AppleCost.Hash).to.equal('b');
54
+
55
+ fTestComplete();
56
+ }
57
+ );
58
+ test
59
+ (
60
+ 'We should be able to remap properties safely.',
61
+ (fTestComplete)=>
62
+ {
63
+ let tmpSchemaDescriptors = (
64
+ {
65
+ "a": { "Hash": "a", "Type": "Number" },
66
+ "b": { "Hash": "b", "Type": "Number" }
67
+ });
68
+
69
+ let tmpTranslationTable = (
70
+ {
71
+ "a": "CarrotCost",
72
+ "b": "AppleCost"
73
+ });
74
+
75
+ Expect(tmpSchemaDescriptors.a.Hash).to.equal('a');
76
+
77
+ let _Manyfest = new libManyfest();
78
+ // Now remap the schema (in-place)
79
+ let tmpNewSchemaDescriptors = _Manyfest.schemaManipulations.safeResolveAddressMappings(tmpSchemaDescriptors, tmpTranslationTable);
80
+
81
+ // The schema should be safe
82
+ Expect(tmpSchemaDescriptors.a.Hash).to.equal('a');
83
+ // And a new schema should have been created with the alterations
84
+ Expect(tmpNewSchemaDescriptors.CarrotCost.Hash).to.equal('a');
85
+ Expect(tmpNewSchemaDescriptors.AppleCost.Hash).to.equal('b');
86
+
87
+ fTestComplete();
88
+ }
89
+ );
90
+ }
91
+ );
92
+ }
93
+ );
@@ -0,0 +1,82 @@
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
+ 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
+ );