diff --git a/app/javascript/packages/document-capture/components/acuant-camera.tsx b/app/javascript/packages/document-capture/components/acuant-camera.tsx index b6707d54eaa..2ec70c0bfc4 100644 --- a/app/javascript/packages/document-capture/components/acuant-camera.tsx +++ b/app/javascript/packages/document-capture/components/acuant-camera.tsx @@ -93,6 +93,9 @@ interface AcuantCameraUIOptions { text: AcuantCameraUIText; } +/** + * We call String.toLowerCase() on these when sending analytics events to the server + */ export enum AcuantDocumentType { NONE = 0, ID = 1, diff --git a/app/javascript/packages/document-capture/components/acuant-capture.tsx b/app/javascript/packages/document-capture/components/acuant-capture.tsx index acbe5ccd9e5..94259387c4e 100644 --- a/app/javascript/packages/document-capture/components/acuant-capture.tsx +++ b/app/javascript/packages/document-capture/components/acuant-capture.tsx @@ -16,20 +16,15 @@ import type { ReactNode, MouseEvent, Ref } from 'react'; import AnalyticsContext from '../context/analytics'; import AcuantContext from '../context/acuant'; import FailedCaptureAttemptsContext from '../context/failed-capture-attempts'; -import AcuantCamera from './acuant-camera'; +import AcuantCamera, { AcuantDocumentType } from './acuant-camera'; import AcuantCaptureCanvas from './acuant-capture-canvas'; import FileInput from './file-input'; import DeviceContext from '../context/device'; import UploadContext from '../context/upload'; import useCounter from '../hooks/use-counter'; import useCookie from '../hooks/use-cookie'; -import type { - AcuantSuccessResponse, - AcuantDocumentType, - AcuantCaptureFailureError, -} from './acuant-camera'; +import type { AcuantSuccessResponse, AcuantCaptureFailureError } from './acuant-camera'; -type AcuantDocumentTypeLabel = 'id' | 'passport' | 'none'; type AcuantImageAssessment = 'success' | 'glare' | 'blurry' | 'unsupported'; type ImageSource = 'acuant' | 'upload'; @@ -61,7 +56,7 @@ interface ImageAnalyticsPayload { } interface AcuantImageAnalyticsPayload extends ImageAnalyticsPayload { - documentType: AcuantDocumentTypeLabel | string; + documentType: string; dpi: number; moire: number; glare: number; @@ -132,21 +127,12 @@ export const isAcuantCameraAccessFailure = (error: AcuantCaptureFailureError): e error instanceof Error; /** - * Returns a human-readable document label corresponding to the given document type constant. - * + * Returns a human-readable document label corresponding to the given document type constant, + * such as "id" "passport" or "none" */ -function getDocumentTypeLabel(documentType: AcuantDocumentType): AcuantDocumentTypeLabel | string { - switch (documentType) { - case 0: - return 'none'; - case 1: - return 'id'; - case 2: - return 'passport'; - default: - return `An error in document type returned: ${documentType}`; - } -} +const getDocumentTypeLabel = (documentType: AcuantDocumentType): string => + AcuantDocumentType[documentType]?.toLowerCase() ?? + `An error in document type returned: ${documentType}`; export function getNormalizedAcuantCaptureFailureMessage( error: AcuantCaptureFailureError, @@ -438,7 +424,7 @@ function AcuantCapture( const { image, cardtype, dpi, moire, glare, sharpness } = nextCapture; const isAssessedAsGlare = glare < glareThreshold; const isAssessedAsBlurry = sharpness < sharpnessThreshold; - const isAssessedAsUnsupported = cardtype !== 1; + const isAssessedAsUnsupported = cardtype !== AcuantDocumentType.ID; const { width, height, data } = image; let assessment: AcuantImageAssessment; @@ -593,3 +579,4 @@ function AcuantCapture( } export default forwardRef(AcuantCapture); +export { AcuantDocumentType }; diff --git a/spec/javascript/packages/document-capture/components/acuant-capture-spec.jsx b/spec/javascript/packages/document-capture/components/acuant-capture-spec.jsx index 320abd0c920..b0b38f5c322 100644 --- a/spec/javascript/packages/document-capture/components/acuant-capture-spec.jsx +++ b/spec/javascript/packages/document-capture/components/acuant-capture-spec.jsx @@ -6,6 +6,7 @@ import AcuantCapture, { isAcuantCameraAccessFailure, getNormalizedAcuantCaptureFailureMessage, getDecodedBase64ByteSize, + AcuantDocumentType, } from '@18f/identity-document-capture/components/acuant-capture'; import { AcuantContextProvider, AnalyticsContext } from '@18f/identity-document-capture'; import DeviceContext from '@18f/identity-document-capture/context/device'; @@ -20,7 +21,7 @@ const ACUANT_CAPTURE_SUCCESS_RESULT = { width: 1748, height: 1104, }, - cardtype: 1, + cardtype: AcuantDocumentType.ID, dpi: 519, moire: 99, moireraw: 99, @@ -566,7 +567,7 @@ describe('document-capture/components/acuant-capture', () => { await Promise.resolve(); callbacks.onCropped({ ...ACUANT_CAPTURE_SUCCESS_RESULT, - cardtype: 2, + cardtype: AcuantDocumentType.PASSPORT, }); }), }); diff --git a/spec/javascript/packages/document-capture/components/document-capture-spec.jsx b/spec/javascript/packages/document-capture/components/document-capture-spec.jsx index c685a5dc62c..9641ccbc91d 100644 --- a/spec/javascript/packages/document-capture/components/document-capture-spec.jsx +++ b/spec/javascript/packages/document-capture/components/document-capture-spec.jsx @@ -16,6 +16,7 @@ import DocumentCapture from '@18f/identity-document-capture/components/document- import { FlowContext } from '@18f/identity-verify-flow'; import { expect } from 'chai'; import { useSandbox } from '@18f/identity-test-helpers'; +import { AcuantDocumentType } from '@18f/identity-document-capture/components/acuant-camera'; import { render, useAcuant, useDocumentCaptureForm } from '../../../support/document-capture'; import { getFixtureFile } from '../../../support/file'; @@ -91,7 +92,7 @@ describe('document-capture/components/document-capture', () => { image: { data: validUpload, }, - cardtype: 1, + cardtype: AcuantDocumentType.ID, }); }); diff --git a/spec/javascript/packages/document-capture/components/documents-step-spec.jsx b/spec/javascript/packages/document-capture/components/documents-step-spec.jsx index 0a289f0386a..548fd4b325a 100644 --- a/spec/javascript/packages/document-capture/components/documents-step-spec.jsx +++ b/spec/javascript/packages/document-capture/components/documents-step-spec.jsx @@ -9,6 +9,7 @@ import { UploadContextProvider, } from '@18f/identity-document-capture'; import DocumentsStep from '@18f/identity-document-capture/components/documents-step'; +import { AcuantDocumentType } from '@18f/identity-document-capture/components/acuant-camera'; import { render, useAcuant } from '../../../support/document-capture'; import { getFixtureFile } from '../../../support/file'; @@ -66,7 +67,7 @@ describe('document-capture/components/documents-step', () => { ); initialize(); - const result = { sharpness: 100, image: { data: '' }, cardtype: 1 }; + const result = { sharpness: 100, image: { data: '' }, cardtype: AcuantDocumentType.ID }; window.AcuantCameraUI.start.callsFake(({ onCropped }) => onCropped({ ...result, glare: 10 })); await userEvent.click(getByLabelText('doc_auth.headings.document_capture_front'));