Skip to content

Commit

Permalink
Null check selection piles (#278)
Browse files Browse the repository at this point in the history
* null check

* cleaning

---------

Co-authored-by: Mads Christiansen <madc@assemblyvoting.com>
  • Loading branch information
av-alexistoledo and av-mads authored Nov 28, 2023
1 parent b6a5050 commit 3011b11
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions lib/av_client/validate_selections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@ function validateSelectionPile(pile: SelectionPile, markingType: MarkingType, op
throw new CorruptSelectionError('Blank submissions are not allowed in this contest')
}

// Validate that mark count is within bounds
const calculatedMinMarks = !isBlank && getOption(pile.optionSelections[0]).exclusive ? 1 : markingType.minMarks;
if( !isBlank && !withinBounds(calculatedMinMarks, pile.optionSelections.length, markingType.maxMarks) ){
throw new CorruptSelectionError('Contest selection does not contain a valid amount of option selections')
}

pile.optionSelections.forEach(optionSelection => {
const option = getOption(optionSelection)

// Validate that mark count is within bounds

const isExlusive = pile.optionSelections?.length && option?.exclusive
const calculatedMinMarks = !isBlank && isExlusive ? 1 : markingType.minMarks;

if( !isBlank && !withinBounds(calculatedMinMarks, pile.optionSelections.length, markingType.maxMarks) ){
throw new CorruptSelectionError('Contest selection does not contain a valid amount of option selections')
}

if( option.writeIn ){
if( !optionSelection.text ){
throw new CorruptSelectionError('Expected write in text missing for option selection')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "3.1.16",
"version": "3.1.17",
"name": "@aion-dk/js-client",
"license": "MIT",
"description": "Assembly Voting JS client",
Expand Down

0 comments on commit 3011b11

Please sign in to comment.