Skip to content

Commit

Permalink
Minimally update the VxCentralScan backend
Browse files Browse the repository at this point in the history
To account for libs/backend changes
  • Loading branch information
arsalansufi committed Oct 2, 2023
1 parent fb4deb7 commit 3856417
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion apps/central-scan/backend/src/central_scanner_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export function buildCentralScannerApp({
const exportResult = await exportCastVoteRecordsToUsbDrive(
store,
usb,
store.forEachResultSheet(),
store.forEachAcceptedSheet(),
{ scannerType: 'central' }
);

Expand Down
33 changes: 17 additions & 16 deletions apps/central-scan/backend/src/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import * as tmp from 'tmp';
import { v4 as uuid } from 'uuid';
import { sleep, typedAs } from '@votingworks/basics';
import { ResultSheet } from '@votingworks/backend';
import { AcceptedSheet } from '@votingworks/backend';
import { electionGridLayoutNewHampshireAmherstFixtures } from '@votingworks/fixtures';
import { sha256 } from 'js-sha256';
import { zeroRect } from '../test/fixtures/zero_rect';
Expand Down Expand Up @@ -534,22 +534,23 @@ const sheetWithFiles: SheetOf<PageInterpretationWithFiles> = [
},
];

test('iterating over all result sheets', () => {
test('iterating over all accepted sheets', () => {
const store = Store.memoryStore();
store.setElectionAndJurisdiction({ electionData, jurisdiction });

// starts empty
expect(Array.from(store.forEachResultSheet())).toEqual([]);
expect(Array.from(store.forEachAcceptedSheet())).toEqual([]);

// add a batch with a sheet
const batchId = store.addBatch();
store.addSheet(uuid(), batchId, sheetWithFiles);
store.finishBatch({ batchId });

// has one sheet
expect(Array.from(store.forEachResultSheet())).toEqual(
typedAs<ResultSheet[]>([
expect(Array.from(store.forEachAcceptedSheet())).toEqual(
typedAs<AcceptedSheet[]>([
{
type: 'accepted',
id: expect.any(String),
batchId,
indexInBatch: 1,
Expand All @@ -563,7 +564,7 @@ test('iterating over all result sheets', () => {

// delete the batch and the results are empty again
store.deleteBatch(batchId);
expect(Array.from(store.forEachResultSheet())).toEqual([]);
expect(Array.from(store.forEachAcceptedSheet())).toEqual([]);

// add a sheet requiring adjudication and check that it is not included
const batchId2 = store.addBatch();
Expand All @@ -590,10 +591,10 @@ test('iterating over all result sheets', () => {
},
sheetWithFiles[1],
]);
expect(Array.from(store.forEachResultSheet())).toEqual([]);
expect(Array.from(store.forEachAcceptedSheet())).toEqual([]);
});

test('iterating over each result sheet includes correct batch sequence id', () => {
test('iterating over each accepted sheet includes correct batch sequence id', () => {
const store = Store.memoryStore();
store.setElectionAndJurisdiction({ electionData, jurisdiction });

Expand Down Expand Up @@ -627,9 +628,9 @@ test('iterating over each result sheet includes correct batch sequence id', () =
const batch3Sheet2Id = store.addSheet(uuid(), batch3Id, generateSheet());
store.finishBatch({ batchId: batch3Id });

const resultSheets = Array.from(store.forEachResultSheet());
expect(resultSheets).toHaveLength(6);
const expectedResultSheets: Array<
const acceptedSheets = Array.from(store.forEachAcceptedSheet());
expect(acceptedSheets).toHaveLength(6);
const expectedAcceptedSheets: Array<
[id: string, batchId: string, indexInBatch: number]
> = [
[batch1Sheet1Id, batch1Id, 1],
Expand All @@ -639,13 +640,13 @@ test('iterating over each result sheet includes correct batch sequence id', () =
[batch3Sheet1Id, batch3Id, 1],
[batch3Sheet2Id, batch3Id, 2],
];
for (const expectedResultSheet of expectedResultSheets) {
expect(resultSheets).toMatchObject(
for (const expectedAcceptedSheet of expectedAcceptedSheets) {
expect(acceptedSheets).toMatchObject(
expect.arrayContaining([
expect.objectContaining({
id: expectedResultSheet[0],
batchId: expectedResultSheet[1],
indexInBatch: expectedResultSheet[2],
id: expectedAcceptedSheet[0],
batchId: expectedAcceptedSheet[1],
indexInBatch: expectedAcceptedSheet[2],
}),
])
);
Expand Down
7 changes: 4 additions & 3 deletions apps/central-scan/backend/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { sha256 } from 'js-sha256';
import { DateTime } from 'luxon';
import { dirname, join } from 'path';
import { v4 as uuid } from 'uuid';
import { ResultSheet } from '@votingworks/backend';
import { AcceptedSheet } from '@votingworks/backend';
import {
clearCastVoteRecordHashes,
getCastVoteRecordRootHash,
Expand Down Expand Up @@ -856,9 +856,9 @@ export class Store {
}

/**
* Yields all sheets in the database that would be included in a CVR export.
* Yields all scanned sheets that were accepted and should be tabulated
*/
*forEachResultSheet(): Generator<ResultSheet> {
*forEachAcceptedSheet(): Generator<AcceptedSheet> {
const sql = `
select
sheets.id as id,
Expand Down Expand Up @@ -887,6 +887,7 @@ export class Store {
indexInBatch: number;
}>) {
yield {
type: 'accepted',
id: row.id,
batchId: row.batchId,
indexInBatch: row.indexInBatch,
Expand Down

0 comments on commit 3856417

Please sign in to comment.