Skip to content
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

Manual Tally Policy - CSV Tally Reports #4074

Merged
merged 8 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions libs/utils/src/tabulation/tabulation.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
electionFamousNames2021Fixtures,
electionTwoPartyPrimary,
electionTwoPartyPrimaryDefinition,
electionTwoPartyPrimaryFixtures,
} from '@votingworks/fixtures';
Expand All @@ -11,6 +12,7 @@ import {
YesNoContest,
safeParseJson,
CastVoteRecordExportFileName,
CandidateContest,
} from '@votingworks/types';
import { readFileSync } from 'fs';
import { join } from 'path';
Expand All @@ -37,6 +39,8 @@ import {
getSheetCount,
getScannedBallotCount,
getHmpbBallotCount,
combineCandidateContestResults,
buildContestResultsFixture,
} from './tabulation';
import {
convertCastVoteRecordVotesToTabulationVotes,
Expand Down Expand Up @@ -1265,3 +1269,56 @@ test('mergeManualWriteInTallies', () => {
})
);
});

test('combinedCandidateContestResults - does not alter original tallies', () => {
const contest = find(
electionTwoPartyPrimary.contests,
(c) => c.id === 'zoo-council-mammal'
) as CandidateContest;
const contestResultsA = buildContestResultsFixture({
contest,
contestResultsSummary: {
type: 'candidate',
ballots: 50,
writeInOptionTallies: {
'write-in-1': {
name: 'Write-In 1',
tally: 10,
},
'write-in-2': {
name: 'Write-In 2',
tally: 40,
},
},
},
}) as Tabulation.CandidateContestResults;

const contestResultsB = buildContestResultsFixture({
contest,
contestResultsSummary: {
type: 'candidate',
ballots: 50,
writeInOptionTallies: {
'write-in-1': {
name: 'Write-In 1',
tally: 20,
},
'write-in-3': {
name: 'Write-In 3',
tally: 30,
},
},
},
}) as Tabulation.CandidateContestResults;

const aString = JSON.stringify(contestResultsA);
const bString = JSON.stringify(contestResultsB);

combineCandidateContestResults({
contest,
allContestResults: [contestResultsA, contestResultsB],
});

expect(JSON.stringify(contestResultsA)).toEqual(aString);
expect(JSON.stringify(contestResultsB)).toEqual(bString);
});
4 changes: 3 additions & 1 deletion libs/utils/src/tabulation/tabulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,9 @@ export function combineCandidateContestResults({
combinedContestResults.tallies[candidateTally.id];

if (!combinedCandidateTally) {
combinedContestResults.tallies[candidateTally.id] = candidateTally;
combinedContestResults.tallies[candidateTally.id] = {
...candidateTally,
};
Comment on lines -544 to +545
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈

} else {
combinedCandidateTally.tally += candidateTally.tally;
}
Expand Down