Skip to content

Commit

Permalink
Add more test and string method
Browse files Browse the repository at this point in the history
  • Loading branch information
terryx committed Sep 11, 2016
1 parent a3426a2 commit 42b9110
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
8 changes: 8 additions & 0 deletions monad/flow-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ const constructor = () => {
return inputs.map(input => input.toUpperCase());
}

api.getServiceType = (input) => {
if (input === 'GC') {
return 'GRABCAR';
}

return input;
}

return Object.freeze(api);
};

Expand Down
23 changes: 16 additions & 7 deletions tests/flow-string.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@ const flow = require('lodash/fp/flow');
const map = require('lodash/fp/map');

//the rule is input and output must produce same type
test('flow structure', t => {
test('flow basic structure', t => {
const result = flow(
string.mapUppercase,
map(input => {
if (input === 'FAKE') {
return 'FAKER'
if (input === 'GT') {
return 'GRABTAXI';
} else {
return input;
}

return input;
})
)(['grab', 'fake']);
)(['grab', 'gt']);

t.deepEqual(result, ['GRAB', 'GRABTAXI'])
});

test('flow to getServiceType', t => {
const result = flow(
string.mapUppercase,
map(string.getServiceType)
)(['grab', 'gc']);

t.deepEqual(result, ['GRAB', 'FAKER'])
t.deepEqual(result, ['GRAB', 'GRABCAR'])
});

0 comments on commit 42b9110

Please sign in to comment.