Comparing version 1.0.4 to 1.0.5
{ | ||
"name": "js-awe", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -104,3 +104,3 @@ import { resolve } from 'fluture' | ||
const stackParallelReducer = function(){ | ||
const stackParallelReducer = function(numberOfThreads){ | ||
let accruingParallel = false | ||
@@ -129,3 +129,3 @@ let funsToParallelize = [] | ||
{ | ||
value: runFunctionsSyncOrParallel()(funsToParallelize), | ||
value: runFunctionsSyncOrParallel(numberOfThreads)(funsToParallelize), | ||
path: el.path.slice(0,-1) | ||
@@ -149,8 +149,8 @@ } | ||
} | ||
}() | ||
} | ||
const acumParallel = (stack) => | ||
const acumParallel = numberOfThreads => stack => | ||
{ | ||
return stack.reduce( | ||
stackParallelReducer, | ||
stackParallelReducer(numberOfThreads), | ||
[] | ||
@@ -212,14 +212,43 @@ ) | ||
] | ||
}() | ||
} | ||
function plan(plan) | ||
function changeFunWithMockupsObj(mockupsObj) | ||
{ | ||
return stack => { | ||
if (!mockupsObj) return stack | ||
return stack.map( | ||
({path, value}) => { | ||
if(mockupsObj?.[value.name] !== undefined) | ||
{ | ||
if(typeof mockupsObj[value.name] === 'function') { | ||
return { | ||
value:mockupsObj[value.name], | ||
path | ||
} | ||
} | ||
return { | ||
value: () => mockupsObj[value.name], | ||
path | ||
} | ||
} | ||
return {value:value, path} | ||
} | ||
) | ||
} | ||
} | ||
function plan(plan, {numberOfThreads, mockupsObj} = {numberOfThreads: Infinity, mockupsObj: {}}) | ||
{ | ||
return pipe( | ||
generateStack, | ||
changeFunWithMockupsObj(mockupsObj), | ||
pipeWhile(stack => stack.length > 1)( | ||
pipeWhile(...lengthStackPrevLessThanCurr) | ||
pipeWhile(...lengthStackPrevLessThanCurr()) | ||
( | ||
acumSiblings, | ||
acumParallel, | ||
acumParallel(numberOfThreads), | ||
), | ||
@@ -226,0 +255,0 @@ reduceNesting, |
@@ -5,4 +5,4 @@ import { strict as assert } from 'assert' | ||
import { plan } from '../src/plan.js' | ||
import { R, innerRightJoinWith } from '../src/ramdaExt.js' | ||
import { fork, promise, resolve } from 'fluture' | ||
import { R, innerRightJoinWith } from '../src/ramdaExt.js' | ||
import { promise, resolve } from 'fluture' | ||
@@ -78,17 +78,19 @@ const bankDB = { | ||
let buildPlaceholderStructure = R.reduce( | ||
(acc, el) => { | ||
acc.resultPlaceholder.push({ account:el.account, uuid:el.uuid }) | ||
if(el.prod === '300') acc.bankingToFetch.push(el.account) | ||
if(el.prod === '500') acc.creditCardsToFetch.push(el.account) | ||
return acc | ||
}, | ||
//placeholderStructure | ||
{ | ||
resultPlaceholder:[], | ||
bankingToFetch:[], | ||
creditCardsToFetch:[] | ||
}, | ||
) | ||
function buildPlaceholderStructure(data) { | ||
return R.reduce( | ||
(acc, el) => { | ||
acc.resultPlaceholder.push({ account:el.account, uuid:el.uuid }) | ||
if(el.prod === '300') acc.bankingToFetch.push(el.account) | ||
if(el.prod === '500') acc.creditCardsToFetch.push(el.account) | ||
return acc | ||
}, | ||
//placeholderStructure | ||
{ | ||
resultPlaceholder:[], | ||
bankingToFetch:[], | ||
creditCardsToFetch:[] | ||
}, | ||
)(data) | ||
} | ||
@@ -123,4 +125,3 @@ | ||
filterActiveAccounts, // [ 0, 1, 1 ] | ||
buildPlaceholderStructure, // [ 0, 1, 2 ] | ||
buildPlaceholderStructure, // [ 0, 1, 2 ] | ||
[ // [ 0, 1, 3 ] | ||
@@ -132,3 +133,3 @@ [ // [ 0, 1, 3, 0 ] | ||
getCreditCardBalances, // [ 0, 1, 3, 1, 0 ] | ||
], // [ 0, 1, 3, 1, 0 ] | ||
], | ||
mergeCardsAndAccountsInArray // [ 0, 1, 3, 2 ] | ||
@@ -148,4 +149,2 @@ ], | ||
describe('plan', () => { | ||
@@ -155,5 +154,4 @@ | ||
const returnTestFramework = plan(complexPlan)('f1') | ||
returnTestFramework.pipe( | ||
fork | ||
(error => assert.fail('Future was not expected to be rejected')) | ||
return promise(returnTestFramework) | ||
.then( | ||
(data => | ||
@@ -170,6 +168,59 @@ assert.deepStrictEqual( | ||
) | ||
) | ||
), | ||
(error => assert.fail('Future was not expected to be rejected with: ' + JSON.stringify(error))) | ||
) | ||
}) | ||
it('Repeating the test should work as expected', () => { | ||
const returnTestFramework = plan(complexPlan)('f1') | ||
return promise(returnTestFramework) | ||
.then( | ||
(data => | ||
assert.deepStrictEqual( | ||
data, | ||
{ | ||
name: 'Jose Marin', | ||
holdings: [ | ||
{ account: '2', current: 12, available: 35, uuid: 'u2' }, | ||
{ account: '3', current: 8, available: 1975, uuid: 'u3' } | ||
] | ||
} | ||
) | ||
), | ||
(error => assert.fail('Future was not expected to be rejected with: ' + JSON.stringify(error))) | ||
) | ||
}) | ||
it('plan expected output using mockups', () => { | ||
const returnTestFramework = | ||
plan( | ||
complexPlan, | ||
{ | ||
numberOfThreads: Infinity, | ||
mockupsObj: { | ||
getBankingBalances: resolve([{ | ||
account: '2', | ||
current: 999, | ||
available: 99 | ||
}]) | ||
} | ||
} | ||
)('f1') | ||
return promise(returnTestFramework) | ||
.then( | ||
(data => | ||
assert.deepStrictEqual( | ||
data, | ||
{ | ||
name: 'Jose Marin', | ||
holdings: [ | ||
{ account: '2', current: 999, available: 99, uuid: 'u2' }, | ||
{ account: '3', current: 8, available: 1975, uuid: 'u3' } | ||
] | ||
} | ||
) | ||
), | ||
(error => assert.fail('Future was not expected to be rejected with: ' + JSON.stringify(error))) | ||
) | ||
@@ -176,0 +227,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
155655
4654