-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#58 better test coverage for eventAction reducing
- Loading branch information
1 parent
a87161a
commit 92a1615
Showing
9 changed files
with
1,170 additions
and
374 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Removes all the estimations of the given user from all the stories | ||
* This is done, when a user leaves the room. | ||
* | ||
* @param {object} storiesObjectFromReduxState | ||
* @param {string} userId | ||
* @return {object} the modified "stories" object | ||
*/ | ||
export default function clearStoryEstimationsOfUser(storiesObjectFromReduxState, userId) { | ||
const storyArray = Object.values(storiesObjectFromReduxState); | ||
|
||
return storyArray.reduce((result, currentStory) => { | ||
const estimationArrayOfCurrentStory = Object.keys(currentStory.estimations); | ||
const estimationOfUser = estimationArrayOfCurrentStory.find((uid) => userId === uid); | ||
|
||
if (!estimationOfUser) { | ||
result[currentStory.id] = currentStory; | ||
return result; | ||
} | ||
|
||
const modifiedEstimations = {...currentStory.estimations}; | ||
delete modifiedEstimations[userId]; | ||
result[currentStory.id] = { | ||
...currentStory, | ||
estimations: modifiedEstimations | ||
}; | ||
return result; | ||
}, {}); | ||
} |
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
Oops, something went wrong.