fable 3.0.85 → 3.0.87
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/debug/Harness.js +8 -10
- package/package.json +4 -3
- package/retold-harness/bookstore-serve-api.js +2 -2
- package/source/Fable.js +187 -50
- package/source/services/Fable-Service-Anticipate.js +1 -1
- package/source/services/Fable-Service-DataGeneration.js +1 -1
- package/source/services/Fable-Service-EnvironmentData-Web.js +1 -1
- package/source/services/Fable-Service-EnvironmentData.js +1 -1
- package/source/services/Fable-Service-FilePersistence-Web.js +18 -22
- package/source/services/Fable-Service-FilePersistence.js +51 -23
- package/source/services/Fable-Service-MetaTemplate.js +1 -1
- package/source/services/Fable-Service-Operation-DefaultSettings.js +4 -6
- package/source/services/Fable-Service-Operation.js +97 -3
- package/source/services/Fable-Service-RestClient.js +1 -1
- package/source/services/Fable-Service-Template.js +1 -1
- package/source/services/Fable-Service-Utility.js +3 -3
- package/test/Anticipate_tests.js +2 -2
- package/test/CSVParser_tests.js +1 -1
- package/test/Cache_tests.js +1 -1
- package/test/DataGeneration_tests.js +7 -7
- package/test/DateManipulation_tests.js +1 -1
- package/test/FableOperation_tests.js +33 -4
- package/test/FableServiceManager_tests.js +51 -51
- package/test/FilePersistence_tests.js +45 -12
- package/test/Manifest_tests.js +1 -1
- package/test/MetaTemplating_tests.js +1 -1
- package/test/RestClient_test.js +6 -6
- package/dist/fable.compatible.js +0 -3354
- package/dist/fable.compatible.min.js +0 -12
- package/dist/fable.compatible.min.js.map +0 -1
- package/dist/fable.js +0 -3354
- package/dist/fable.min.js +0 -12
- package/dist/fable.min.js.map +0 -1
- package/source/Fable-ServiceManager.js +0 -164
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const libFableServiceBase = require('
|
|
1
|
+
const libFableServiceBase = require('fable-serviceproviderbase');
|
|
2
2
|
|
|
3
3
|
const _OperationStatePrototypeString = JSON.stringify(require('./Fable-Service-Operation-DefaultSettings.js'));
|
|
4
4
|
|
|
@@ -18,15 +18,108 @@ class FableOperation extends libFableServiceBase
|
|
|
18
18
|
|
|
19
19
|
this.state = JSON.parse(_OperationStatePrototypeString);
|
|
20
20
|
|
|
21
|
+
this.stepMap = {};
|
|
22
|
+
this.stepFunctions = {};
|
|
23
|
+
|
|
21
24
|
// Match the service instantiation to the operation.
|
|
22
25
|
this.state.Metadata.Hash = this.Hash;
|
|
23
26
|
this.state.Metadata.UUID = this.UUID;
|
|
24
27
|
|
|
25
|
-
this.
|
|
28
|
+
this.state.Metadata.Name = (typeof(this.options.Name) == 'string') ? this.options.Name : `Unnamed Operation ${this.state.Metadata.UUID}`;
|
|
29
|
+
this.name = this.state.Metadata.Name;
|
|
26
30
|
|
|
27
31
|
this.log = this;
|
|
28
32
|
}
|
|
29
33
|
|
|
34
|
+
execute(fExecutionCompleteCallback)
|
|
35
|
+
{
|
|
36
|
+
if (this.state.Status.TimeStart)
|
|
37
|
+
{
|
|
38
|
+
return fExecutionCompleteCallback(new Error(`Operation [${this.state.Metadata.UUID}] ${this.state.Metadata.Name} has already been executed!`));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.state.Status.TimeStart = +new Date();
|
|
42
|
+
|
|
43
|
+
let tmpAnticipate = this.fable.instantiateServiceProviderWithoutRegistration('Anticipate');
|
|
44
|
+
|
|
45
|
+
for (let i = 0; i < this.state.Steps; i++)
|
|
46
|
+
{
|
|
47
|
+
tmpAnticipate.anticipate(this.stepFunctions[this.state.Steps[i].GUIDStep].bind(this));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Wait for the anticipation to complete
|
|
51
|
+
tmpAnticipate.wait(
|
|
52
|
+
(pError) =>
|
|
53
|
+
{
|
|
54
|
+
this.state.Status.TimeEnd = +new Date();
|
|
55
|
+
return fExecutionCompleteCallback();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/*
|
|
60
|
+
TODO: I've gone back and forth on whether this should be an object, JSON
|
|
61
|
+
object prototype, or set of functions here. Discuss with colleagues!
|
|
62
|
+
*/
|
|
63
|
+
addStep(pGUIDStep, fStepFunction, pStepName, pStepDescription, pStepMetadata)
|
|
64
|
+
{
|
|
65
|
+
let tmpStep = {};
|
|
66
|
+
tmpStep.GUIDStep = (typeof(pGUIDStep) !== 'undefined') ? pGUIDStep : `STEP-${this.state.Steps.length}-${this.fable.DataGeneration.randomNumericString()}`;
|
|
67
|
+
tmpStep.Name = (typeof(pStepName) !== 'undefined') ? pStepName : `Step [${tmpStep.GUIDStep}]`;
|
|
68
|
+
tmpStep.Description = (typeof(pStepDescription) !== 'undefined') ? pStepDescription : `Step execution of ${tmpStep.Name}.`;
|
|
69
|
+
// TODO: Right now this allows an Array... do we want to block that?
|
|
70
|
+
tmpStep.Metadata = (typeof(pStepMetadata) === 'object') ? pStepMetadata : {};
|
|
71
|
+
|
|
72
|
+
tmpStep.TimeStart = false;
|
|
73
|
+
tmpStep.TimeEnd = false;
|
|
74
|
+
|
|
75
|
+
// There is an array of steps, in the Operation State itself ... push a step there
|
|
76
|
+
this.state.Steps.push(tmpStep);
|
|
77
|
+
|
|
78
|
+
this.stepMap[tmpStep.GUIDStep]
|
|
79
|
+
this.stepFunctions[tmpStep.GUIDStep] = fStepFunction;
|
|
80
|
+
|
|
81
|
+
this.state.Status.StepCount++;
|
|
82
|
+
return tmpStep;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
getStep(pGUIDStep)
|
|
86
|
+
{
|
|
87
|
+
if (this.stepMap.hasOwnProperty(pGUIDStep))
|
|
88
|
+
{
|
|
89
|
+
return this.stepMap[pGUIDStep];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
startStep(pGUIDStep)
|
|
96
|
+
{
|
|
97
|
+
let tmpStep = this.getStep(pGUIDStep);
|
|
98
|
+
|
|
99
|
+
if (tmpStep === false)
|
|
100
|
+
{
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
tmpStep.TimeStart = +new Date();
|
|
105
|
+
|
|
106
|
+
return tmpStep;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
stopStep(pGUIDStep)
|
|
110
|
+
{
|
|
111
|
+
let tmpStep = this.getStep(pGUIDStep);
|
|
112
|
+
|
|
113
|
+
if (tmpStep === false)
|
|
114
|
+
{
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
tmpStep.TimeEnd = +new Date();
|
|
119
|
+
|
|
120
|
+
return tmpStep;
|
|
121
|
+
}
|
|
122
|
+
|
|
30
123
|
writeOperationLog(pLogLevel, pLogText, pLogObject)
|
|
31
124
|
{
|
|
32
125
|
this.state.Log.push(`${new Date().toUTCString()} [${pLogLevel}]: ${pLogText}`);
|
|
@@ -47,6 +140,7 @@ class FableOperation extends libFableServiceBase
|
|
|
47
140
|
}
|
|
48
141
|
}
|
|
49
142
|
|
|
143
|
+
|
|
50
144
|
trace(pLogText, pLogObject)
|
|
51
145
|
{
|
|
52
146
|
this.writeOperationLog('TRACE', pLogText, pLogObject);
|
|
@@ -85,6 +179,7 @@ class FableOperation extends libFableServiceBase
|
|
|
85
179
|
this.fable.log.fatal(pLogText, pLogObject);
|
|
86
180
|
}
|
|
87
181
|
|
|
182
|
+
|
|
88
183
|
/************************************************************************
|
|
89
184
|
* BEGINNING OF --> Telemetry Helpers
|
|
90
185
|
*/
|
|
@@ -263,7 +358,6 @@ class FableOperation extends libFableServiceBase
|
|
|
263
358
|
}
|
|
264
359
|
}
|
|
265
360
|
}
|
|
266
|
-
|
|
267
361
|
// logMemoryResourcesUsed()
|
|
268
362
|
// {
|
|
269
363
|
//
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const libFableServiceBase = require('
|
|
1
|
+
const libFableServiceBase = require('fable-serviceproviderbase');
|
|
2
2
|
|
|
3
3
|
// TODO: These are still pretty big -- consider the smaller polyfills
|
|
4
4
|
const libAsyncWaterfall = require('async.waterfall');
|
|
@@ -56,7 +56,7 @@ class FableServiceUtility extends libFableServiceBase
|
|
|
56
56
|
// with the added twist of returning a precompiled function ready to go.
|
|
57
57
|
template(pTemplateText, pData)
|
|
58
58
|
{
|
|
59
|
-
let tmpTemplate = this.fable.
|
|
59
|
+
let tmpTemplate = this.fable.instantiateServiceProviderWithoutRegistration('Template');
|
|
60
60
|
|
|
61
61
|
return tmpTemplate.buildTemplateFunction(pTemplateText, pData);
|
|
62
62
|
}
|
|
@@ -64,7 +64,7 @@ class FableServiceUtility extends libFableServiceBase
|
|
|
64
64
|
// Build a template function from a template hash, and, register it with the service provider
|
|
65
65
|
buildHashedTemplate(pTemplateHash, pTemplateText, pData)
|
|
66
66
|
{
|
|
67
|
-
let tmpTemplate = this.fable.
|
|
67
|
+
let tmpTemplate = this.fable.instantiateServiceProvider('Template', {}, pTemplateHash);
|
|
68
68
|
|
|
69
69
|
this.templates[pTemplateHash] = tmpTemplate.buildTemplateFunction(pTemplateText, pData);
|
|
70
70
|
|
package/test/Anticipate_tests.js
CHANGED
|
@@ -26,7 +26,7 @@ suite
|
|
|
26
26
|
function (fTestComplete)
|
|
27
27
|
{
|
|
28
28
|
let testFable = new libFable();
|
|
29
|
-
let tmpAnticipate = testFable.
|
|
29
|
+
let tmpAnticipate = testFable.instantiateServiceProvider('Anticipate');
|
|
30
30
|
tmpAnticipate.anticipate(function (fCallback)
|
|
31
31
|
{
|
|
32
32
|
testFable.log.info('Operation First test timeout entered...');
|
|
@@ -58,7 +58,7 @@ suite
|
|
|
58
58
|
function (fTestComplete)
|
|
59
59
|
{
|
|
60
60
|
let testFable = new libFable();
|
|
61
|
-
let tmpAnticipate = testFable.
|
|
61
|
+
let tmpAnticipate = testFable.instantiateServiceProvider('Anticipate');
|
|
62
62
|
tmpAnticipate.maxOperations = 2;
|
|
63
63
|
tmpAnticipate.anticipate(function (fCallback)
|
|
64
64
|
{
|
package/test/CSVParser_tests.js
CHANGED
|
@@ -30,7 +30,7 @@ suite
|
|
|
30
30
|
function(fDone)
|
|
31
31
|
{
|
|
32
32
|
let testFable = new libFable();
|
|
33
|
-
let tmpCSVParser = testFable.
|
|
33
|
+
let tmpCSVParser = testFable.instantiateServiceProvider('CSVParser', {Name: 'Big Complex Integration Operation'}, 'CSV Parser-123');
|
|
34
34
|
let tmpRecords = [];
|
|
35
35
|
|
|
36
36
|
const tmpReadline = libReadline.createInterface(
|
package/test/Cache_tests.js
CHANGED
|
@@ -26,7 +26,7 @@ suite
|
|
|
26
26
|
function (fTestComplete)
|
|
27
27
|
{
|
|
28
28
|
let testFable = new libFable();
|
|
29
|
-
let tmpDataGeneration = testFable.
|
|
29
|
+
let tmpDataGeneration = testFable.instantiateServiceProvider('DataGeneration');
|
|
30
30
|
Expect(tmpDataGeneration.randomIntegerUpTo(100)).to.be.within(0, 100);
|
|
31
31
|
return fTestComplete();
|
|
32
32
|
}
|
|
@@ -37,7 +37,7 @@ suite
|
|
|
37
37
|
function (fTestComplete)
|
|
38
38
|
{
|
|
39
39
|
let testFable = new libFable();
|
|
40
|
-
let tmpDataGeneration = testFable.
|
|
40
|
+
let tmpDataGeneration = testFable.instantiateServiceProvider('DataGeneration');
|
|
41
41
|
Expect(tmpDataGeneration.randomNumericString()).to.be.a('string');
|
|
42
42
|
Expect(tmpDataGeneration.randomNumericString().length).to.equal(10);
|
|
43
43
|
return fTestComplete();
|
|
@@ -49,7 +49,7 @@ suite
|
|
|
49
49
|
function (fTestComplete)
|
|
50
50
|
{
|
|
51
51
|
let testFable = new libFable();
|
|
52
|
-
let tmpDataGeneration = testFable.
|
|
52
|
+
let tmpDataGeneration = testFable.instantiateServiceProvider('DataGeneration');
|
|
53
53
|
testFable.log.info(`Random color: ${tmpDataGeneration.randomColor()}`);
|
|
54
54
|
Expect(tmpDataGeneration.randomColor()).to.be.a('string');
|
|
55
55
|
return fTestComplete();
|
|
@@ -61,7 +61,7 @@ suite
|
|
|
61
61
|
function (fTestComplete)
|
|
62
62
|
{
|
|
63
63
|
let testFable = new libFable();
|
|
64
|
-
let tmpDataGeneration = testFable.
|
|
64
|
+
let tmpDataGeneration = testFable.instantiateServiceProvider('DataGeneration');
|
|
65
65
|
testFable.log.info(`Random Day of Week: ${tmpDataGeneration.randomDayOfWeek()}`);
|
|
66
66
|
Expect(tmpDataGeneration.randomDayOfWeek()).to.be.a('string');
|
|
67
67
|
return fTestComplete();
|
|
@@ -73,7 +73,7 @@ suite
|
|
|
73
73
|
function (fTestComplete)
|
|
74
74
|
{
|
|
75
75
|
let testFable = new libFable();
|
|
76
|
-
let tmpDataGeneration = testFable.
|
|
76
|
+
let tmpDataGeneration = testFable.instantiateServiceProvider('DataGeneration');
|
|
77
77
|
testFable.log.info(`Random Month: ${tmpDataGeneration.randomMonth()}`);
|
|
78
78
|
Expect(tmpDataGeneration.randomMonth()).to.be.a('string');
|
|
79
79
|
return fTestComplete();
|
|
@@ -85,7 +85,7 @@ suite
|
|
|
85
85
|
function (fTestComplete)
|
|
86
86
|
{
|
|
87
87
|
let testFable = new libFable();
|
|
88
|
-
let tmpDataGeneration = testFable.
|
|
88
|
+
let tmpDataGeneration = testFable.instantiateServiceProvider('DataGeneration');
|
|
89
89
|
testFable.log.info(`Random Name: ${tmpDataGeneration.randomName()}`);
|
|
90
90
|
Expect(tmpDataGeneration.randomName()).to.be.a('string');
|
|
91
91
|
return fTestComplete();
|
|
@@ -97,7 +97,7 @@ suite
|
|
|
97
97
|
function (fTestComplete)
|
|
98
98
|
{
|
|
99
99
|
let testFable = new libFable();
|
|
100
|
-
let tmpDataGeneration = testFable.
|
|
100
|
+
let tmpDataGeneration = testFable.instantiateServiceProvider('DataGeneration');
|
|
101
101
|
testFable.log.info(`Random Surname: ${tmpDataGeneration.randomSurname()}`);
|
|
102
102
|
Expect(tmpDataGeneration.randomSurname()).to.be.a('string');
|
|
103
103
|
return fTestComplete();
|
|
@@ -29,7 +29,7 @@ suite
|
|
|
29
29
|
function(fDone)
|
|
30
30
|
{
|
|
31
31
|
let testFable = new libFable();
|
|
32
|
-
let tmpDates = testFable.
|
|
32
|
+
let tmpDates = testFable.instantiateServiceProvider('Dates');
|
|
33
33
|
|
|
34
34
|
testFable.log.info(`Guessing your timezone: ${tmpDates.dayJS.tz.guess()}`);
|
|
35
35
|
|
|
@@ -27,7 +27,7 @@ suite
|
|
|
27
27
|
function()
|
|
28
28
|
{
|
|
29
29
|
let testFable = new libFable();
|
|
30
|
-
let tmpOperation = testFable.
|
|
30
|
+
let tmpOperation = testFable.instantiateServiceProvider('Operation', {Name: 'Big Complex Integration Operation'}, 'INTEGRATION-123');
|
|
31
31
|
Expect(tmpOperation).to.be.an('object');
|
|
32
32
|
Expect(testFable.servicesMap.Operation['INTEGRATION-123']).to.equal(tmpOperation);
|
|
33
33
|
Expect(testFable.servicesMap.Operation['BADHASH']).to.be.undefined;
|
|
@@ -43,11 +43,11 @@ suite
|
|
|
43
43
|
function()
|
|
44
44
|
{
|
|
45
45
|
let testFable = new libFable();
|
|
46
|
-
let tmpOperation = testFable.
|
|
46
|
+
let tmpOperation = testFable.instantiateServiceProvider('Operation', {Name: 'Big Complex Integration Operation'}, 'INTEGRATION-123');;
|
|
47
47
|
Expect(tmpOperation).to.be.an('object');
|
|
48
48
|
Expect(tmpOperation.name).to.equal('Big Complex Integration Operation');
|
|
49
49
|
|
|
50
|
-
let tmpCollisionOperation = testFable.
|
|
50
|
+
let tmpCollisionOperation = testFable.instantiateServiceProvider('Operation', {Name: 'Another Big Complex Integration Operation with Colliding Name'}, 'INTEGRATION-123');;
|
|
51
51
|
Expect(tmpCollisionOperation).to.be.an('object');
|
|
52
52
|
Expect(tmpCollisionOperation.name).to.equal('Another Big Complex Integration Operation with Colliding Name');
|
|
53
53
|
|
|
@@ -61,7 +61,7 @@ suite
|
|
|
61
61
|
function()
|
|
62
62
|
{
|
|
63
63
|
let testFable = new libFable();
|
|
64
|
-
let tmpOperation = testFable.
|
|
64
|
+
let tmpOperation = testFable.instantiateServiceProvider('Operation', {Name:'Another Big Complex Integration Operation'});
|
|
65
65
|
Expect(tmpOperation).to.be.an('object');
|
|
66
66
|
Expect(testFable.servicesMap.Operation.hasOwnProperty(tmpOperation.Hash)).to.equal(true);
|
|
67
67
|
Expect(tmpOperation.state.Log.length).to.equal(0);
|
|
@@ -80,6 +80,35 @@ suite
|
|
|
80
80
|
Expect(tmpOperation.state.Errors.length).to.equal(4);
|
|
81
81
|
}
|
|
82
82
|
);
|
|
83
|
+
test
|
|
84
|
+
(
|
|
85
|
+
'Timing Stuff for Operations',
|
|
86
|
+
function(fDone)
|
|
87
|
+
{
|
|
88
|
+
let testFable = new libFable();
|
|
89
|
+
let tmpOperation = testFable.instantiateServiceProvider('Operation', {Name:'The last operation in town.'});
|
|
90
|
+
Expect(tmpOperation).to.be.an('object');
|
|
91
|
+
Expect(testFable.servicesMap.Operation.hasOwnProperty(tmpOperation.Hash)).to.equal(true);
|
|
92
|
+
Expect(tmpOperation.state.Log.length).to.equal(0);
|
|
93
|
+
let tmpText = `Operation ${tmpOperation.Hash} starting up...`;
|
|
94
|
+
tmpOperation.log.info(tmpText);
|
|
95
|
+
Expect(tmpOperation.state.Log.length).to.equal(1);
|
|
96
|
+
Expect(tmpOperation.state.Log[0]).to.contain(tmpText);
|
|
97
|
+
|
|
98
|
+
tmpOperation.addStep('001-Login',
|
|
99
|
+
(fStepComplete) =>
|
|
100
|
+
{
|
|
101
|
+
setTimeout(
|
|
102
|
+
() =>
|
|
103
|
+
{
|
|
104
|
+
tmpOperation.log.trace('Login thingy complete!');
|
|
105
|
+
return fStepComplete();
|
|
106
|
+
}, 150);
|
|
107
|
+
}, 'Example step 1!');
|
|
108
|
+
|
|
109
|
+
tmpOperation.execute(fDone);
|
|
110
|
+
}
|
|
111
|
+
);
|
|
83
112
|
}
|
|
84
113
|
);
|
|
85
114
|
}
|
|
@@ -87,10 +87,10 @@ suite
|
|
|
87
87
|
function ()
|
|
88
88
|
{
|
|
89
89
|
testFable = new libFable();
|
|
90
|
-
testFable.
|
|
91
|
-
testFable.
|
|
90
|
+
testFable.addServiceType('SimpleService');
|
|
91
|
+
testFable.instantiateServiceProvider('SimpleService', { SomeOption: true }, 'SimpleService-123');
|
|
92
92
|
|
|
93
|
-
Expect(testFable.
|
|
93
|
+
Expect(testFable.servicesMap['SimpleService']['SimpleService-123']).to.be.an('object');
|
|
94
94
|
}
|
|
95
95
|
);
|
|
96
96
|
test
|
|
@@ -99,17 +99,17 @@ suite
|
|
|
99
99
|
function ()
|
|
100
100
|
{
|
|
101
101
|
testFable = new libFable();
|
|
102
|
-
testFable.
|
|
103
|
-
testFable.
|
|
102
|
+
testFable.addServiceType('SimpleService');
|
|
103
|
+
testFable.extraServiceInitialization = (pService) =>
|
|
104
104
|
{
|
|
105
105
|
pService.MyFancyProperty = 'Fancy';
|
|
106
106
|
return pService;
|
|
107
107
|
}
|
|
108
|
-
testFable.
|
|
108
|
+
testFable.instantiateServiceProvider('SimpleService', { SomeOption: true }, 'TheBestOne');
|
|
109
109
|
|
|
110
|
-
Expect(testFable.
|
|
111
|
-
Expect(testFable.
|
|
112
|
-
Expect(testFable.
|
|
110
|
+
Expect(testFable.services.SimpleService).to.be.an('object');
|
|
111
|
+
Expect(testFable.services.SimpleService.MyFancyProperty).to.equal('Fancy');
|
|
112
|
+
Expect(testFable.servicesMap.SimpleService.TheBestOne.MyFancyProperty).to.equal('Fancy');
|
|
113
113
|
}
|
|
114
114
|
);
|
|
115
115
|
test
|
|
@@ -118,16 +118,16 @@ suite
|
|
|
118
118
|
function ()
|
|
119
119
|
{
|
|
120
120
|
testFable = new libFable();
|
|
121
|
-
testFable.
|
|
122
|
-
testFable.
|
|
121
|
+
testFable.addServiceType('SimpleService', SimpleService);
|
|
122
|
+
testFable.instantiateServiceProvider('SimpleService', { SomeOption: true }, 'SimpleService-123');
|
|
123
123
|
|
|
124
|
-
Expect(testFable.
|
|
124
|
+
Expect(testFable.servicesMap['SimpleService']['SimpleService-123']).to.be.an('object');
|
|
125
125
|
|
|
126
|
-
Expect(testFable.
|
|
126
|
+
Expect(testFable.services['SimpleService']).to.be.an('object');
|
|
127
127
|
|
|
128
|
-
testFable.
|
|
128
|
+
testFable.services.SimpleService.doSomething();
|
|
129
129
|
|
|
130
|
-
Expect(testFable.
|
|
130
|
+
Expect(testFable.services['SimpleService'].Hash).to.equal('SimpleService-123');
|
|
131
131
|
}
|
|
132
132
|
);
|
|
133
133
|
test
|
|
@@ -137,13 +137,13 @@ suite
|
|
|
137
137
|
{
|
|
138
138
|
let testFable = new libFable({});
|
|
139
139
|
|
|
140
|
-
testFable.
|
|
140
|
+
testFable.addServiceType('SimpleService', SimpleService);
|
|
141
141
|
|
|
142
|
-
testFable.
|
|
142
|
+
testFable.instantiateServiceProvider('SimpleService', { SomeOption: true }, 'SimpleService-13');
|
|
143
143
|
|
|
144
|
-
testFable.
|
|
144
|
+
testFable.servicesMap['SimpleService']['SimpleService-13'].doSomething();
|
|
145
145
|
|
|
146
|
-
Expect(testFable.
|
|
146
|
+
Expect(testFable.servicesMap['SimpleService']['SimpleService-13']).to.be.an('object');
|
|
147
147
|
}
|
|
148
148
|
);
|
|
149
149
|
|
|
@@ -154,10 +154,10 @@ suite
|
|
|
154
154
|
{
|
|
155
155
|
let testFable = new libFable({});
|
|
156
156
|
|
|
157
|
-
testFable.
|
|
157
|
+
testFable.addServiceType('SimpleService', SimpleService);
|
|
158
158
|
|
|
159
|
-
let tmpService = testFable.
|
|
160
|
-
let tmpServiceFromPrototype = testFable.
|
|
159
|
+
let tmpService = testFable.instantiateServiceProviderWithoutRegistration('SimpleService', { SomeOption: true }, 'SimpleService-99');
|
|
160
|
+
let tmpServiceFromPrototype = testFable.instantiateServiceProviderFromPrototype('SimpleService', { SomeOption: true }, 'SimpleService-100', SimpleService);
|
|
161
161
|
|
|
162
162
|
Expect(testFable.servicesMap.SimpleService['SimpleService-99']).to.be.an('undefined');
|
|
163
163
|
Expect(testFable.servicesMap.SimpleService['SimpleService-100']).to.be.an('object');
|
|
@@ -174,29 +174,29 @@ suite
|
|
|
174
174
|
{
|
|
175
175
|
let testFable = new libFable({});
|
|
176
176
|
|
|
177
|
-
testFable.
|
|
178
|
-
testFable.
|
|
177
|
+
testFable.addServiceType('SimpleService', SimpleService);
|
|
178
|
+
testFable.addServiceType('DatabaseService', MockDatabaseService);
|
|
179
179
|
|
|
180
|
-
testFable.
|
|
181
|
-
testFable.
|
|
180
|
+
testFable.instantiateServiceProvider('SimpleService', { SomeOption: true });
|
|
181
|
+
testFable.services.SimpleService.doSomething();
|
|
182
182
|
|
|
183
|
-
testFable.
|
|
183
|
+
testFable.instantiateServiceProvider('DatabaseService', { ConnectionString: 'mongodb://localhost:27017/test' }, 'PrimaryConnection');
|
|
184
184
|
|
|
185
|
-
Expect(testFable.
|
|
185
|
+
Expect(testFable.services.DatabaseService.Hash).to.equal('PrimaryConnection');
|
|
186
186
|
|
|
187
|
-
testFable.
|
|
187
|
+
testFable.instantiateServiceProvider('DatabaseService', { ConnectionString: 'mongodb://localhost:27017/test' }, 'SecondaryConnection');
|
|
188
188
|
|
|
189
|
-
Expect(testFable.
|
|
189
|
+
Expect(testFable.services.DatabaseService.Hash).to.equal('PrimaryConnection');
|
|
190
190
|
|
|
191
|
-
testFable.
|
|
192
|
-
testFable.
|
|
191
|
+
testFable.services.DatabaseService.connect();
|
|
192
|
+
testFable.services.DatabaseService.commit('Test Record');
|
|
193
193
|
|
|
194
|
-
testFable.
|
|
194
|
+
testFable.setDefaultServiceInstantiation('DatabaseService', 'SecondaryConnection');
|
|
195
195
|
|
|
196
|
-
testFable.
|
|
197
|
-
testFable.
|
|
196
|
+
testFable.services.DatabaseService.connect();
|
|
197
|
+
testFable.services.DatabaseService.commit('Another Test Record');
|
|
198
198
|
|
|
199
|
-
Expect(testFable.
|
|
199
|
+
Expect(testFable.services.DatabaseService.Hash).to.equal('SecondaryConnection');
|
|
200
200
|
}
|
|
201
201
|
);
|
|
202
202
|
|
|
@@ -239,7 +239,7 @@ suite
|
|
|
239
239
|
|
|
240
240
|
let testFable = new libFable({});
|
|
241
241
|
|
|
242
|
-
testFable.
|
|
242
|
+
testFable.connectPreinitServiceProviderInstance(tmpCoreService);
|
|
243
243
|
|
|
244
244
|
Expect(testFable.servicesMap.MockCoreService['MockCoreService-2']).to.be.an('object');
|
|
245
245
|
Expect(testFable.services.MockCoreService).to.be.an('object');
|
|
@@ -255,29 +255,29 @@ suite
|
|
|
255
255
|
{
|
|
256
256
|
let testFable = new libFable({});
|
|
257
257
|
|
|
258
|
-
testFable.
|
|
259
|
-
testFable.
|
|
258
|
+
testFable.addServiceType('SimpleService', SimpleService);
|
|
259
|
+
testFable.addServiceType('DatabaseService', MockDatabaseService);
|
|
260
260
|
|
|
261
|
-
testFable.
|
|
262
|
-
testFable.
|
|
261
|
+
testFable.instantiateServiceProvider('SimpleService', { SomeOption: true });
|
|
262
|
+
testFable.services.SimpleService.doSomething();
|
|
263
263
|
|
|
264
|
-
testFable.
|
|
264
|
+
testFable.instantiateServiceProvider('DatabaseService', { ConnectionString: 'mongodb://localhost:27017/test' }, 'PrimaryConnection');
|
|
265
265
|
|
|
266
|
-
Expect(testFable.
|
|
266
|
+
Expect(testFable.services.DatabaseService.Hash).to.equal('PrimaryConnection');
|
|
267
267
|
|
|
268
|
-
testFable.
|
|
268
|
+
testFable.instantiateServiceProvider('DatabaseService', { ConnectionString: 'mongodb://localhost:27017/test' }, 'SecondaryConnection');
|
|
269
269
|
|
|
270
|
-
Expect(testFable.
|
|
270
|
+
Expect(testFable.services.DatabaseService.Hash).to.equal('PrimaryConnection');
|
|
271
271
|
|
|
272
|
-
testFable.
|
|
273
|
-
testFable.
|
|
272
|
+
testFable.services.DatabaseService.connect();
|
|
273
|
+
testFable.services.DatabaseService.commit('Test Record');
|
|
274
274
|
|
|
275
|
-
Expect(testFable.
|
|
275
|
+
Expect(testFable.setDefaultServiceInstantiation('DatabaseService', 'TertiaryConnection')).to.be.false;
|
|
276
276
|
|
|
277
|
-
testFable.
|
|
278
|
-
testFable.
|
|
277
|
+
testFable.services.DatabaseService.connect();
|
|
278
|
+
testFable.services.DatabaseService.commit('Another Test Record');
|
|
279
279
|
|
|
280
|
-
Expect(testFable.
|
|
280
|
+
Expect(testFable.services.DatabaseService.Hash).to.equal('PrimaryConnection');
|
|
281
281
|
}
|
|
282
282
|
);
|
|
283
283
|
}
|
|
@@ -11,8 +11,6 @@ var libFable = require('../source/Fable.js');
|
|
|
11
11
|
var Chai = require("chai");
|
|
12
12
|
var Expect = Chai.expect;
|
|
13
13
|
|
|
14
|
-
// https://en.wiktionary.org/w/api.php?action=parse&prop=wikitext&format=json&page=dog
|
|
15
|
-
|
|
16
14
|
suite
|
|
17
15
|
(
|
|
18
16
|
'Fable FilePersistence',
|
|
@@ -34,7 +32,7 @@ suite
|
|
|
34
32
|
function(fTestComplete)
|
|
35
33
|
{
|
|
36
34
|
let testFable = new libFable();
|
|
37
|
-
let tmpFilePersistence = testFable.
|
|
35
|
+
let tmpFilePersistence = testFable.instantiateServiceProvider('FilePersistence');
|
|
38
36
|
Expect(tmpFilePersistence).is.an('object');
|
|
39
37
|
Expect(tmpFilePersistence.existsSync(`${__dirname}/../package.json`)).to.equal(true);
|
|
40
38
|
Expect(tmpFilePersistence.existsSync(`${__dirname}/package.json`)).to.equal(false);
|
|
@@ -42,13 +40,48 @@ suite
|
|
|
42
40
|
}
|
|
43
41
|
);
|
|
44
42
|
test
|
|
43
|
+
(
|
|
44
|
+
'Read a file line-by-line',
|
|
45
|
+
function(fTestComplete)
|
|
46
|
+
{
|
|
47
|
+
let testFable = new libFable();
|
|
48
|
+
let tmpFilePersistence = testFable.instantiateServiceProvider('FilePersistence');
|
|
49
|
+
let tmpFirstLine = 'id,book_id,best_book_id,work_id,books_count,isbn,isbn13,authors,original_publication_year,original_title,title,language_code,average_rating,ratings_count,work_ratings_count,work_text_reviews_count,ratings_1,ratings_2,ratings_3,ratings_4,ratings_5,image_url,small_image_url';
|
|
50
|
+
|
|
51
|
+
let tmpLineReader = tmpFilePersistence.lineReaderFactory(`${__dirname}/data/books.csv`,
|
|
52
|
+
(pLine) =>
|
|
53
|
+
{
|
|
54
|
+
if (tmpFirstLine)
|
|
55
|
+
{
|
|
56
|
+
Expect(pLine).to.equal(tmpFirstLine);
|
|
57
|
+
tmpFirstLine = false;
|
|
58
|
+
}
|
|
59
|
+
//console.log(pLine);
|
|
60
|
+
},
|
|
61
|
+
() =>
|
|
62
|
+
{
|
|
63
|
+
console.log('LINE-BY-LINE FILE READING COMPLETE; GOOD DAY SIR.');
|
|
64
|
+
return fTestComplete();
|
|
65
|
+
},
|
|
66
|
+
(pError) =>
|
|
67
|
+
{
|
|
68
|
+
console.log(`Error reading file line-by-line: ${pError}`);
|
|
69
|
+
});
|
|
70
|
+
if (!tmpLineReader)
|
|
71
|
+
{
|
|
72
|
+
Expect(false).to.equal(true, 'The line reader was not initialized properly!')
|
|
73
|
+
return fTestComplete();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
test
|
|
45
78
|
(
|
|
46
79
|
'Create, write, read and then delete a file.',
|
|
47
80
|
function(fTestComplete)
|
|
48
81
|
{
|
|
49
82
|
let testFable = new libFable();
|
|
50
|
-
let tmpFilePersistence = testFable.
|
|
51
|
-
let tmpDataGeneration = testFable.
|
|
83
|
+
let tmpFilePersistence = testFable.instantiateServiceProvider('FilePersistence');
|
|
84
|
+
let tmpDataGeneration = testFable.instantiateServiceProvider('DataGeneration');
|
|
52
85
|
|
|
53
86
|
let tmpLogFilePath = `/tmp/Fable-Test-${tmpDataGeneration.randomNumericString()}.log`;
|
|
54
87
|
testFable.log.info(`Writing test log file: [${tmpLogFilePath}]`);
|
|
@@ -62,7 +95,7 @@ suite
|
|
|
62
95
|
|
|
63
96
|
// Now delete the file
|
|
64
97
|
tmpFilePersistence.deleteFileSync(tmpLogFilePath);
|
|
65
|
-
|
|
98
|
+
|
|
66
99
|
Expect(tmpFilePersistence.existsSync(tmpLogFilePath)).to.equal(false);
|
|
67
100
|
|
|
68
101
|
return fTestComplete();
|
|
@@ -74,7 +107,7 @@ suite
|
|
|
74
107
|
function(fTestComplete)
|
|
75
108
|
{
|
|
76
109
|
let testFable = new libFable();
|
|
77
|
-
let tmpFilePersistence = testFable.
|
|
110
|
+
let tmpFilePersistence = testFable.instantiateServiceProvider('FilePersistence');
|
|
78
111
|
|
|
79
112
|
Expect(tmpFilePersistence.joinPath('/tmp/tests/../othertests/names/'))
|
|
80
113
|
.to.equal('/tmp/othertests/names');
|
|
@@ -88,8 +121,8 @@ suite
|
|
|
88
121
|
function(fTestComplete)
|
|
89
122
|
{
|
|
90
123
|
let testFable = new libFable();
|
|
91
|
-
let tmpFilePersistence = testFable.
|
|
92
|
-
let tmpDataGeneration = testFable.
|
|
124
|
+
let tmpFilePersistence = testFable.instantiateServiceProvider('FilePersistence');
|
|
125
|
+
let tmpDataGeneration = testFable.instantiateServiceProvider('DataGeneration');
|
|
93
126
|
|
|
94
127
|
let tmpFolderExtras = [];
|
|
95
128
|
|
|
@@ -121,8 +154,8 @@ suite
|
|
|
121
154
|
function(fTestComplete)
|
|
122
155
|
{
|
|
123
156
|
let testFable = new libFable();
|
|
124
|
-
let tmpFilePersistence = testFable.
|
|
125
|
-
let tmpDataGeneration = testFable.
|
|
157
|
+
let tmpFilePersistence = testFable.instantiateServiceProvider('FilePersistence');
|
|
158
|
+
let tmpDataGeneration = testFable.instantiateServiceProvider('DataGeneration');
|
|
126
159
|
|
|
127
160
|
let tmpLogFilePath = `/tmp/Fable-Test-${tmpDataGeneration.randomNumericString()}.log`;
|
|
128
161
|
testFable.log.info(`Writing test log file: [${tmpLogFilePath}]`);
|
|
@@ -139,7 +172,7 @@ suite
|
|
|
139
172
|
|
|
140
173
|
// Now delete the file
|
|
141
174
|
tmpFilePersistence.deleteFileSync(tmpLogFilePath);
|
|
142
|
-
|
|
175
|
+
|
|
143
176
|
Expect(tmpFilePersistence.existsSync(tmpLogFilePath)).to.equal(false);
|
|
144
177
|
|
|
145
178
|
return fTestComplete();
|