Skip to content

Commit a6bc6f4

Browse files
committed
invalid vote prevention
1 parent 97416af commit a6bc6f4

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/core.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ export function next(state) {
3232
}
3333

3434
export function vote(voteState, entry) {
35-
return voteState.updateIn(
36-
['tally', entry],
37-
0,
38-
tally => tally + 1
39-
);
35+
if (voteState.get('pair').includes(entry)) {
36+
return voteState.updateIn(
37+
['tally', entry],
38+
0,
39+
tally => tally + 1
40+
);
41+
} else {
42+
return voteState;
43+
}
4044
}

test/core_spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ describe('application logic', () => {
144144
);
145145
});
146146

147+
it('ignores the vote if for an invalid entry', () => {
148+
expect(
149+
vote(Map({
150+
pair: List.of('Trainspotting', '28 Days Later')
151+
}), 'Sunshine')
152+
).to.equal(
153+
Map({
154+
pair: List.of('Trainspotting', '28 Days Later')
155+
})
156+
);
157+
});
158+
147159
});
148160

149161
});

0 commit comments

Comments
 (0)