-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix missing participants #1
Conversation
src/participants.test.js
Outdated
@@ -211,6 +211,30 @@ describe('.calculateFinalizeMaps', () => { | |||
|
|||
expect(calculateFinalizeMaps(ps)).toEqual(maps) | |||
}) | |||
|
|||
it.only('p5 is missing, override', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take out only
to make sure that all the other tests pass
ps.splice(5, 1) | ||
|
||
expect(calculateFinalizeMaps(ps, true)).toEqual(maps) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add another test case which throws the Invalid overrideMissingValue
error
src/participants.js
Outdated
@@ -20,10 +20,36 @@ export const calculateNumAttended = participants => participants.reduce((m, v) = | |||
return m + (attended ? 1 : 0) | |||
}, 0) | |||
|
|||
export const calculateFinalizeMaps = participants => { | |||
export const calculateFinalizeMaps = (participants, overrideMissingValue = false) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about the following 3 options
calculateFinalizeMaps(participants)
= Default, raises error if there is a missing valuecalculateFinalizeMaps(participants, overrideMissingValue=1)
= set missing value as 1calculateFinalizeMaps(participants, overrideMissingValue=0)
= set missing value as 0calculateFinalizeMaps(participants, overrideMissingValue=12345)
= invalid value, throw error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be better to have the caller pass in the PARTICIPANT_STATUS.<value>
as the overrideMissingValue
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hiddentao not sure about that. PARTICIPANT_STATUS has 5 valid statuses but this option has 3 (1, 0, null=throw error) and they don't map equally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just disallow the ones that don't map then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise, create a new enum to pass in as that would still be better than passing in magic numbers.
Fix missing participants
Adds checks for missing participants when calling calculating finalize maps.
The method
calculateFinalizeMaps
has a new parameteroverrideMissingValue
which defaults tofalse
.overrideMissingValue == false
the method throws an error when it detects a missing participant in theparticipants
array.overrideMissingValue == true
the method inserts a dummy participant withstatus = PARTICIPANT_STATUS.REGISTERED
when it detects a missing participant