@@ -9,11 +9,28 @@ OF ANY KIND, either express or implied. See the License for the specific languag
99governing permissions and limitations under the License.
1010*/
1111
12+ // eslint-disable-next-line import/no-extraneous-dependencies
13+ const lodash = require ( 'lodash' ) ;
1214const createGetDataElementValueModule = require ( '../createGetDataElementValue' ) ;
1315
1416jest . mock ( '../cleanText.js' ) ;
1517
16- const defaultContext = { arcAndUtils : { } } ;
18+ const getContext = ( context = { } ) => {
19+ const logs = [ ] ;
20+ return lodash . merge (
21+ {
22+ arcAndUtils : {
23+ arc : { event : { } } ,
24+ utils : {
25+ logger : {
26+ log : ( m ) => logs . push ( m )
27+ }
28+ }
29+ }
30+ } ,
31+ context
32+ ) ;
33+ } ;
1734
1835const createGetDataElementDefinitionDefault = ( dataDef ) =>
1936 jest . fn ( ) . mockImplementation ( ( dataElementName ) => {
@@ -64,7 +81,7 @@ describe('function returned by createGetDataElementValue', () => {
6481 }
6582 } ) ;
6683
67- return getDataElementValue ( 'testDataElement' , defaultContext ) . then (
84+ return getDataElementValue ( 'testDataElement' , getContext ( ) ) . then (
6885 ( dataElementValue ) => expect ( dataElementValue ) . toBe ( 'bar' )
6986 ) ;
7087 } ) ;
@@ -87,12 +104,12 @@ describe('function returned by createGetDataElementValue', () => {
87104 { moduleProvider }
88105 ) ;
89106
90- return getDataElementValue ( 'testDataElement' , context ) . then (
107+ return getDataElementValue ( 'testDataElement' , getContext ( context ) ) . then (
91108 ( dataElementValue ) => expect ( dataElementValue ) . toBe ( 'bar' )
92109 ) ;
93110 } ) ;
94111
95- test ( 'gives extension settings access to the data element module' , async ( ) => {
112+ test . only ( 'gives extension settings access to the data element module' , async ( ) => {
96113 const moduleProvider = createGetModuleProvider ( {
97114 getModuleExports :
98115 ( ) =>
@@ -105,7 +122,7 @@ describe('function returned by createGetDataElementValue', () => {
105122 { moduleProvider }
106123 ) ;
107124
108- return getDataElementValue ( 'testDataElement' , defaultContext ) . then (
125+ return getDataElementValue ( 'testDataElement' , getContext ( ) ) . then (
109126 ( dataElementValue ) =>
110127 expect ( dataElementValue ) . toEqual ( { data : 'extension settings' } )
111128 ) ;
@@ -134,7 +151,7 @@ describe('function returned by createGetDataElementValue', () => {
134151 { moduleProvider }
135152 ) ;
136153
137- return getDataElementValue ( 'testDataElement' , context ) . then (
154+ return getDataElementValue ( 'testDataElement' , getContext ( context ) ) . then (
138155 ( dataElementValue ) => expect ( dataElementValue ) . toEqual ( { foo : 'bar' } )
139156 ) ;
140157 } ) ;
@@ -159,7 +176,7 @@ describe('function returned by createGetDataElementValue', () => {
159176 { moduleProvider }
160177 ) ;
161178
162- return getDataElementValue ( 'testDataElement' , context ) . then (
179+ return getDataElementValue ( 'testDataElement' , getContext ( context ) ) . then (
163180 ( dataElementValue ) => expect ( dataElementValue ) . toEqual ( { } )
164181 ) ;
165182 } ) ;
@@ -170,7 +187,7 @@ describe('function returned by createGetDataElementValue', () => {
170187 settings : { foo : 'bar' }
171188 } ) ;
172189
173- return getDataElementValue ( 'testDataElement' , defaultContext ) . then (
190+ return getDataElementValue ( 'testDataElement' , getContext ( ) ) . then (
174191 ( dataElementValue ) => expect ( dataElementValue ) . toBe ( 'cleaned:bar' )
175192 ) ;
176193 } ) ;
@@ -189,7 +206,7 @@ describe('function returned by createGetDataElementValue', () => {
189206 moduleProvider
190207 ) ;
191208
192- return getDataElementValue ( 'testDataElement' , defaultContext ) . then (
209+ return getDataElementValue ( 'testDataElement' , getContext ( ) ) . then (
193210 ( dataElementValue ) => expect ( dataElementValue ) . toBe ( 'defaultValue' )
194211 ) ;
195212 } ) ;
@@ -203,7 +220,7 @@ describe('function returned by createGetDataElementValue', () => {
203220 { moduleProvider }
204221 ) ;
205222
206- return getDataElementValue ( 'testDataElement' , defaultContext ) . then (
223+ return getDataElementValue ( 'testDataElement' , getContext ( ) ) . then (
207224 ( dataElementValue ) =>
208225 expect ( dataElementValue ) . toBe ( testDataElementValue )
209226 ) ;
@@ -224,7 +241,7 @@ describe('function returned by createGetDataElementValue', () => {
224241 { moduleProvider }
225242 ) ;
226243
227- return getDataElementValue ( 'testDataElement' , defaultContext ) . then (
244+ return getDataElementValue ( 'testDataElement' , getContext ( ) ) . then (
228245 ( dataElementValue ) =>
229246 expect ( dataElementValue ) . toBe ( testDataElementValue )
230247 ) ;
@@ -239,7 +256,7 @@ describe('function returned by createGetDataElementValue', () => {
239256 }
240257 } ) ;
241258
242- return getDataElementValue ( 'testDataElement' , defaultContext ) . then (
259+ return getDataElementValue ( 'testDataElement' , getContext ( ) ) . then (
243260 ( dataElementValue ) => expect ( dataElementValue ) . toBe ( 'bar' )
244261 ) ;
245262 } ) ;
@@ -251,7 +268,7 @@ describe('function returned by createGetDataElementValue', () => {
251268 settings : { }
252269 } ) ;
253270
254- return getDataElementValue ( 'testDataElement' , defaultContext ) . then (
271+ return getDataElementValue ( 'testDataElement' , getContext ( ) ) . then (
255272 ( dataElementValue ) => expect ( dataElementValue ) . toBe ( 'bar' )
256273 ) ;
257274 } ) ;
@@ -271,7 +288,7 @@ describe('function returned by createGetDataElementValue', () => {
271288 { moduleProvider }
272289 ) ;
273290
274- return getDataElementValue ( 'testDataElement' , defaultContext ) . catch ( ( e ) => {
291+ return getDataElementValue ( 'testDataElement' , getContext ( ) ) . catch ( ( e ) => {
275292 expect ( e . message ) . toMatch (
276293 'Failed to execute module for data element "testDataElement". noob tried to divide by zero'
277294 ) ;
@@ -292,7 +309,7 @@ describe('function returned by createGetDataElementValue', () => {
292309 { moduleProvider }
293310 ) ;
294311
295- return getDataElementValue ( 'testDataElement' , defaultContext )
312+ return getDataElementValue ( 'testDataElement' , getContext ( ) )
296313 . then ( ( ) => {
297314 throw new Error ( 'This section should not have been called.' ) ;
298315 } )
@@ -312,7 +329,7 @@ describe('function returned by createGetDataElementValue', () => {
312329 { createGetDataElementDefinition : ( ) => ( ) => { } }
313330 ) ;
314331
315- return getDataElementValue ( 'testDataElement' , defaultContext )
332+ return getDataElementValue ( 'testDataElement' , getContext ( ) )
316333 . then ( ( ) => {
317334 throw new Error ( 'This section should not have been called.' ) ;
318335 } )
@@ -330,10 +347,13 @@ describe('function returned by createGetDataElementValue', () => {
330347 }
331348 } ) ;
332349
333- return getDataElementValue ( 'testDataElement' , {
334- dataElementCallStack : [ 'testDataElement' ] ,
335- arcAndUtils : { }
336- } )
350+ return getDataElementValue (
351+ 'testDataElement' ,
352+ getContext ( {
353+ dataElementCallStack : [ 'testDataElement' ] ,
354+ arcAndUtils : { }
355+ } )
356+ )
337357 . then ( ( ) => {
338358 throw new Error ( 'This section should not have been called.' ) ;
339359 } )
@@ -361,7 +381,7 @@ describe('function returned by createGetDataElementValue', () => {
361381 { moduleProvider }
362382 ) ;
363383
364- return getDataElementValue ( 'testDataElement' , defaultContext ) . then (
384+ return getDataElementValue ( 'testDataElement' , getContext ( ) ) . then (
365385 ( dataElementValue ) =>
366386 expect ( dataElementValue ) . toEqual ( {
367387 id : 'DE123' ,
0 commit comments