Skip to content

Commit

Permalink
Merge branch 'test' of https://github.com/ustaxcourt/ef-cms into 1047…
Browse files Browse the repository at this point in the history
…6-story-intermediate-branch-to-test-1725906410
  • Loading branch information
Mwindo committed Sep 9, 2024
2 parents 8b7f454 + dcde118 commit 7338a3b
Show file tree
Hide file tree
Showing 280 changed files with 8,792 additions and 8,382 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ jobs:
- run:
name: Set Marker to Indicate Data is Finished Gluing
command: |
export DEPLOYING_COLOR="$CURRENT_COLOR"
JOB_NAME="wait-for-glued-data-to-index" ./scripts/migration/set-migration-complete-marker.sh
- run:
name: Enable Dynamodb Streams
Expand Down
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = {
'no-underscore-dangle': 'off',
'promise/always-return': 'off',
'promise/catch-or-return': 'off',
'promise/no-nesting': 'off',
},
},
{
Expand Down
4 changes: 4 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
toggleFeatureFlag,
} from './cypress/helpers/cypressTasks/dynamo/dynamo-helpers';
import { overrideIdleTimeouts } from './cypress/local-only/support/idleLogoutHelpers';
import { parsePdf } from './cypress/local-only/support/helpers.ts';
import { unzipFile } from './cypress/helpers/file/unzip-file';
import { waitForNoce } from './cypress/helpers/cypressTasks/wait-for-noce';
import { waitForPractitionerEmailUpdate } from './cypress/helpers/cypressTasks/wait-for-practitioner-email-update';
Expand Down Expand Up @@ -60,6 +61,9 @@ export default defineConfig({
getUserByEmail(email: string) {
return getUserByEmail(email);
},
parsePdf({ filePath }) {
return parsePdf({ filePath });
},
table(message) {
console.table(message);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ describe('Admissions Clerk Grants E-Access', () => {
getCypressEnv().defaultAccountPass,
);
cy.get('[data-testid="change-password-button"]').click();
cy.get('[data-testid="open-cases-count"]');
cy.get('[data-testid="petition-welcome-text"]');
createAndServePaperPetition().then(({ docketNumber }) => {
cy.login('admissionsclerk1');
cy.get('[data-testid="messages-banner"]');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Admissions Clerk Updates Practitioner Email', () => {
getCypressEnv().defaultAccountPass,
);
cy.get('[data-testid="change-password-button"]').click();
cy.get('[data-testid="open-cases-count"]');
cy.get('[data-testid="petition-welcome-text"]');
logout();

loginAsAdmissionsClerk();
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('Admissions Clerk Updates Practitioner Email', () => {
getCypressEnv().defaultAccountPass,
);
cy.get('[data-testid="change-password-button"]').click();
cy.get('[data-testid="open-cases-count"]');
cy.get('[data-testid="petition-welcome-text"]');

createAndServePaperPetition().then(({ docketNumber }) => {
cy.login('admissionsclerk1');
Expand Down
30 changes: 26 additions & 4 deletions cypress/helpers/fileAPetition/create-and-serve-paper-petition.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import { ProcedureType } from '../../../shared/src/business/entities/EntityConstants';
import { loginAsPetitionsClerk1 } from '../authentication/login-as-helpers';

export function createAndServePaperPetition(
options = { yearReceived: '2020' },
) {
{
procedureType = 'Regular',
trialLocation = 'Birmingham, Alabama',
yearReceived = '2020',
}: Partial<{
yearReceived: string;
procedureType: ProcedureType;
trialLocation: string;
}> = {
procedureType: 'Regular',
trialLocation: 'Birmingham, Alabama',
yearReceived: '2020',
},
): Cypress.Chainable<{
docketNumber: string;
documentsCreated: {
eventCode: string;
index: number;
servedTo: string;
}[];
name: string;
}> {
const name = 'rick james ' + Date.now();
loginAsPetitionsClerk1();
cy.get('[data-testid="inbox-tab-content"]').should('exist');
Expand All @@ -22,10 +43,11 @@ export function createAndServePaperPetition(
cy.get('[data-testid="phone"]').type('n/a');
cy.get('#tab-case-info > .button-text').click();
cy.get('#date-received-picker').clear();
cy.get('#date-received-picker').type(`01/02/${options.yearReceived}`);
cy.get('#date-received-picker').type(`01/02/${yearReceived}`);
cy.get('#mailing-date').clear();
cy.get('#mailing-date').type('01/02/2019');
cy.get('[data-testid="preferred-trial-city"]').select('Birmingham, Alabama');
cy.get(`[data-testid="procedure-type-${procedureType}-radio"]`).click();
cy.get('[data-testid="preferred-trial-city"]').select(trialLocation);
cy.get(
':nth-child(9) > .usa-fieldset > :nth-child(3) > .usa-radio__label',
).click();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PROCEDURE_TYPES_MAP } from '../../../shared/src/business/entities/EntityConstants';
import { uploadFile } from '../file/upload-file';

export function petitionerCreatesElectronicCaseUpdated(
Expand Down Expand Up @@ -26,8 +27,9 @@ export function petitionerCreatesElectronicCaseUpdated(
cy.get('[data-testid="redaction-acknowledgement-label"]').click();
cy.get('[data-testid="step-3-next-button"]').click();

cy.get('[data-testid="procedure-type-1"]').click();
cy.get('[data-testid="procedure-type-0"]').click();
cy.get(
`[data-testid="procedure-type-${PROCEDURE_TYPES_MAP.regular}-radio"]`,
).click();
cy.get('[data-testid="preferred-trial-city"]').select('Mobile, Alabama');
cy.get('[data-testid="step-4-next-button"]').click();

Expand Down Expand Up @@ -119,8 +121,9 @@ export function petitionerAttemptsToUploadCorruptPdfUpdated() {
cy.get('[data-testid="redaction-acknowledgement-label"]').click();
cy.get('[data-testid="step-3-next-button"]').click();

cy.get('[data-testid="procedure-type-1"]').click();
cy.get('[data-testid="procedure-type-0"]').click();
cy.get(
`[data-testid="procedure-type-${PROCEDURE_TYPES_MAP.regular}-radio"]`,
).click();
cy.get('[data-testid="preferred-trial-city"]').select('Mobile, Alabama');
cy.get('[data-testid="step-4-next-button"]').click();

Expand Down Expand Up @@ -170,8 +173,9 @@ export function petitionerCreatesElectronicCaseWithSpouseUpdated(
cy.get('[data-testid="redaction-acknowledgement-label"]').click();
cy.get('[data-testid="step-3-next-button"]').click();

cy.get('[data-testid="procedure-type-1"]').click();
cy.get('[data-testid="procedure-type-0"]').click();
cy.get(
`[data-testid="procedure-type-${PROCEDURE_TYPES_MAP.regular}-radio"]`,
).click();
cy.get('[data-testid="preferred-trial-city"]').select('Mobile, Alabama');
cy.get('[data-testid="step-4-next-button"]').click();

Expand Down Expand Up @@ -221,8 +225,9 @@ export function petitionerCreatesElectronicCaseWithDeceasedSpouseUpdated(
cy.get('[data-testid="redaction-acknowledgement-label"]').click();
cy.get('[data-testid="step-3-next-button"]').click();

cy.get('[data-testid="procedure-type-1"]').click();
cy.get('[data-testid="procedure-type-0"]').click();
cy.get(
`[data-testid="procedure-type-${PROCEDURE_TYPES_MAP.regular}-radio"]`,
).click();
cy.get('[data-testid="preferred-trial-city"]').select('Mobile, Alabama');
cy.get('[data-testid="step-4-next-button"]').click();

Expand Down
31 changes: 19 additions & 12 deletions cypress/helpers/fileAPetition/petitioner-creates-electronic-case.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PROCEDURE_TYPES_MAP } from '../../../shared/src/business/entities/EntityConstants';
import {
petitionerAttemptsToUploadCorruptPdfUpdated,
petitionerCreatesElectronicCaseForBusinessUpdated,
Expand Down Expand Up @@ -31,8 +32,9 @@ export function petitionerCreatesElectronicCaseWithDeceasedSpouseOld(
cy.get('[data-testid="phone"]').type('1111111111');
cy.get('[data-testid="use-same-address-above-label"]').click();
cy.get('[data-testid="complete-step-3"]').click();
cy.get('[data-testid="procedure-type-1"]').click();
cy.get('[data-testid="procedure-type-0"]').click();
cy.get(
`[data-testid="procedure-type-${PROCEDURE_TYPES_MAP.regular}-radio"]`,
).click();
cy.get('[data-testid="preferred-trial-city"]').select('Mobile, Alabama');
cy.get('[data-testid="complete-step-4"]').click();
cy.get('[data-testid="file-petition"]').click();
Expand Down Expand Up @@ -111,8 +113,9 @@ export function petitionerCreatesElectronicCaseWithSpouseOld(
cy.get('[data-testid="phone"]').type('1111111111');
cy.get('[data-testid="use-same-address-above-label"]').click();
cy.get('[data-testid="complete-step-3"]').click();
cy.get('[data-testid="procedure-type-1"]').click();
cy.get('[data-testid="procedure-type-0"]').click();
cy.get(
`[data-testid="procedure-type-${PROCEDURE_TYPES_MAP.regular}-radio"]`,
).click();
cy.get('[data-testid="preferred-trial-city"]').select('Mobile, Alabama');
cy.get('[data-testid="complete-step-4"]').click();
cy.get('[data-testid="file-petition"]').click();
Expand Down Expand Up @@ -160,8 +163,9 @@ function petitionerCreatesElectronicCaseOld(primaryFilerName = 'John') {
cy.get('[data-testid="phone"]').type('1111111111');

cy.get('[data-testid="complete-step-3"]').click();
cy.get('[data-testid="procedure-type-1"]').click();
cy.get('[data-testid="procedure-type-0"]').click();
cy.get(
`[data-testid="procedure-type-${PROCEDURE_TYPES_MAP.regular}-radio"]`,
).click();
cy.get('[data-testid="preferred-trial-city"]').select('Mobile, Alabama');
cy.get('[data-testid="complete-step-4"]').click();

Expand Down Expand Up @@ -204,8 +208,9 @@ export function petitionerCreatesElectronicCaseForBusinessOld() {
uploadFile('corporate-disclosure-file');

cy.get('[data-testid="complete-step-3"]').click();
cy.get('[data-testid="procedure-type-1"]').click();
cy.get('[data-testid="procedure-type-0"]').click();
cy.get(
`[data-testid="procedure-type-${PROCEDURE_TYPES_MAP.regular}-radio"]`,
).click();
cy.get('[data-testid="preferred-trial-city"]').select('Mobile, Alabama');
cy.get('[data-testid="complete-step-4"]').click();

Expand Down Expand Up @@ -259,8 +264,9 @@ export function privatePractitionerCreatesElectronicCaseForBusiness() {
uploadFile('corporate-disclosure-file');

cy.get('[data-testid="complete-step-3"]').click();
cy.get('[data-testid="procedure-type-1"]').click();
cy.get('[data-testid="procedure-type-0"]').click();
cy.get(
`[data-testid="procedure-type-${PROCEDURE_TYPES_MAP.regular}-radio"]`,
).click();
cy.get('[data-testid="preferred-trial-city"]').select('Mobile, Alabama');
cy.get('[data-testid="complete-step-4"]').click();

Expand Down Expand Up @@ -313,8 +319,9 @@ export function petitionerAttemptsToUploadCorruptPdfOld() {
cy.get('[data-testid="phone"]').type('1111111111');

cy.get('[data-testid="complete-step-3"]').click();
cy.get('[data-testid="procedure-type-1"]').click();
cy.get('[data-testid="procedure-type-0"]').click();
cy.get(
`[data-testid="procedure-type-${PROCEDURE_TYPES_MAP.regular}-radio"]`,
).click();
cy.get('[data-testid="preferred-trial-city"]').select('Mobile, Alabama');
cy.get('[data-testid="complete-step-4"]').click();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { PROCEDURE_TYPES_MAP } from '../../../shared/src/business/entities/EntityConstants';
import { petitionerCreatesElectronicCaseUpdated } from './petitioner-creates-electronic-case-updated';
import { uploadFile } from '../file/upload-file';

export function practitionerCreatesElectronicCase() {
return cy
.task('getFeatureFlagValue', { flag: 'updated-petition-flow' })
.then(updatedFlow => {
if (updatedFlow) {
return petitionerCreatesElectronicCaseUpdated();
}
return practitionerCreatesElectronicCaseOld();
});
}

export function practitionerCreatesElectronicCaseOld() {
cy.get('[data-testid="file-a-petition"]').click();
uploadFile('stin-file');
cy.get('[data-testid="complete-step-1"]').click();
Expand All @@ -20,8 +33,9 @@ export function practitionerCreatesElectronicCase() {
cy.get('[data-testid="phone"]').type('1111111111');
cy.get('[data-testid="use-same-address-above-label"]').click();
cy.get('[data-testid="complete-step-3"]').click();
cy.get('[data-testid="procedure-type-1"]').click();
cy.get('[data-testid="procedure-type-0"]').click();
cy.get(
`[data-testid="procedure-type-${PROCEDURE_TYPES_MAP.regular}-radio"]`,
).click();
cy.get('[data-testid="preferred-trial-city"]').select('Mobile, Alabama');
cy.get('[data-testid="complete-step-4"]').click();
cy.get('[data-testid="file-petition"]').click();
Expand Down
113 changes: 90 additions & 23 deletions cypress/local-only/support/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
/* eslint-disable */
/**
* @param b64Data
* @param contentType
* @param sliceSize
*/
export function b64toBlob(b64Data, contentType, sliceSize) {
contentType = contentType || '';
sliceSize = sliceSize || 512;
const byteCharacters = atob(b64Data);
const byteArrays = [];
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
const slice = byteCharacters.slice(offset, offset + sliceSize);
const byteNumbers = new Array(slice.length);
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
byteArrays.push(new Uint8Array(byteNumbers));
}
const blob = new Blob(byteArrays, { type: contentType });
blob.lastModifiedDate = new Date();
return blob;
}
import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf';
import fs from 'fs';
pdfjsLib.GlobalWorkerOptions.workerSrc = './pdf.worker.js';

export function generateRandomPhoneNumber(): string {
function getRandomNumber(min: number, max: number) {
Expand All @@ -34,3 +14,90 @@ export function generateRandomPhoneNumber(): string {

return phoneNumber;
}

export function downloadAndParsePdf(element: string) {
cy.intercept('GET', '**/document-download-url').as('documentDownloadUrl');

cy.get(element).click();

return cy.wait('@documentDownloadUrl').then(({ response }) => {
if (!response) throw Error('Did not find response');

const { url } = response.body;

return cy
.request({
encoding: 'binary',
url,
})
.then(res => {
const filePath = 'cypress/downloads/file.pdf';

return cy.writeFile(filePath, res.body, 'binary').then(() => {
return cy
.readFile(filePath, { timeout: 15000 })
.should('exist')
.then(() => {
return cy.task('parsePdf', { filePath });
});
});
});
});
}

export async function parsePdf({
filePath,
}: {
filePath: string;
}): Promise<string> {
try {
const dataBuffer = await fs.promises.readFile(filePath);

const pdfDocument = await pdfjsLib.getDocument({ data: dataBuffer })
.promise;

const pdfText = await extractPdfText(pdfDocument);
return pdfText;
} catch (error) {
throw new Error('Failed to parse PDF');
}
}

async function extractPdfText(pdfDocument: any) {
let fullText = '';

for (let pageNum = 1; pageNum <= pdfDocument.numPages; pageNum++) {
const page = await pdfDocument.getPage(pageNum);
const pageText = await extractPageText(page);
fullText += pageText + '\n';
}

return fullText;
}

async function extractPageText(page: any) {
const textContent = await page.getTextContent();

let lastX: number | null = null;
let lastY: number | null = null;
let pageText = '';

textContent.items.forEach((item: any) => {
// Check if the current text item is on the same line and close to the previous item.
// If not, add a space to separate them.
if (lastX !== null && lastY !== null) {
const sameLine = Math.abs(item.transform[5] - lastY) < 5;
const closeToLastItem = Math.abs(item.transform[4] - lastX) < 5;

if (!sameLine || !closeToLastItem) {
pageText += ' ';
}
}

pageText += item.str;
lastX = item.transform[4] + item.width;
lastY = item.transform[5];
});

return pageText;
}
Loading

0 comments on commit 7338a3b

Please sign in to comment.