orator 3.0.2 → 3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orator",
3
- "version": "3.0.2",
3
+ "version": "3.0.4",
4
4
  "description": "Unopinionated restful web API server container",
5
5
  "main": "source/Orator.js",
6
6
  "scripts": {
@@ -62,8 +62,8 @@
62
62
  },
63
63
  "dependencies": {
64
64
  "async": "^3.2.4",
65
- "fable": "~3.0.2",
65
+ "fable": "^3.0.7",
66
66
  "find-my-way": "^7.5.0",
67
- "orator-serviceserver": "^1.0.1"
67
+ "orator-serviceserver": "^1.0.2"
68
68
  }
69
69
  }
@@ -28,6 +28,28 @@ class OratorServiceServerIPC extends libOratorServiceServerBase
28
28
  this.postBehaviorFunctions = [];
29
29
  }
30
30
 
31
+ use(fHandlerFunction)
32
+ {
33
+ if (!super.use(fHandlerFunction))
34
+ {
35
+ this.log.error(`IPC provider failed to map USE handler function!`);
36
+ return false;
37
+ }
38
+
39
+ this.preBehaviorFunctions.push(fHandlerFunction);
40
+ }
41
+
42
+ addPostBehaviorFunction(fHandlerFunction)
43
+ {
44
+ if (!super.use(fHandlerFunction))
45
+ {
46
+ this.log.error(`IPC provider failed to map USE handler function!`);
47
+ return false;
48
+ }
49
+
50
+ this.preBehaviorFunctions.push(fHandlerFunction);
51
+ }
52
+
31
53
  executePreBehaviorFunctions(pRequest, pResponse, fNext)
32
54
  {
33
55
  libAsyncEachOfSeries(this.preBehaviorFunctions,
@@ -45,6 +67,17 @@ class OratorServiceServerIPC extends libOratorServiceServerBase
45
67
  });
46
68
  }
47
69
 
70
+ addPostBehaviorFunction(fHandlerFunction)
71
+ {
72
+ if (!super.use(fHandlerFunction))
73
+ {
74
+ this.log.error(`IPC provider failed to map USE handler function!`);
75
+ return false;
76
+ }
77
+
78
+ this.preBehaviorFunctions.push(fHandlerFunction);
79
+ }
80
+
48
81
  executePostBehaviorFunctions(pRequest, pResponse, fNext)
49
82
  {
50
83
  libAsyncEachOfSeries(this.postBehaviorFunctions,
@@ -13,6 +13,8 @@ const Expect = Chai.expect;
13
13
  const Assert = Chai.assert;
14
14
 
15
15
  //const libSuperTest = require('supertest');
16
+ const libFable = require('fable');
17
+ const _Fable = new libFable({Product:'Orator-BasicTests-Backplane'});
16
18
 
17
19
  const _MockSettings = (
18
20
  {
@@ -53,7 +55,9 @@ suite
53
55
  // Start the service server
54
56
  tmpOrator.initializeServiceServer();
55
57
  // Start the service
58
+ Expect(tmpOrator.serviceServer.Active).to.equal(false);
56
59
  tmpOrator.startService(fDone);
60
+ Expect(tmpOrator.serviceServer.Active).to.equal(true);
57
61
  }
58
62
  );
59
63
 
@@ -75,7 +79,7 @@ suite
75
79
  {
76
80
  // Send back the request parameters
77
81
  pResponse.send(pRequest.params);
78
- tmpOrator.fable.log.info(`sent ${pRequest.params}`);
82
+ tmpOrator.fable.log.info(`Endpoint sent parameters object:`,pRequest.params);
79
83
  return fNext();
80
84
  }
81
85
  );
@@ -84,11 +88,117 @@ suite
84
88
  tmpOrator.invoke('GET', tmpURI, null,
85
89
  (pError, pResponseData) =>
86
90
  {
87
- tmpOrator.log.info(`Response to [${tmpURI}] came back from IPC resulting in [${pResponseData}]!`)
91
+ let tmpResponseObject = JSON.parse(pResponseData);
92
+ Expect(tmpResponseObject).to.have.a.property('hash');
93
+ Expect(tmpResponseObject.hash).to.equal('SomeHash');
94
+ tmpOrator.log.info(`Response to [${tmpURI}] came back from IPC resulting in [${pResponseData}] which is type ${typeof(pResponseData)}!`);
88
95
  return fDone();
89
96
  });
90
97
  }
91
98
  );
99
+
100
+ test
101
+ (
102
+ 'ipc should be able to process any number of handler additions with the use function',
103
+ (fDone) =>
104
+ {
105
+ let tmpOrator = new libOrator();
106
+ // Initialize the service server
107
+ tmpOrator.initializeServiceServer();
108
+ // Start the service
109
+ tmpOrator.startService();
110
+
111
+ tmpOrator.serviceServer.get
112
+ (
113
+ '/MagicEndpoint/:MagicWords',
114
+ (pRequest, pResponse, fNext) =>
115
+ {
116
+ let tmpResponseObject = (
117
+ {
118
+ MagicWords: pRequest.params.MagicWords,
119
+ MagicIngredients: pRequest.MagicIngredients
120
+ });
121
+ pResponse.send(tmpResponseObject);
122
+ return fNext();
123
+ }
124
+ );
125
+
126
+ _Fable.Utility.waterfall([
127
+ (fStageComplete) =>
128
+ {
129
+ let tmpURI = `/MagicEndpoint/BippityBoppityBoo`;
130
+ tmpOrator.invoke('GET', tmpURI, null,
131
+ (pError, pResponseData) =>
132
+ {
133
+ let tmpResponseObject = JSON.parse(pResponseData);
134
+ Expect(tmpResponseObject).to.have.a.property('MagicWords');
135
+ Expect(tmpResponseObject.MagicWords).to.equal('BippityBoppityBoo');
136
+ Expect(tmpResponseObject).to.not.have.a.property('MagicIngredients');
137
+ //Expect(tmpResponseObject.MagicIngredients).to.be('undefined');
138
+ tmpOrator.log.info(`Response to [${tmpURI}] came back from IPC resulting in [${pResponseData}] which is type ${typeof(pResponseData)}!`);
139
+ return fStageComplete();
140
+ });
141
+ },
142
+ (fStageComplete) =>
143
+ {
144
+ // Add a use parameter that decorates the ingredients
145
+ tmpOrator.serviceServer.use(
146
+ (pRequest, pResponse, fNext) =>
147
+ {
148
+ pRequest.MagicIngredients = [];
149
+ return fNext();
150
+ });
151
+ return fStageComplete();
152
+ },
153
+ (fStageComplete) =>
154
+ {
155
+ let tmpURI = `/MagicEndpoint/BippityBoppityBoo`;
156
+ tmpOrator.invoke('GET', tmpURI, null,
157
+ (pError, pResponseData) =>
158
+ {
159
+ let tmpResponseObject = JSON.parse(pResponseData);
160
+ Expect(tmpResponseObject).to.have.a.property('MagicWords');
161
+ Expect(tmpResponseObject.MagicWords).to.equal('BippityBoppityBoo');
162
+ Expect(tmpResponseObject).to.have.a.property('MagicIngredients');
163
+ Expect(tmpResponseObject.MagicIngredients).to.be.an('array');
164
+ tmpOrator.log.info(`Response to [${tmpURI}] came back from IPC resulting in [${pResponseData}] which is type ${typeof(pResponseData)}!`);
165
+ return fStageComplete();
166
+ });
167
+ },
168
+ (fStageComplete) =>
169
+ {
170
+ // Add a use parameter that decorates the ingredients
171
+ tmpOrator.serviceServer.use(
172
+ (pRequest, pResponse, fNext) =>
173
+ {
174
+ pRequest.MagicIngredients.push('Magic Outcomes');
175
+ return fNext();
176
+ });
177
+ return fStageComplete();
178
+ },
179
+ (fStageComplete) =>
180
+ {
181
+ let tmpURI = `/MagicEndpoint/BippityBoppityBoo`;
182
+ tmpOrator.invoke('GET', tmpURI, null,
183
+ (pError, pResponseData) =>
184
+ {
185
+ let tmpResponseObject = JSON.parse(pResponseData);
186
+ Expect(tmpResponseObject).to.have.a.property('MagicWords');
187
+ Expect(tmpResponseObject.MagicWords).to.equal('BippityBoppityBoo');
188
+ Expect(tmpResponseObject).to.have.a.property('MagicIngredients');
189
+ Expect(tmpResponseObject.MagicIngredients).to.be.an('array');
190
+ Expect(tmpResponseObject.MagicIngredients[0]).to.equal('Magic Outcomes`');
191
+ tmpOrator.log.info(`Response to [${tmpURI}] came back from IPC resulting in [${pResponseData}] which is type ${typeof(pResponseData)}!`);
192
+ return fStageComplete();
193
+ });
194
+ }
195
+ ],
196
+ (pError) =>
197
+ {
198
+ fDone();
199
+ })
200
+ }
201
+ );
92
202
  }
93
203
  );
94
204
  }