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

change ballot package location on USB #4142

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 8 additions & 3 deletions apps/admin/backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { createReadStream, createWriteStream, promises as fs } from 'fs';
import path, { join } from 'path';
import {
BALLOT_PACKAGE_FOLDER,
generateElectionBasedSubfolderName,
generateFilenameForBallotExportPackage,
groupMapToGroupList,
isIntegrationTest,
Expand Down Expand Up @@ -221,12 +222,12 @@ function buildApi({
const electionRecord = getCurrentElectionRecord(workspace);
assert(electionRecord);
const { electionDefinition, id: electionId } = electionRecord;
const { election, electionHash } = electionDefinition;
const systemSettings = store.getSystemSettings(electionId);

const tempDirectory = dirSync().name;
try {
const ballotPackageFileName = generateFilenameForBallotExportPackage(
electionDefinition,
new Date()
);
const tempDirectoryBallotPackageFilePath = join(
Expand Down Expand Up @@ -255,8 +256,12 @@ function buildApi({
ballotPackageZipStream.finish();
await ballotPackageZipPromise.promise;

const usbDriveBallotPackageDirectoryRelativePath = join(
generateElectionBasedSubfolderName(election, electionHash),
BALLOT_PACKAGE_FOLDER
);
const exportBallotPackageResult = await exporter.exportDataToUsbDrive(
BALLOT_PACKAGE_FOLDER,
usbDriveBallotPackageDirectoryRelativePath,
ballotPackageFileName,
createReadStream(tempDirectoryBallotPackageFilePath)
);
Expand All @@ -272,7 +277,7 @@ function buildApi({
filePath: tempDirectoryBallotPackageFilePath,
});
const exportSignatureFileResult = await exporter.exportDataToUsbDrive(
BALLOT_PACKAGE_FOLDER,
usbDriveBallotPackageDirectoryRelativePath,
signatureFile.fileName,
signatureFile.fileContents
);
Expand Down
30 changes: 14 additions & 16 deletions apps/central-scan/backend/src/end_to_end_hmpb.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import getPort from 'get-port';
import {
createBallotPackageZipArchive,
getCastVoteRecordExportDirectoryPaths,
isTestReport,
mockBallotPackageFileTree,
readCastVoteRecordExport,
} from '@votingworks/backend';
import {
Expand Down Expand Up @@ -143,21 +143,19 @@ test('going through the whole process works', async () => {
BooleanEnvironmentVariableName.SKIP_BALLOT_PACKAGE_AUTHENTICATION
);

mockUsbDrive.insertUsbDrive({
'ballot-packages': {
'ballot-package.zip': await createBallotPackageZipArchive(
electionGridLayoutNewHampshireAmherstFixtures.electionJson.toBallotPackage(
{
...DEFAULT_SYSTEM_SETTINGS,
markThresholds: {
definite: 0.08,
marginal: 0.05,
},
}
)
),
},
});
mockUsbDrive.insertUsbDrive(
await mockBallotPackageFileTree(
electionGridLayoutNewHampshireAmherstFixtures.electionJson.toBallotPackage(
{
...DEFAULT_SYSTEM_SETTINGS,
markThresholds: {
definite: 0.08,
marginal: 0.05,
},
}
)
)
);
const configureResult =
await apiClient.configureFromBallotPackageOnUsbDrive();
expect(configureResult.err()).toBeUndefined();
Expand Down
14 changes: 6 additions & 8 deletions apps/central-scan/integration-testing/e2e/configuration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from '@playwright/test';
import { createBallotPackageZipArchive } from '@votingworks/backend';
import { mockBallotPackageFileTree } from '@votingworks/backend';
import { getMockFileUsbDriveHandler } from '@votingworks/usb-drive';
import { electionGridLayoutNewHampshireAmherstFixtures } from '@votingworks/fixtures';
import { logInAsElectionManager, forceReset } from './helpers';
Expand All @@ -15,13 +15,11 @@ test('configure + scan', async ({ page }) => {

await logInAsElectionManager(page, electionDefinition.electionHash);

usbHandler.insert({
'ballot-packages': {
'ballot-package.zip': await createBallotPackageZipArchive(
electionGridLayoutNewHampshireAmherstFixtures.electionJson.toBallotPackage()
),
},
});
usbHandler.insert(
await mockBallotPackageFileTree(
electionGridLayoutNewHampshireAmherstFixtures.electionJson.toBallotPackage()
)
);
await page.getByText('No ballots have been scanned').waitFor();
usbHandler.remove();

Expand Down
28 changes: 14 additions & 14 deletions apps/mark-scan/backend/src/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import {
} from '@votingworks/test-utils';
import { InsertedSmartCardAuthApi } from '@votingworks/auth';
import {
BALLOT_PACKAGE_FOLDER,
BooleanEnvironmentVariableName,
getFeatureFlagMock,
singlePrecinctSelectionFor,
} from '@votingworks/utils';
import { Buffer } from 'buffer';
import { createBallotPackageZipArchive } from '@votingworks/backend';
import { mockBallotPackageFileTree } from '@votingworks/backend';
import { Server } from 'http';
import * as grout from '@votingworks/grout';
import {
Expand Down Expand Up @@ -68,17 +69,14 @@ afterEach(() => {
async function setUpUsbAndConfigureElection(
electionDefinition: ElectionDefinition
) {
const zipBuffer = await createBallotPackageZipArchive({
electionDefinition,
systemSettings: safeParseSystemSettings(
systemSettings.asText()
).unsafeUnwrap(),
});
mockUsbDrive.insertUsbDrive({
'ballot-packages': {
'test-ballot-package.zip': zipBuffer,
},
});
mockUsbDrive.insertUsbDrive(
await mockBallotPackageFileTree({
electionDefinition,
systemSettings: safeParseSystemSettings(
systemSettings.asText()
).unsafeUnwrap(),
})
);

const writeResult = await apiClient.configureBallotPackageFromUsb();
assert(writeResult.isOk());
Expand Down Expand Up @@ -227,8 +225,10 @@ test('configureBallotPackageFromUsb returns an error if ballot package parsing f
);

mockUsbDrive.insertUsbDrive({
'ballot-packages': {
'test-ballot-package.zip': Buffer.from("doesn't matter"),
'some-election': {
[BALLOT_PACKAGE_FOLDER]: {
'test-ballot-package.zip': Buffer.from("doesn't matter"),
},
},
});

Expand Down
14 changes: 6 additions & 8 deletions apps/mark-scan/backend/test/app_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Application } from 'express';
import { AddressInfo } from 'net';
import { fakeLogger, Logger } from '@votingworks/logging';
import tmp from 'tmp';
import { createBallotPackageZipArchive } from '@votingworks/backend';
import { mockBallotPackageFileTree } from '@votingworks/backend';
import { Server } from 'http';
import { electionFamousNames2021Fixtures } from '@votingworks/fixtures';
import {
Expand Down Expand Up @@ -128,13 +128,11 @@ export async function configureApp(
sessionExpiresAt: fakeSessionExpiresAt(),
})
);
mockUsbDrive.insertUsbDrive({
'ballot-packages': {
'test-ballot-package.zip': await createBallotPackageZipArchive(
electionJson.toBallotPackage(systemSettings)
),
},
});
mockUsbDrive.insertUsbDrive(
await mockBallotPackageFileTree(
electionJson.toBallotPackage(systemSettings)
)
);
const result = await apiClient.configureBallotPackageFromUsb();
expect(result.isOk()).toEqual(true);
mockOf(mockAuth.getAuthStatus).mockImplementation(() =>
Expand Down
51 changes: 24 additions & 27 deletions apps/mark/backend/src/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import {
ElectionDefinition,
} from '@votingworks/types';
import {
BALLOT_PACKAGE_FOLDER,
BooleanEnvironmentVariableName,
getFeatureFlagMock,
} from '@votingworks/utils';

import { Buffer } from 'buffer';
import { createBallotPackageZipArchive } from '@votingworks/backend';
import { mockBallotPackageFileTree } from '@votingworks/backend';
import { Server } from 'http';
import * as grout from '@votingworks/grout';
import { MockUsbDrive } from '@votingworks/usb-drive';
Expand Down Expand Up @@ -97,18 +98,15 @@ test('configureBallotPackageFromUsb reads to and writes from store', async () =>

mockElectionManagerAuth(electionDefinition);

const zipBuffer = await createBallotPackageZipArchive({
electionDefinition,
systemSettings: safeParseJson(
systemSettings.asText(),
SystemSettingsSchema
).unsafeUnwrap(),
});
mockUsbDrive.insertUsbDrive({
'ballot-packages': {
'test-ballot-package.zip': zipBuffer,
},
});
mockUsbDrive.insertUsbDrive(
await mockBallotPackageFileTree({
electionDefinition,
systemSettings: safeParseJson(
systemSettings.asText(),
SystemSettingsSchema
).unsafeUnwrap(),
})
);

const writeResult = await apiClient.configureBallotPackageFromUsb();
assert(writeResult.isOk());
Expand All @@ -126,18 +124,15 @@ test('unconfigureMachine deletes system settings and election definition', async

mockElectionManagerAuth(electionDefinition);

const zipBuffer = await createBallotPackageZipArchive({
electionDefinition,
systemSettings: safeParseJson(
systemSettings.asText(),
SystemSettingsSchema
).unsafeUnwrap(),
});
mockUsbDrive.insertUsbDrive({
'ballot-packages': {
'test-ballot-package.zip': zipBuffer,
},
});
mockUsbDrive.insertUsbDrive(
await mockBallotPackageFileTree({
electionDefinition,
systemSettings: safeParseJson(
systemSettings.asText(),
SystemSettingsSchema
).unsafeUnwrap(),
})
);

const writeResult = await apiClient.configureBallotPackageFromUsb();
assert(writeResult.isOk());
Expand Down Expand Up @@ -173,8 +168,10 @@ test('configureBallotPackageFromUsb returns an error if ballot package parsing f
);

mockUsbDrive.insertUsbDrive({
'ballot-packages': {
'test-ballot-package.zip': Buffer.from("doesn't matter"),
'some-election': {
[BALLOT_PACKAGE_FOLDER]: {
'test-ballot-package.zip': Buffer.from("doesn't matter"),
},
},
});

Expand Down
14 changes: 6 additions & 8 deletions apps/mark/backend/test/app_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Application } from 'express';
import { AddressInfo } from 'net';
import { fakeLogger } from '@votingworks/logging';
import tmp from 'tmp';
import { createBallotPackageZipArchive } from '@votingworks/backend';
import { mockBallotPackageFileTree } from '@votingworks/backend';
import { Server } from 'http';
import { electionFamousNames2021Fixtures } from '@votingworks/fixtures';
import {
Expand Down Expand Up @@ -71,13 +71,11 @@ export async function configureApp(
sessionExpiresAt: fakeSessionExpiresAt(),
})
);
mockUsbDrive.insertUsbDrive({
'ballot-packages': {
'test-ballot-package.zip': await createBallotPackageZipArchive(
electionJson.toBallotPackage(systemSettings)
),
},
});
mockUsbDrive.insertUsbDrive(
await mockBallotPackageFileTree(
electionJson.toBallotPackage(systemSettings)
)
);
const result = await apiClient.configureBallotPackageFromUsb();
expect(result.isOk()).toEqual(true);
mockOf(mockAuth.getAuthStatus).mockImplementation(() =>
Expand Down
12 changes: 4 additions & 8 deletions apps/mark/integration-testing/e2e/scroll_buttons.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
electionGeneralJson,
} from '@votingworks/fixtures';
import { getMockFileUsbDriveHandler } from '@votingworks/usb-drive';
import { createBallotPackageZipArchive } from '@votingworks/backend';
import { mockBallotPackageFileTree } from '@votingworks/backend';
import assert from 'assert';
import {
mockCardRemoval,
Expand Down Expand Up @@ -37,13 +37,9 @@ test('configure, open polls, and test contest scroll buttons', async ({
await enterPin(page);
await page.getByText('VxMark is Not Configured').waitFor();

usbHandler.insert({
'ballot-packages': {
'ballot-package.zip': await createBallotPackageZipArchive(
electionGeneralJson.toBallotPackage()
),
},
});
usbHandler.insert(
await mockBallotPackageFileTree(electionGeneralJson.toBallotPackage())
);

// Election Manager: set precinct
await page.getByText('Precinct', { exact: true }).waitFor();
Expand Down
Loading