Skip to content

Commit

Permalink
invalid vote prevention
Browse files Browse the repository at this point in the history
  • Loading branch information
teropa committed Sep 10, 2015
1 parent 97416af commit a6bc6f4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ export function next(state) {
}

export function vote(voteState, entry) {
return voteState.updateIn(
['tally', entry],
0,
tally => tally + 1
);
if (voteState.get('pair').includes(entry)) {
return voteState.updateIn(
['tally', entry],
0,
tally => tally + 1
);
} else {
return voteState;
}
}
12 changes: 12 additions & 0 deletions test/core_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ describe('application logic', () => {
);
});

it('ignores the vote if for an invalid entry', () => {
expect(
vote(Map({
pair: List.of('Trainspotting', '28 Days Later')
}), 'Sunshine')
).to.equal(
Map({
pair: List.of('Trainspotting', '28 Days Later')
})
);
});

});

});

0 comments on commit a6bc6f4

Please sign in to comment.