Last active
December 22, 2019 12:41
-
-
Save MinimumViablePerson/94aae4e600d001ed0940f9d49d80ffeb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { keyEquals, any, hasNo, has } = require('./utils') | |
const itemIdEquals = keyEquals('itemId') | |
const isScheduledItemSuccess = collectionItem => | |
any( | |
itemIdEquals(collectionItem._id), | |
hasNo('publishingError') | |
) | |
const isScheduledItemFailure = collectionItem => | |
any( | |
itemIdEquals(collectionItem._id), | |
has('publishingError') | |
) | |
module.exports = { | |
isScheduledItemSuccess, | |
isScheduledItemFailure | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { isScheduledItemFailure, isScheduledItemSuccess } = require('./main') | |
const scheduledItems = [ | |
{ itemId: 1, publishingError: 'Timeout' }, | |
{ itemId: 2 } | |
] | |
const failedItem = { _id: 1 } | |
const successfulItem = { _id: 2 } | |
console.assert( | |
isScheduledItemSuccess(failedItem)(scheduledItems) === false, | |
'isScheduledItemSuccess returns false for failed item' | |
) | |
console.assert( | |
isScheduledItemSuccess(successfulItem)(scheduledItems) === true, | |
'isScheduledItemSuccess returns true for successful item' | |
) | |
console.assert( | |
isScheduledItemFailure(failedItem)(scheduledItems) === true, | |
'isScheduledItemFailure returns true for failed item' | |
) | |
console.assert( | |
isScheduledItemFailure(successfulItem)(scheduledItems) === false, | |
'isScheduledItemFailure returns false for successful item' | |
) | |
console.log('All tests ended.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const any = (...predicates) => array => | |
array.some(item => predicates.every(predicate => predicate(item))) | |
const pipe = (...funcs) => initialValue => | |
funcs.reduce((value, func) => func(value), initialValue) | |
const prop = key => obj => obj[key] | |
const not = boolean => !boolean | |
const has = key => obj => obj.hasOwnProperty(key) | |
const hasNo = key => pipe(has(key), not) | |
const equals = a => b => a === b | |
const keyEquals = key => target => pipe(prop(key), equals(target)) | |
module.exports = { | |
any, | |
pipe, | |
prop, | |
not, | |
has, | |
hasNo, | |
equals, | |
keyEquals | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if changing the function signature is not an option
we can always keep scheduledItems as a param