diff --git a/shared/jest-shared.config.ts b/shared/jest-shared.config.ts index 35e2e05c5a7..c6cc22d750b 100644 --- a/shared/jest-shared.config.ts +++ b/shared/jest-shared.config.ts @@ -20,7 +20,7 @@ const config: Config = { '!src/persistence/sqs/getMessages.ts', '!src/persistence/messages/*.ts', '!src/persistence/dynamo/**/*.ts', - '!src/business/utilities/documentGenerators/*.ts', + '!src/business/utilities/documentGenerators/**/*.ts', ], coverageDirectory: './coverage', coverageProvider: 'babel', diff --git a/shared/src/business/entities/ReconciliationReportEntry.ts b/shared/src/business/entities/ReconciliationReportEntry.ts index 01d270f6edc..ea877e6d622 100644 --- a/shared/src/business/entities/ReconciliationReportEntry.ts +++ b/shared/src/business/entities/ReconciliationReportEntry.ts @@ -2,12 +2,6 @@ import { DOCKET_ENTRY_VALIDATION_RULES } from './EntityValidationConstants'; import { JoiValidationEntity } from './JoiValidationEntity'; import { pick } from 'lodash'; -/** - * constructor - * - * @param {object} rawDocketEntry the raw docket entry data - * @constructor - */ export class ReconciliationReportEntry extends JoiValidationEntity { public caseCaption: string; public docketEntryId: string; @@ -23,6 +17,7 @@ export class ReconciliationReportEntry extends JoiValidationEntity { constructor(rawDocketEntry) { super('ReconciliationReportEntry'); + this.caseCaption = rawDocketEntry.caseCaption; this.docketEntryId = rawDocketEntry.docketEntryId; this.docketNumber = rawDocketEntry.docketNumber; @@ -56,3 +51,6 @@ export class ReconciliationReportEntry extends JoiValidationEntity { return {}; } } + +export type RawReconciliationReportEntry = + ExcludeMethods; diff --git a/shared/src/business/entities/cases/PublicCase.test.ts b/shared/src/business/entities/cases/PublicCase.test.ts index 8e34bf3f45e..6cdc0256886 100644 --- a/shared/src/business/entities/cases/PublicCase.test.ts +++ b/shared/src/business/entities/cases/PublicCase.test.ts @@ -15,9 +15,14 @@ import { PublicCase } from './PublicCase'; import { applicationContext } from '../../test/createTestApplicationContext'; import { getContactSecondary } from './Case'; -const mockContactId = 'b430f7f9-06f3-4a25-915d-5f51adab2f29'; -const mockContactIdSecond = '39a359e9-dde3-409e-b40e-77a4959b6f2c'; describe('PublicCase', () => { + const mockContactId = 'b430f7f9-06f3-4a25-915d-5f51adab2f29'; + const mockContactIdSecond = '39a359e9-dde3-409e-b40e-77a4959b6f2c'; + + it('should throw an error when applicationContext is not provided to the constructor', () => { + expect(() => new PublicCase({}, {} as any)).toThrow(TypeError); + }); + describe('validation', () => { it('should validate when all information is provided and case is not sealed', () => { const entity = new PublicCase( @@ -337,7 +342,6 @@ describe('PublicCase', () => { const entity = new PublicCase(rawCase, { applicationContext }); expect(entity.irsPractitioners).toBeUndefined(); - expect(entity.otherFilers).toBeUndefined(); expect(entity.privatePractitioners).toBeUndefined(); expect(entity.leadDocketNumber).toBeUndefined(); }); @@ -545,7 +549,6 @@ describe('PublicCase', () => { const entity = new PublicCase(rawCase, { applicationContext }); expect(entity.irsPractitioners).toBeUndefined(); - expect(entity.otherFilers).toBeUndefined(); expect(entity.privatePractitioners).toBeUndefined(); }); }); @@ -586,7 +589,6 @@ describe('PublicCase', () => { const entity = new PublicCase(rawCase, { applicationContext }); expect(entity.irsPractitioners).toBeDefined(); - expect(entity.otherFilers).toBeUndefined(); expect(entity.privatePractitioners).toBeDefined(); expect(entity.leadDocketNumber).toBeDefined(); }); diff --git a/shared/src/business/entities/cases/PublicCase.ts b/shared/src/business/entities/cases/PublicCase.ts index 8adc2d181f2..79e569e2941 100644 --- a/shared/src/business/entities/cases/PublicCase.ts +++ b/shared/src/business/entities/cases/PublicCase.ts @@ -38,6 +38,7 @@ export class PublicCase extends JoiValidationEntity { public petitioners: any[] | undefined; public irsPractitioners?: any[]; public privatePractitioners: any; + private _score?: string; constructor( @@ -53,6 +54,7 @@ export class PublicCase extends JoiValidationEntity { if (!applicationContext) { throw new TypeError('applicationContext must be defined'); } + this.entityName = 'PublicCase'; this.canAllowDocumentService = rawCase.canAllowDocumentService; this.canAllowPrintableDocketRecord = rawCase.canAllowPrintableDocketRecord; diff --git a/shared/src/business/entities/docketEntry/DocketEntryFactory.ts b/shared/src/business/entities/docketEntry/DocketEntryFactory.ts index 912cfa82039..30d13445ece 100644 --- a/shared/src/business/entities/docketEntry/DocketEntryFactory.ts +++ b/shared/src/business/entities/docketEntry/DocketEntryFactory.ts @@ -184,7 +184,10 @@ function DocketEntryFactory(rawProps) { }; const exDoc = ExternalDocumentFactory(rawProps); - const docketEntryExternalDocumentSchema = exDoc.getSchema(); + const rules = exDoc.getValidationRules(); + const docketEntryExternalDocumentSchema = rules.validate + ? rules + : joi.object().keys(rules); schema = schema.concat(docketEntryExternalDocumentSchema).concat( joi.object({ diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentBase.ts b/shared/src/business/entities/externalDocument/ExternalDocumentBase.ts index 0e8eb79ceaf..80b7553dfc2 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentBase.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentBase.ts @@ -1,16 +1,138 @@ -const { JoiValidationConstants } = require('../JoiValidationConstants'); - -const externalDocumentDecorator = (obj, rawObj) => { - obj.category = rawObj.category; - obj.documentTitle = rawObj.documentTitle; - obj.documentType = rawObj.documentType; -}; - -const baseExternalDocumentValidation = { - category: JoiValidationConstants.STRING.required(), - documentTitle: JoiValidationConstants.DOCUMENT_TITLE.optional(), - documentType: JoiValidationConstants.STRING.required(), -}; - -exports.externalDocumentDecorator = externalDocumentDecorator; -exports.baseExternalDocumentValidation = baseExternalDocumentValidation; +import { JoiValidationConstants } from '../JoiValidationConstants'; +import { JoiValidationEntity } from '../JoiValidationEntity'; +import { MAX_FILE_SIZE_MB } from '../EntityConstants'; + +export class ExternalDocumentBase extends JoiValidationEntity { + public category: string; + public documentTitle?: string; + public documentType: string; + + constructor(rawProps, scenario: string) { + super(scenario); + + this.category = rawProps.category; + this.documentTitle = rawProps.documentTitle; + this.documentType = rawProps.documentType; + } + + static VALIDATION_RULES = { + category: JoiValidationConstants.STRING.required(), + documentTitle: JoiValidationConstants.DOCUMENT_TITLE.optional(), + documentType: JoiValidationConstants.STRING.required(), + }; + + static VALIDATION_ERROR_MESSAGES = { + additionalInfo: [ + { + contains: 'must be less than or equal to', + message: 'Limit is 500 characters. Enter 500 or fewer characters.', + }, + ], + additionalInfo2: [ + { + contains: 'must be less than or equal to', + message: 'Limit is 500 characters. Enter 500 or fewer characters.', + }, + ], + attachments: 'Enter selection for Attachments.', + category: 'Select a Category.', + certificateOfService: + 'Indicate whether you are including a Certificate of Service', + certificateOfServiceDate: [ + { + contains: 'must be less than or equal to', + message: + 'Certificate of Service date cannot be in the future. Enter a valid date.', + }, + 'Enter date of service', + ], + documentTitle: + 'Document title must be 3000 characters or fewer. Update this document title and try again.', + documentType: [ + { + contains: 'contains an invalid value', + message: + 'Proposed Stipulated Decision must be filed separately in each case', + }, + 'Select a document type', + ], + filers: 'Select a filing party', + freeText: [ + { contains: 'is required', message: 'Provide an answer' }, + { + contains: 'must be less than or equal to', + message: 'Limit is 1000 characters. Enter 1000 or fewer characters.', + }, + ], + freeText2: [ + { contains: 'is required', message: 'Provide an answer' }, + { + contains: 'must be less than or equal to', + message: 'Limit is 1000 characters. Enter 1000 or fewer characters.', + }, + ], + hasSecondarySupportingDocuments: + 'Enter selection for Secondary Supporting Documents.', + hasSupportingDocuments: 'Enter selection for Supporting Documents.', + objections: 'Enter selection for Objections.', + ordinalValue: 'Select an iteration', + otherIteration: [ + { + contains: 'is required', + message: 'Enter an iteration number.', + }, + 'Maximum iteration value is 999.', + ], + partyIrsPractitioner: 'Select a filing party', + previousDocument: 'Select a document', + primaryDocumentFile: 'Upload a document', + primaryDocumentFileSize: [ + { + contains: 'must be less than or equal to', + message: `Your Primary Document file size is too big. The maximum file size is ${MAX_FILE_SIZE_MB}MB.`, + }, + 'Your Primary Document file size is empty.', + ], + secondaryDocument: 'Select a document', + secondaryDocumentFile: 'Upload a document', + secondaryDocumentFileSize: [ + { + contains: 'must be less than or equal to', + message: `Your Secondary Document file size is too big. The maximum file size is ${MAX_FILE_SIZE_MB}MB.`, + }, + 'Your Secondary Document file size is empty.', + ], + serviceDate: [ + { + contains: 'must be less than or equal to', + message: 'Service date cannot be in the future. Enter a valid date.', + }, + 'Provide a service date', + ], + supportingDocument: 'Select a document type', + supportingDocumentFile: 'Upload a document', + supportingDocumentFileSize: [ + { + contains: 'must be less than or equal to', + message: `Your Supporting Document file size is too big. The maximum file size is ${MAX_FILE_SIZE_MB}MB.`, + }, + 'Your Supporting Document file size is empty.', + ], + supportingDocumentFreeText: 'Enter name', + trialLocation: 'Select a preferred trial location.', + } as const; + + getValidationRules() { + return ExternalDocumentBase.VALIDATION_RULES; + } + + getErrorToMessageMap(): any { + return ExternalDocumentBase.VALIDATION_ERROR_MESSAGES; + } + + getDocumentTitle() { + return this.documentTitle!; + } +} + +export type RawExternalDocumentBase = ExcludeMethods; diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentFactory.ts b/shared/src/business/entities/externalDocument/ExternalDocumentFactory.ts index c95ea8fbe47..fb519ec70e2 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentFactory.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentFactory.ts @@ -1,44 +1,22 @@ -const { - ExternalDocumentNonStandardA, -} = require('./ExternalDocumentNonStandardA'); -const { - ExternalDocumentNonStandardB, -} = require('./ExternalDocumentNonStandardB'); -const { - ExternalDocumentNonStandardC, -} = require('./ExternalDocumentNonStandardC'); -const { - ExternalDocumentNonStandardD, -} = require('./ExternalDocumentNonStandardD'); -const { - ExternalDocumentNonStandardE, -} = require('./ExternalDocumentNonStandardE'); -const { - ExternalDocumentNonStandardF, -} = require('./ExternalDocumentNonStandardF'); -const { - ExternalDocumentNonStandardG, -} = require('./ExternalDocumentNonStandardG'); -const { - ExternalDocumentNonStandardH, -} = require('./ExternalDocumentNonStandardH'); -const { - ExternalDocumentNonStandardI, -} = require('./ExternalDocumentNonStandardI'); -const { - ExternalDocumentNonStandardJ, -} = require('./ExternalDocumentNonStandardJ'); -const { ExternalDocumentStandard } = require('./ExternalDocumentStandard'); +import { ExternalDocumentBase } from './ExternalDocumentBase'; +import { ExternalDocumentNonStandardA } from './ExternalDocumentNonStandardA'; +import { ExternalDocumentNonStandardB } from './ExternalDocumentNonStandardB'; +import { ExternalDocumentNonStandardC } from './ExternalDocumentNonStandardC'; +import { ExternalDocumentNonStandardD } from './ExternalDocumentNonStandardD'; +import { ExternalDocumentNonStandardE } from './ExternalDocumentNonStandardE'; +import { ExternalDocumentNonStandardF } from './ExternalDocumentNonStandardF'; +import { ExternalDocumentNonStandardG } from './ExternalDocumentNonStandardG'; +import { ExternalDocumentNonStandardH } from './ExternalDocumentNonStandardH'; +import { ExternalDocumentNonStandardI } from './ExternalDocumentNonStandardI'; +import { ExternalDocumentNonStandardJ } from './ExternalDocumentNonStandardJ'; +import { ExternalDocumentStandard } from './ExternalDocumentStandard'; -/** - * External Document Factory entity - * - * @param {object} documentMetadata the document metadata - * @constructor - */ -function ExternalDocumentFactory(documentMetadata) { +export function ExternalDocumentFactory( + documentMetadata, +): ExternalDocumentBase { if (documentMetadata && documentMetadata.scenario) { const scenario = documentMetadata.scenario.toLowerCase().trim(); + switch (scenario) { case 'nonstandard a': return new ExternalDocumentNonStandardA(documentMetadata); @@ -55,10 +33,7 @@ function ExternalDocumentFactory(documentMetadata) { case 'nonstandard g': return new ExternalDocumentNonStandardG(documentMetadata); case 'nonstandard h': - return new ExternalDocumentNonStandardH( - documentMetadata, - ExternalDocumentFactory, - ); + return new ExternalDocumentNonStandardH(documentMetadata); case 'nonstandard i': return new ExternalDocumentNonStandardI(documentMetadata); case 'nonstandard j': @@ -66,8 +41,5 @@ function ExternalDocumentFactory(documentMetadata) { } } - // standard - default return new ExternalDocumentStandard(documentMetadata); } - -module.exports = { ExternalDocumentFactory }; diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentInformationFactory.test.ts b/shared/src/business/entities/externalDocument/ExternalDocumentInformationFactory.test.ts index a0978a584b7..e7bb60b1d9d 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentInformationFactory.test.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentInformationFactory.test.ts @@ -1,12 +1,12 @@ -const { - calculateISODate, - createISODateString, -} = require('../../utilities/DateHandler'); -const { +import { ExternalDocumentInformationFactory, VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { OBJECTIONS_OPTIONS_MAP } = require('../EntityConstants'); +} from './ExternalDocumentInformationFactory'; +import { OBJECTIONS_OPTIONS_MAP } from '../EntityConstants'; +import { + calculateISODate, + createISODateString, +} from '../../utilities/DateHandler'; describe('ExternalDocumentInformationFactory', () => { let baseDoc; diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardA.test.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardA.test.ts index 930d46dc327..7808cf32dd8 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardA.test.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardA.test.ts @@ -1,61 +1,71 @@ -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { ExternalDocumentFactory } = require('./ExternalDocumentFactory'); -const { getTextByCount } = require('../../utilities/getTextByCount'); +import { ExternalDocumentFactory } from './ExternalDocumentFactory'; +import { ExternalDocumentNonStandardA } from './ExternalDocumentNonStandardA'; +import { getTextByCount } from '../../utilities/getTextByCount'; describe('ExternalDocumentNonStandardA', () => { describe('validation', () => { it('should have error messages for missing fields', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentA = ExternalDocumentFactory({ scenario: 'Nonstandard A', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - category: VALIDATION_ERROR_MESSAGES.category, - documentType: VALIDATION_ERROR_MESSAGES.documentType[1], - previousDocument: VALIDATION_ERROR_MESSAGES.previousDocument, + + expect(externalDocumentA.getFormattedValidationErrors()).toEqual({ + category: + ExternalDocumentNonStandardA.VALIDATION_ERROR_MESSAGES.category, + documentType: + ExternalDocumentNonStandardA.VALIDATION_ERROR_MESSAGES + .documentType[1], + previousDocument: + ExternalDocumentNonStandardA.VALIDATION_ERROR_MESSAGES + .previousDocument, }); }); it('should be valid when all fields are present', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentA = ExternalDocumentFactory({ category: 'Supporting Document', documentTitle: 'Brief in Support of [Document Name]', documentType: 'Brief in Support', previousDocument: { documentType: 'Petition' }, scenario: 'Nonstandard A', }); - expect(extDoc.getFormattedValidationErrors()).toEqual(null); + + expect(externalDocumentA.getFormattedValidationErrors()).toEqual(null); }); it('should be invalid when documentTitle is over 3000 characters', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentA = ExternalDocumentFactory({ category: 'Supporting Document', documentTitle: getTextByCount(3001), documentType: 'Brief in Support', previousDocument: { documentType: 'Petition' }, scenario: 'Nonstandard A', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - documentTitle: VALIDATION_ERROR_MESSAGES.documentTitle, + + expect(externalDocumentA.getFormattedValidationErrors()).toEqual({ + documentTitle: + ExternalDocumentNonStandardA.VALIDATION_ERROR_MESSAGES.documentTitle, }); }); }); describe('title generation', () => { it('should generate valid title with previousDocument documentType', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentA = ExternalDocumentFactory({ category: 'Supporting Document', documentTitle: 'Brief in Support of [Document Name]', documentType: 'Brief in Support', previousDocument: { documentType: 'Petition' }, scenario: 'Nonstandard A', }); - expect(extDoc.getDocumentTitle()).toEqual('Brief in Support of Petition'); + + expect(externalDocumentA.getDocumentTitle()).toEqual( + 'Brief in Support of Petition', + ); }); it('should generate valid title with previousDocument documentTitle', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentA = ExternalDocumentFactory({ category: 'Supporting Document', documentTitle: 'Brief in Support of [Document Name]', documentType: 'Brief in Support', @@ -65,19 +75,23 @@ describe('ExternalDocumentNonStandardA', () => { }, scenario: 'Nonstandard A', }); - expect(extDoc.getDocumentTitle()).toEqual( + + expect(externalDocumentA.getDocumentTitle()).toEqual( 'Brief in Support of Stipulation Something', ); }); it('should generate title without previousDocument', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentA = ExternalDocumentFactory({ category: 'Supporting Document', documentTitle: 'Brief in Support of [Document Name]', documentType: 'Brief in Support', scenario: 'Nonstandard A', }); - expect(extDoc.getDocumentTitle()).toEqual('Brief in Support of'); + + expect(externalDocumentA.getDocumentTitle()).toEqual( + 'Brief in Support of', + ); }); }); }); diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardA.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardA.ts index 88de632a3f3..8b68ef46c2f 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardA.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardA.ts @@ -1,61 +1,42 @@ -const joi = require('joi'); -const { - baseExternalDocumentValidation, - externalDocumentDecorator, -} = require('./ExternalDocumentBase'); -const { - joiValidationDecorator, - validEntityDecorator, -} = require('../JoiValidationDecorator'); -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { JoiValidationConstants } = require('../JoiValidationConstants'); -const { replaceBracketed } = require('../../utilities/replaceBracketed'); +import { ExternalDocumentBase } from './ExternalDocumentBase'; +import { JoiValidationConstants } from '../JoiValidationConstants'; +import { replaceBracketed } from '../../utilities/replaceBracketed'; +import joi from 'joi'; -/** - * - * @param {object} rawProps the raw document data - * @constructor - */ -function ExternalDocumentNonStandardA() {} +export class ExternalDocumentNonStandardA extends ExternalDocumentBase { + public previousDocument: { documentTitle?: string; documentType: string }; -ExternalDocumentNonStandardA.prototype.init = function init(rawProps) { - externalDocumentDecorator(this, rawProps); - this.previousDocument = rawProps.previousDocument; -}; + constructor(rawProps) { + super(rawProps, 'ExternalDocumentNonStandardA'); -ExternalDocumentNonStandardA.prototype.getDocumentTitle = function () { - return replaceBracketed( - this.documentTitle, - this.previousDocument - ? this.previousDocument.documentTitle || - this.previousDocument.documentType - : '', - ); -}; + this.previousDocument = rawProps.previousDocument; + } -ExternalDocumentNonStandardA.VALIDATION_ERROR_MESSAGES = { - ...VALIDATION_ERROR_MESSAGES, -}; + static VALIDATION_RULES = { + ...ExternalDocumentBase.VALIDATION_RULES, + previousDocument: joi + .object() + .keys({ + documentTitle: JoiValidationConstants.STRING.optional(), + documentType: JoiValidationConstants.STRING.required(), + }) + .required(), + }; -ExternalDocumentNonStandardA.schema = { - ...baseExternalDocumentValidation, - previousDocument: joi - .object() - .keys({ - documentTitle: JoiValidationConstants.STRING.optional(), - documentType: JoiValidationConstants.STRING.required(), - }) - .required(), -}; + getValidationRules() { + return ExternalDocumentNonStandardA.VALIDATION_RULES; + } -joiValidationDecorator( - ExternalDocumentNonStandardA, - ExternalDocumentNonStandardA.schema, - ExternalDocumentNonStandardA.VALIDATION_ERROR_MESSAGES, -); + getDocumentTitle(): string { + return replaceBracketed( + this.documentTitle, + this.previousDocument + ? this.previousDocument.documentTitle || + this.previousDocument.documentType + : '', + ); + } +} -exports.ExternalDocumentNonStandardA = validEntityDecorator( - ExternalDocumentNonStandardA, -); +export type RawExternalDocumentNonStandardA = + ExcludeMethods; diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardB.test.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardB.test.ts index 36ecef1dce0..a607d80b5e6 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardB.test.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardB.test.ts @@ -1,70 +1,81 @@ -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { ExternalDocumentFactory } = require('./ExternalDocumentFactory'); -const { getTextByCount } = require('../../utilities/getTextByCount'); +import { ExternalDocumentFactory } from './ExternalDocumentFactory'; +import { ExternalDocumentNonStandardB } from './ExternalDocumentNonStandardB'; +import { getTextByCount } from '../../utilities/getTextByCount'; describe('ExternalDocumentNonStandardB', () => { describe('validation', () => { it('should have error messages for missing fields', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentB = ExternalDocumentFactory({ scenario: 'Nonstandard B', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - category: VALIDATION_ERROR_MESSAGES.category, - documentType: VALIDATION_ERROR_MESSAGES.documentType[1], - freeText: VALIDATION_ERROR_MESSAGES.freeText[0].message, + + expect(externalDocumentB.getFormattedValidationErrors()).toEqual({ + category: + ExternalDocumentNonStandardB.VALIDATION_ERROR_MESSAGES.category, + documentType: + ExternalDocumentNonStandardB.VALIDATION_ERROR_MESSAGES + .documentType[1], + freeText: + ExternalDocumentNonStandardB.VALIDATION_ERROR_MESSAGES.freeText[0] + .message, }); }); it('should be valid when all fields are present', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentB = ExternalDocumentFactory({ category: 'Application', documentTitle: 'Application to Take Deposition of [Name]', documentType: 'Application to Take Deposition', freeText: 'Petition', scenario: 'Nonstandard B', }); - expect(extDoc.getFormattedValidationErrors()).toEqual(null); + + expect(externalDocumentB.getFormattedValidationErrors()).toEqual(null); }); it('should be invalid when documentTitle is over 3000 characters', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentB = ExternalDocumentFactory({ category: 'Application', documentTitle: getTextByCount(3001), documentType: 'Application to Take Deposition', freeText: 'Petition', scenario: 'Nonstandard B', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - documentTitle: VALIDATION_ERROR_MESSAGES.documentTitle, + + expect(externalDocumentB.getFormattedValidationErrors()).toEqual({ + documentTitle: + ExternalDocumentNonStandardB.VALIDATION_ERROR_MESSAGES.documentTitle, }); }); }); it('should not validate when freeText is over 1000 characters', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentB = ExternalDocumentFactory({ category: 'Application', documentTitle: 'Application to Take Deposition of [Name]', documentType: 'Application to Take Deposition', freeText: getTextByCount(1001), scenario: 'Nonstandard B', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - freeText: VALIDATION_ERROR_MESSAGES.freeText[1].message, + + expect(externalDocumentB.getFormattedValidationErrors()).toEqual({ + freeText: + ExternalDocumentNonStandardB.VALIDATION_ERROR_MESSAGES.freeText[1] + .message, }); }); describe('title generation', () => { it('should generate valid title', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentB = ExternalDocumentFactory({ category: 'Application', documentTitle: 'Application to Take Deposition of [Name]', documentType: 'Application to Take Deposition', freeText: 'Petition', scenario: 'Nonstandard B', }); - expect(extDoc.getDocumentTitle()).toEqual( + + expect(externalDocumentB.getDocumentTitle()).toEqual( 'Application to Take Deposition of Petition', ); }); diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardB.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardB.ts index 23a911ce727..96f00c92c7c 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardB.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardB.ts @@ -1,50 +1,29 @@ -const { - baseExternalDocumentValidation, - externalDocumentDecorator, -} = require('./ExternalDocumentBase'); -const { - joiValidationDecorator, - validEntityDecorator, -} = require('../JoiValidationDecorator'); -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { JoiValidationConstants } = require('../JoiValidationConstants'); -const { replaceBracketed } = require('../../utilities/replaceBracketed'); +import { ExternalDocumentBase } from './ExternalDocumentBase'; +import { JoiValidationConstants } from '../JoiValidationConstants'; +import { replaceBracketed } from '../../utilities/replaceBracketed'; -/** - * - * @param {object} rawProps the raw document data - * @constructor - */ -function ExternalDocumentNonStandardB() {} +export class ExternalDocumentNonStandardB extends ExternalDocumentBase { + public freeText: string; -ExternalDocumentNonStandardB.prototype.init = function init(rawProps) { - externalDocumentDecorator(this, rawProps); - this.freeText = rawProps.freeText; -}; + constructor(rawProps) { + super(rawProps, 'ExternalDocumentNonStandardB'); -ExternalDocumentNonStandardB.prototype.getDocumentTitle = function () { - return replaceBracketed(this.documentTitle, this.freeText); -}; + this.freeText = rawProps.freeText; + } -ExternalDocumentNonStandardB.VALIDATION_ERROR_MESSAGES = { - ...VALIDATION_ERROR_MESSAGES, -}; + static VALIDATION_RULES = { + ...ExternalDocumentBase.VALIDATION_RULES, + freeText: JoiValidationConstants.STRING.max(1000).required(), + }; -ExternalDocumentNonStandardB.schema = { - ...baseExternalDocumentValidation, - freeText: JoiValidationConstants.STRING.max(1000).required(), -}; + getValidationRules() { + return ExternalDocumentNonStandardB.VALIDATION_RULES; + } -joiValidationDecorator( - ExternalDocumentNonStandardB, - ExternalDocumentNonStandardB.schema, - ExternalDocumentNonStandardB.VALIDATION_ERROR_MESSAGES, -); + getDocumentTitle(): string { + return replaceBracketed(this.documentTitle, this.freeText); + } +} -module.exports = { - ExternalDocumentNonStandardB: validEntityDecorator( - ExternalDocumentNonStandardB, - ), -}; +export type RawExternalDocumentNonStandardB = + ExcludeMethods; diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardC.test.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardC.test.ts index e417d3d7151..063a340de7b 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardC.test.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardC.test.ts @@ -1,27 +1,24 @@ -const { - ExternalDocumentNonStandardC, -} = require('./ExternalDocumentNonStandardC'); -const { ExternalDocumentFactory } = require('./ExternalDocumentFactory'); -const { getTextByCount } = require('../../utilities/getTextByCount'); - -const { VALIDATION_ERROR_MESSAGES } = ExternalDocumentNonStandardC; +import { ExternalDocumentFactory } from './ExternalDocumentFactory'; +import { getTextByCount } from '../../utilities/getTextByCount'; describe('ExternalDocumentNonStandardC', () => { describe('validation', () => { it('should have error messages for missing fields', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentC = ExternalDocumentFactory({ scenario: 'Nonstandard C', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - category: VALIDATION_ERROR_MESSAGES.category, - documentType: VALIDATION_ERROR_MESSAGES.documentType[1], - freeText: VALIDATION_ERROR_MESSAGES.freeText[0].message, - previousDocument: VALIDATION_ERROR_MESSAGES.previousDocument, + + expect(externalDocumentC.getFormattedValidationErrors()).toEqual({ + category: externalDocumentC.getErrorToMessageMap().category, + documentType: externalDocumentC.getErrorToMessageMap().documentType[1], + freeText: externalDocumentC.getErrorToMessageMap().freeText[0].message, + previousDocument: + externalDocumentC.getErrorToMessageMap().previousDocument, }); }); it('should be valid when all fields are present', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentC = ExternalDocumentFactory({ category: 'Supporting Document', documentTitle: 'Affidavit Of [Name] in Support Of [Document Name]', documentType: 'Affidavit in Support', @@ -29,11 +26,12 @@ describe('ExternalDocumentNonStandardC', () => { previousDocument: { documentType: 'Petition' }, scenario: 'Nonstandard C', }); - expect(extDoc.getFormattedValidationErrors()).toEqual(null); + + expect(externalDocumentC.getFormattedValidationErrors()).toEqual(null); }); it('should be invalid when freeText is over 1000 characters', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentC = ExternalDocumentFactory({ category: 'Supporting Document', documentTitle: 'Affidavit Of [Name] in Support Of [Document Name]', documentType: 'Affidavit in Support', @@ -41,15 +39,14 @@ describe('ExternalDocumentNonStandardC', () => { previousDocument: { documentType: 'Petition' }, scenario: 'Nonstandard C', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - freeText: - ExternalDocumentNonStandardC.VALIDATION_ERROR_MESSAGES.freeText[1] - .message, + + expect(externalDocumentC.getFormattedValidationErrors()).toEqual({ + freeText: externalDocumentC.getErrorToMessageMap().freeText[1].message, }); }); it('should be invalid when documentTitle is over 3000 characters', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentC = ExternalDocumentFactory({ category: 'Supporting Document', documentTitle: getTextByCount(3001), documentType: 'Affidavit in Support', @@ -57,15 +54,16 @@ describe('ExternalDocumentNonStandardC', () => { previousDocument: { documentType: 'Petition' }, scenario: 'Nonstandard C', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - documentTitle: VALIDATION_ERROR_MESSAGES.documentTitle, + + expect(externalDocumentC.getFormattedValidationErrors()).toEqual({ + documentTitle: externalDocumentC.getErrorToMessageMap().documentTitle, }); }); }); describe('title generation', () => { it('should generate valid title with previousDocument documentType', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentC = ExternalDocumentFactory({ category: 'Supporting Document', documentTitle: 'Affidavit Of [Name] in Support Of [Document Name]', documentType: 'Affidavit in Support', @@ -73,13 +71,14 @@ describe('ExternalDocumentNonStandardC', () => { previousDocument: { documentType: 'Petition' }, scenario: 'Nonstandard C', }); - expect(extDoc.getDocumentTitle()).toEqual( + + expect(externalDocumentC.getDocumentTitle()).toEqual( 'Affidavit Of Lori Loughlin in Support Of Petition', ); }); it('should generate valid title with previousDocument documentTitle', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentC = ExternalDocumentFactory({ category: 'Supporting Document', documentTitle: 'Affidavit Of [Name] in Support Of [Document Name]', documentType: 'Affidavit in Support', @@ -90,20 +89,22 @@ describe('ExternalDocumentNonStandardC', () => { }, scenario: 'Nonstandard C', }); - expect(extDoc.getDocumentTitle()).toEqual( + + expect(externalDocumentC.getDocumentTitle()).toEqual( 'Affidavit Of Lori Loughlin in Support Of Stipulation Something', ); }); it('should generate title without previousDocument', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentC = ExternalDocumentFactory({ category: 'Supporting Document', documentTitle: 'Affidavit Of [Name] in Support Of [Document Name]', documentType: 'Affidavit in Support', freeText: 'Lori Loughlin', scenario: 'Nonstandard C', }); - expect(extDoc.getDocumentTitle()).toEqual( + + expect(externalDocumentC.getDocumentTitle()).toEqual( 'Affidavit Of Lori Loughlin in Support Of', ); }); diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardC.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardC.ts index 48441fedb53..759bad20654 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardC.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardC.ts @@ -1,73 +1,59 @@ -const joi = require('joi'); -const { - baseExternalDocumentValidation, - externalDocumentDecorator, -} = require('./ExternalDocumentBase'); -const { - joiValidationDecorator, - validEntityDecorator, -} = require('../JoiValidationDecorator'); -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { JoiValidationConstants } = require('../JoiValidationConstants'); -const { replaceBracketed } = require('../../utilities/replaceBracketed'); +import { ExternalDocumentBase } from './ExternalDocumentBase'; +import { JoiValidationConstants } from '../JoiValidationConstants'; +import { replaceBracketed } from '../../utilities/replaceBracketed'; +import joi from 'joi'; -/** - * - * @param {object} rawProps the raw document data - * @constructor - */ -function ExternalDocumentNonStandardC() {} +export class ExternalDocumentNonStandardC extends ExternalDocumentBase { + public freeText: string; + public previousDocument: { documentTitle?: string; documentType: string }; -ExternalDocumentNonStandardC.prototype.init = function init(rawProps) { - externalDocumentDecorator(this, rawProps); - this.freeText = rawProps.freeText; - this.previousDocument = rawProps.previousDocument; -}; + constructor(rawProps) { + super(rawProps, 'ExternalDocumentNonStandardC'); -ExternalDocumentNonStandardC.prototype.getDocumentTitle = function () { - return replaceBracketed( - this.documentTitle, - this.freeText, - this.previousDocument - ? this.previousDocument.documentTitle || - this.previousDocument.documentType - : '', - ); -}; + this.freeText = rawProps.freeText; + this.previousDocument = rawProps.previousDocument; + } -ExternalDocumentNonStandardC.VALIDATION_ERROR_MESSAGES = { - ...VALIDATION_ERROR_MESSAGES, - freeText: [ - { contains: 'is required', message: 'Enter name' }, - { - contains: 'must be less than or equal to', - message: 'Limit is 1000 characters. Enter 1000 or fewer characters.', - }, - ], -}; + static VALIDATION_RULES = { + ...ExternalDocumentBase.VALIDATION_RULES, + freeText: JoiValidationConstants.STRING.max(1000).required(), + previousDocument: joi + .object() + .keys({ + documentTitle: JoiValidationConstants.STRING.optional(), + documentType: JoiValidationConstants.STRING.required(), + }) + .required(), + }; -ExternalDocumentNonStandardC.schema = { - ...baseExternalDocumentValidation, - freeText: JoiValidationConstants.STRING.max(1000).required(), - previousDocument: joi - .object() - .keys({ - documentTitle: JoiValidationConstants.STRING.optional(), - documentType: JoiValidationConstants.STRING.required(), - }) - .required(), -}; + getValidationRules() { + return ExternalDocumentNonStandardC.VALIDATION_RULES; + } -joiValidationDecorator( - validEntityDecorator(ExternalDocumentNonStandardC), - ExternalDocumentNonStandardC.schema, - ExternalDocumentNonStandardC.VALIDATION_ERROR_MESSAGES, -); + getErrorToMessageMap() { + return { + ...ExternalDocumentBase.VALIDATION_ERROR_MESSAGES, + freeText: [ + { contains: 'is required', message: 'Enter name' }, + { + contains: 'must be less than or equal to', + message: 'Limit is 1000 characters. Enter 1000 or fewer characters.', + }, + ], + }; + } -module.exports = { - ExternalDocumentNonStandardC: validEntityDecorator( - ExternalDocumentNonStandardC, - ), -}; + getDocumentTitle(): string { + return replaceBracketed( + this.documentTitle, + this.freeText, + this.previousDocument + ? this.previousDocument.documentTitle || + this.previousDocument.documentType + : '', + ); + } +} + +export type RawExternalDocumentNonStandardC = + ExcludeMethods; diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardD.test.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardD.test.ts index 1cd1da9d7bd..e8df2f233d4 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardD.test.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardD.test.ts @@ -1,30 +1,36 @@ -const { +import { ExternalDocumentFactory } from './ExternalDocumentFactory'; +import { ExternalDocumentNonStandardD } from './ExternalDocumentNonStandardD'; +import { calculateISODate, createISODateString, -} = require('../../utilities/DateHandler'); -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { ExternalDocumentFactory } = require('./ExternalDocumentFactory'); -const { getTextByCount } = require('../../utilities/getTextByCount'); +} from '../../utilities/DateHandler'; +import { getTextByCount } from '../../utilities/getTextByCount'; describe('ExternalDocumentNonStandardD', () => { describe('validation', () => { it('should have error messages for missing fields', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentD = ExternalDocumentFactory({ scenario: 'Nonstandard D', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - category: VALIDATION_ERROR_MESSAGES.category, - documentType: VALIDATION_ERROR_MESSAGES.documentType[1], - previousDocument: VALIDATION_ERROR_MESSAGES.previousDocument, - serviceDate: VALIDATION_ERROR_MESSAGES.serviceDate[1], + + expect(externalDocumentD.getFormattedValidationErrors()).toEqual({ + category: + ExternalDocumentNonStandardD.VALIDATION_ERROR_MESSAGES.category, + documentType: + ExternalDocumentNonStandardD.VALIDATION_ERROR_MESSAGES + .documentType[1], + previousDocument: + ExternalDocumentNonStandardD.VALIDATION_ERROR_MESSAGES + .previousDocument, + serviceDate: + ExternalDocumentNonStandardD.VALIDATION_ERROR_MESSAGES.serviceDate[1], }); }); it('should have error message for future date', () => { const serviceDate = calculateISODate({ howMuch: 1, units: 'days' }); - const extDoc = ExternalDocumentFactory({ + + const externalDocumentD = ExternalDocumentFactory({ category: 'Supporting Document', documentTitle: 'Certificate of Service [Document Name] [Date]', documentType: 'Certificate of Service', @@ -32,14 +38,18 @@ describe('ExternalDocumentNonStandardD', () => { scenario: 'Nonstandard D', serviceDate, }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - serviceDate: VALIDATION_ERROR_MESSAGES.serviceDate[0].message, + + expect(externalDocumentD.getFormattedValidationErrors()).toEqual({ + serviceDate: + ExternalDocumentNonStandardD.VALIDATION_ERROR_MESSAGES.serviceDate[0] + .message, }); }); it('should be valid when all fields are present', () => { const serviceDate = createISODateString(); - const extDoc = ExternalDocumentFactory({ + + const externalDocumentD = ExternalDocumentFactory({ category: 'Supporting Document', documentTitle: 'Certificate of Service [Document Name] [Date]', documentType: 'Certificate of Service', @@ -47,12 +57,14 @@ describe('ExternalDocumentNonStandardD', () => { scenario: 'Nonstandard D', serviceDate, }); - expect(extDoc.getFormattedValidationErrors()).toEqual(null); + + expect(externalDocumentD.getFormattedValidationErrors()).toEqual(null); }); it('should be invalid when serviceDate is undefined-undefined-undefined', () => { const serviceDate = 'undefined-undefined-undefined'; - const extDoc = ExternalDocumentFactory({ + + const externalDocumentD = ExternalDocumentFactory({ category: 'Supporting Document', documentTitle: 'Certificate of Service [Document Name] [Date]', documentType: 'Certificate of Service', @@ -60,14 +72,17 @@ describe('ExternalDocumentNonStandardD', () => { scenario: 'Nonstandard D', serviceDate, }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - serviceDate: VALIDATION_ERROR_MESSAGES.serviceDate[1], + + expect(externalDocumentD.getFormattedValidationErrors()).toEqual({ + serviceDate: + ExternalDocumentNonStandardD.VALIDATION_ERROR_MESSAGES.serviceDate[1], }); }); it('should be invalid when documentTitle is over 3000 characters', () => { const serviceDate = createISODateString(); - const extDoc = ExternalDocumentFactory({ + + const externalDocumentD = ExternalDocumentFactory({ category: 'Supporting Document', documentTitle: getTextByCount(3001), documentType: 'Certificate of Service', @@ -75,16 +90,19 @@ describe('ExternalDocumentNonStandardD', () => { scenario: 'Nonstandard D', serviceDate, }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - documentTitle: VALIDATION_ERROR_MESSAGES.documentTitle, + + expect(externalDocumentD.getFormattedValidationErrors()).toEqual({ + documentTitle: + ExternalDocumentNonStandardD.VALIDATION_ERROR_MESSAGES.documentTitle, }); }); }); describe('title generation', () => { const serviceDate = '2012-04-10T04:00:00.000Z'; + it('should generate valid title with previousDocument documentType', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentD = ExternalDocumentFactory({ category: 'Supporting Document', documentTitle: 'Certificate of Service [Document Name] [Date]', documentType: 'Certificate of Service', @@ -92,13 +110,14 @@ describe('ExternalDocumentNonStandardD', () => { scenario: 'Nonstandard D', serviceDate, }); - expect(extDoc.getDocumentTitle()).toEqual( + + expect(externalDocumentD.getDocumentTitle()).toEqual( 'Certificate of Service Petition 04-10-2012', ); }); it('should generate valid title with previousDocument documentTitle', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentD = ExternalDocumentFactory({ category: 'Supporting Document', documentTitle: 'Certificate of Service [Document Name] [Date]', documentType: 'Certificate of Service', @@ -109,20 +128,22 @@ describe('ExternalDocumentNonStandardD', () => { scenario: 'Nonstandard D', serviceDate, }); - expect(extDoc.getDocumentTitle()).toEqual( + + expect(externalDocumentD.getDocumentTitle()).toEqual( 'Certificate of Service Stipulation Something 04-10-2012', ); }); it('should generate title without previousDocument', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentD = ExternalDocumentFactory({ category: 'Supporting Document', documentTitle: 'Certificate of Service [Document Name] [Date]', documentType: 'Certificate of Service', scenario: 'Nonstandard D', serviceDate, }); - expect(extDoc.getDocumentTitle()).toEqual( + + expect(externalDocumentD.getDocumentTitle()).toEqual( 'Certificate of Service 04-10-2012', ); }); diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardD.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardD.ts index 4bd93ee7956..4ab8c0ac132 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardD.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardD.ts @@ -1,67 +1,47 @@ -const joi = require('joi'); -const { - baseExternalDocumentValidation, - externalDocumentDecorator, -} = require('./ExternalDocumentBase'); -const { - joiValidationDecorator, - validEntityDecorator, -} = require('../JoiValidationDecorator'); -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { formatDateString, FORMATS } = require('../../utilities/DateHandler'); -const { JoiValidationConstants } = require('../JoiValidationConstants'); -const { replaceBracketed } = require('../../utilities/replaceBracketed'); +import { ExternalDocumentBase } from './ExternalDocumentBase'; +import { FORMATS, formatDateString } from '../../utilities/DateHandler'; +import { JoiValidationConstants } from '../JoiValidationConstants'; +import { replaceBracketed } from '../../utilities/replaceBracketed'; +import joi from 'joi'; -/** - * - * @param {object} rawProps the raw document data - * @constructor - */ -function ExternalDocumentNonStandardD() {} +export class ExternalDocumentNonStandardD extends ExternalDocumentBase { + public previousDocument: { documentTitle?: string; documentType: string }; + public serviceDate: string; -ExternalDocumentNonStandardD.prototype.init = function init(rawProps) { - externalDocumentDecorator(this, rawProps); - this.previousDocument = rawProps.previousDocument; - this.serviceDate = rawProps.serviceDate; -}; + constructor(rawProps) { + super(rawProps, 'ExternalDocumentNonStandardD'); -ExternalDocumentNonStandardD.prototype.getDocumentTitle = function () { - return replaceBracketed( - this.documentTitle, - this.previousDocument - ? this.previousDocument.documentTitle || - this.previousDocument.documentType - : '', - formatDateString(this.serviceDate, FORMATS.MMDDYYYY_DASHED), - ); -}; + this.previousDocument = rawProps.previousDocument; + this.serviceDate = rawProps.serviceDate; + } -ExternalDocumentNonStandardD.VALIDATION_ERROR_MESSAGES = { - ...VALIDATION_ERROR_MESSAGES, -}; + static VALIDATION_RULES = { + ...ExternalDocumentBase.VALIDATION_RULES, + previousDocument: joi + .object() + .keys({ + documentTitle: JoiValidationConstants.STRING.optional(), + documentType: JoiValidationConstants.STRING.required(), + }) + .required(), + serviceDate: JoiValidationConstants.ISO_DATE.max('now').required(), + }; -ExternalDocumentNonStandardD.schema = { - ...baseExternalDocumentValidation, - previousDocument: joi - .object() - .keys({ - documentTitle: JoiValidationConstants.STRING.optional(), - documentType: JoiValidationConstants.STRING.required(), - }) - .required(), - serviceDate: JoiValidationConstants.ISO_DATE.max('now').required(), -}; + getValidationRules() { + return ExternalDocumentNonStandardD.VALIDATION_RULES; + } -joiValidationDecorator( - ExternalDocumentNonStandardD, - ExternalDocumentNonStandardD.schema, - ExternalDocumentNonStandardD.VALIDATION_ERROR_MESSAGES, -); + getDocumentTitle(): string { + return replaceBracketed( + this.documentTitle, + this.previousDocument + ? this.previousDocument.documentTitle || + this.previousDocument.documentType + : '', + formatDateString(this.serviceDate, FORMATS.MMDDYYYY_DASHED), + ); + } +} -module.exports = { - ExternalDocumentNonStandardD: validEntityDecorator( - ExternalDocumentNonStandardD, - ), -}; +export type RawExternalDocumentNonStandardD = + ExcludeMethods; diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardE.test.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardE.test.ts index 0629ff22236..127f92a5f6f 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardE.test.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardE.test.ts @@ -1,24 +1,27 @@ -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { ExternalDocumentFactory } = require('./ExternalDocumentFactory'); -const { getTextByCount } = require('../../utilities/getTextByCount'); +import { ExternalDocumentFactory } from './ExternalDocumentFactory'; +import { ExternalDocumentNonStandardE } from './ExternalDocumentNonStandardE'; +import { getTextByCount } from '../../utilities/getTextByCount'; describe('ExternalDocumentNonStandardE', () => { describe('validation', () => { it('should have error messages for missing fields', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentD = ExternalDocumentFactory({ scenario: 'Nonstandard E', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - category: VALIDATION_ERROR_MESSAGES.category, - documentType: VALIDATION_ERROR_MESSAGES.documentType[1], - trialLocation: VALIDATION_ERROR_MESSAGES.trialLocation, + + expect(externalDocumentD.getFormattedValidationErrors()).toEqual({ + category: + ExternalDocumentNonStandardE.VALIDATION_ERROR_MESSAGES.category, + documentType: + ExternalDocumentNonStandardE.VALIDATION_ERROR_MESSAGES + .documentType[1], + trialLocation: + ExternalDocumentNonStandardE.VALIDATION_ERROR_MESSAGES.trialLocation, }); }); it('should be valid when all fields are present', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentD = ExternalDocumentFactory({ category: 'Motion', documentTitle: 'Motion to Change Place of Submission of Declaratory Judgment Case to [Place]', @@ -27,11 +30,12 @@ describe('ExternalDocumentNonStandardE', () => { scenario: 'Nonstandard E', trialLocation: 'Little Rock, AR', }); - expect(extDoc.getFormattedValidationErrors()).toEqual(null); + + expect(externalDocumentD.getFormattedValidationErrors()).toEqual(null); }); it('should be invalid when documentTitle is over 3000 characters', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentD = ExternalDocumentFactory({ category: 'Motion', documentTitle: getTextByCount(3001), documentType: @@ -39,15 +43,17 @@ describe('ExternalDocumentNonStandardE', () => { scenario: 'Nonstandard E', trialLocation: 'Little Rock, AR', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - documentTitle: VALIDATION_ERROR_MESSAGES.documentTitle, + + expect(externalDocumentD.getFormattedValidationErrors()).toEqual({ + documentTitle: + ExternalDocumentNonStandardE.VALIDATION_ERROR_MESSAGES.documentTitle, }); }); }); describe('title generation', () => { it('should generate valid title', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentD = ExternalDocumentFactory({ category: 'Motion', documentTitle: 'Motion to Change Place of Submission of Declaratory Judgment Case to [Place]', @@ -56,7 +62,8 @@ describe('ExternalDocumentNonStandardE', () => { scenario: 'Nonstandard E', trialLocation: 'Little Rock, AR', }); - expect(extDoc.getDocumentTitle()).toEqual( + + expect(externalDocumentD.getDocumentTitle()).toEqual( 'Motion to Change Place of Submission of Declaratory Judgment Case to Little Rock, AR', ); }); diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardE.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardE.ts index 170c312cc1c..a7279e351ee 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardE.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardE.ts @@ -1,50 +1,29 @@ -const { - baseExternalDocumentValidation, - externalDocumentDecorator, -} = require('./ExternalDocumentBase'); -const { - joiValidationDecorator, - validEntityDecorator, -} = require('../JoiValidationDecorator'); -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { JoiValidationConstants } = require('../JoiValidationConstants'); -const { replaceBracketed } = require('../../utilities/replaceBracketed'); +import { ExternalDocumentBase } from './ExternalDocumentBase'; +import { JoiValidationConstants } from '../JoiValidationConstants'; +import { replaceBracketed } from '../../utilities/replaceBracketed'; -/** - * - * @param {object} rawProps the raw document data - * @constructor - */ -function ExternalDocumentNonStandardE() {} +export class ExternalDocumentNonStandardE extends ExternalDocumentBase { + public trialLocation: string; -ExternalDocumentNonStandardE.prototype.init = function init(rawProps) { - externalDocumentDecorator(this, rawProps); - this.trialLocation = rawProps.trialLocation; -}; + constructor(rawProps) { + super(rawProps, 'ExternalDocumentNonStandardE'); -ExternalDocumentNonStandardE.prototype.getDocumentTitle = function () { - return replaceBracketed(this.documentTitle, this.trialLocation); -}; + this.trialLocation = rawProps.trialLocation; + } -ExternalDocumentNonStandardE.VALIDATION_ERROR_MESSAGES = { - ...VALIDATION_ERROR_MESSAGES, -}; + static VALIDATION_RULES = { + ...ExternalDocumentBase.VALIDATION_RULES, + trialLocation: JoiValidationConstants.STRING.required(), + }; -ExternalDocumentNonStandardE.schema = { - ...baseExternalDocumentValidation, - trialLocation: JoiValidationConstants.STRING.required(), -}; + getValidationRules() { + return ExternalDocumentNonStandardE.VALIDATION_RULES; + } -joiValidationDecorator( - ExternalDocumentNonStandardE, - ExternalDocumentNonStandardE.schema, - ExternalDocumentNonStandardE.VALIDATION_ERROR_MESSAGES, -); + getDocumentTitle(): string { + return replaceBracketed(this.documentTitle, this.trialLocation); + } +} -module.exports = { - ExternalDocumentNonStandardE: validEntityDecorator( - ExternalDocumentNonStandardE, - ), -}; +export type RawExternalDocumentNonStandardE = + ExcludeMethods; diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardF.test.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardF.test.ts index 0be90df971a..45feeb50e38 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardF.test.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardF.test.ts @@ -1,25 +1,30 @@ -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { ExternalDocumentFactory } = require('./ExternalDocumentFactory'); -const { getTextByCount } = require('../../utilities/getTextByCount'); +import { ExternalDocumentFactory } from './ExternalDocumentFactory'; +import { ExternalDocumentNonStandardF } from './ExternalDocumentNonStandardF'; +import { getTextByCount } from '../../utilities/getTextByCount'; describe('ExternalDocumentNonStandardF', () => { describe('validation', () => { it('should have error messages for missing fields', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentF = ExternalDocumentFactory({ scenario: 'Nonstandard F', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - category: VALIDATION_ERROR_MESSAGES.category, - documentType: VALIDATION_ERROR_MESSAGES.documentType[1], - ordinalValue: VALIDATION_ERROR_MESSAGES.ordinalValue, - previousDocument: VALIDATION_ERROR_MESSAGES.previousDocument, + + expect(externalDocumentF.getFormattedValidationErrors()).toEqual({ + category: + ExternalDocumentNonStandardF.VALIDATION_ERROR_MESSAGES.category, + documentType: + ExternalDocumentNonStandardF.VALIDATION_ERROR_MESSAGES + .documentType[1], + ordinalValue: + ExternalDocumentNonStandardF.VALIDATION_ERROR_MESSAGES.ordinalValue, + previousDocument: + ExternalDocumentNonStandardF.VALIDATION_ERROR_MESSAGES + .previousDocument, }); }); it('should be valid when all fields are present', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentF = ExternalDocumentFactory({ category: 'Miscellaneous', documentTitle: '[First, Second, etc.] Amended [Document Name]', documentType: 'Amended', @@ -27,11 +32,12 @@ describe('ExternalDocumentNonStandardF', () => { previousDocument: { documentType: 'Petition' }, scenario: 'Nonstandard F', }); - expect(extDoc.getFormattedValidationErrors()).toEqual(null); + + expect(externalDocumentF.getFormattedValidationErrors()).toEqual(null); }); it('should be invalid when documentTitle is over 3000 characters', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentF = ExternalDocumentFactory({ category: 'Miscellaneous', documentTitle: getTextByCount(3001), documentType: 'Amended', @@ -39,15 +45,17 @@ describe('ExternalDocumentNonStandardF', () => { previousDocument: { documentType: 'Petition' }, scenario: 'Nonstandard F', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - documentTitle: VALIDATION_ERROR_MESSAGES.documentTitle, + + expect(externalDocumentF.getFormattedValidationErrors()).toEqual({ + documentTitle: + ExternalDocumentNonStandardF.VALIDATION_ERROR_MESSAGES.documentTitle, }); }); }); describe('title generation', () => { it('should generate valid title with previousDocument documentType', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentF = ExternalDocumentFactory({ category: 'Miscellaneous', documentTitle: '[First, Second, etc.] Amended [Document Name]', documentType: 'Amended', @@ -55,11 +63,14 @@ describe('ExternalDocumentNonStandardF', () => { previousDocument: { documentType: 'Petition' }, scenario: 'Nonstandard F', }); - expect(extDoc.getDocumentTitle()).toEqual('First Amended Petition'); + + expect(externalDocumentF.getDocumentTitle()).toEqual( + 'First Amended Petition', + ); }); it('should generate valid title with previousDocument documentTitle', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentF = ExternalDocumentFactory({ category: 'Miscellaneous', documentTitle: '[First, Second, etc.] Amended [Document Name]', documentType: 'Amended', @@ -70,24 +81,26 @@ describe('ExternalDocumentNonStandardF', () => { }, scenario: 'Nonstandard F', }); - expect(extDoc.getDocumentTitle()).toEqual( + + expect(externalDocumentF.getDocumentTitle()).toEqual( 'First Amended Stipulation Something', ); }); it('should generate title without previousDocument', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentF = ExternalDocumentFactory({ category: 'Miscellaneous', documentTitle: '[First, Second, etc.] Amended [Document Name]', documentType: 'Amended', ordinalValue: '1', scenario: 'Nonstandard F', }); - expect(extDoc.getDocumentTitle()).toEqual('First Amended'); + + expect(externalDocumentF.getDocumentTitle()).toEqual('First Amended'); }); it('should generate title with an otherIteration defined when ordinalValue is "Other"', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentF = ExternalDocumentFactory({ category: 'Miscellaneous', documentTitle: '[First, Second, etc.] Amended [Document Name]', documentType: 'Amended', @@ -95,7 +108,8 @@ describe('ExternalDocumentNonStandardF', () => { otherIteration: 50, scenario: 'Nonstandard F', }); - expect(extDoc.getDocumentTitle()).toEqual('Fiftieth Amended'); + + expect(externalDocumentF.getDocumentTitle()).toEqual('Fiftieth Amended'); }); }); }); diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardF.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardF.ts index 18ffcfd91f8..04bdaa4f527 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardF.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardF.ts @@ -1,77 +1,56 @@ -const joi = require('joi'); -const { - baseExternalDocumentValidation, - externalDocumentDecorator, -} = require('./ExternalDocumentBase'); -const { - joiValidationDecorator, - validEntityDecorator, -} = require('../JoiValidationDecorator'); -const { - transformFormValueToTitleCaseOrdinal, -} = require('../../utilities/transformFormValueToTitleCaseOrdinal'); -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { JoiValidationConstants } = require('../JoiValidationConstants'); -const { replaceBracketed } = require('../../utilities/replaceBracketed'); +import { ExternalDocumentBase } from './ExternalDocumentBase'; +import { JoiValidationConstants } from '../JoiValidationConstants'; +import { replaceBracketed } from '../../utilities/replaceBracketed'; +import { transformFormValueToTitleCaseOrdinal } from '../../utilities/transformFormValueToTitleCaseOrdinal'; +import joi from 'joi'; -/** - * - * @param {object} rawProps the raw document data - * @constructor - */ -function ExternalDocumentNonStandardF() {} +export class ExternalDocumentNonStandardF extends ExternalDocumentBase { + public ordinalValue: string; + public otherIteration?: number; + public previousDocument: { documentTitle?: string; documentType: string }; -ExternalDocumentNonStandardF.prototype.init = function init(rawProps) { - externalDocumentDecorator(this, rawProps); - this.ordinalValue = rawProps.ordinalValue; - this.otherIteration = rawProps.otherIteration; - this.previousDocument = rawProps.previousDocument; -}; + constructor(rawProps) { + super(rawProps, 'ExternalDocumentNonStandardF'); -ExternalDocumentNonStandardF.prototype.getDocumentTitle = function () { - return replaceBracketed( - this.documentTitle, - this.ordinalValue === 'Other' - ? transformFormValueToTitleCaseOrdinal(this.otherIteration) - : transformFormValueToTitleCaseOrdinal(this.ordinalValue), - this.previousDocument - ? this.previousDocument.documentTitle || - this.previousDocument.documentType - : '', - ); -}; + this.ordinalValue = rawProps.ordinalValue; + this.otherIteration = rawProps.otherIteration; + this.previousDocument = rawProps.previousDocument; + } -ExternalDocumentNonStandardF.VALIDATION_ERROR_MESSAGES = { - ...VALIDATION_ERROR_MESSAGES, -}; + static VALIDATION_RULES = { + ...ExternalDocumentBase.VALIDATION_RULES, + ordinalValue: JoiValidationConstants.STRING.required(), + otherIteration: joi.when('ordinalValue', { + is: 'Other', + otherwise: joi.optional().allow(null), + then: joi.number().max(999).required(), + }), + previousDocument: joi + .object() + .keys({ + documentTitle: JoiValidationConstants.STRING.optional(), + documentType: JoiValidationConstants.STRING.required(), + }) + .required(), + }; -ExternalDocumentNonStandardF.schema = { - ...baseExternalDocumentValidation, - ordinalValue: JoiValidationConstants.STRING.required(), - otherIteration: joi.when('ordinalValue', { - is: 'Other', - otherwise: joi.optional().allow(null), - then: joi.number().max(999).required(), - }), - previousDocument: joi - .object() - .keys({ - documentTitle: JoiValidationConstants.STRING.optional(), - documentType: JoiValidationConstants.STRING.required(), - }) - .required(), -}; + getValidationRules() { + return ExternalDocumentNonStandardF.VALIDATION_RULES; + } -joiValidationDecorator( - ExternalDocumentNonStandardF, - ExternalDocumentNonStandardF.schema, - ExternalDocumentNonStandardF.VALIDATION_ERROR_MESSAGES, -); + getDocumentTitle(): string { + return replaceBracketed( + this.documentTitle, + this.ordinalValue === 'Other' + ? transformFormValueToTitleCaseOrdinal(this.otherIteration) + : transformFormValueToTitleCaseOrdinal(this.ordinalValue), + this.previousDocument + ? this.previousDocument.documentTitle || + this.previousDocument.documentType + : '', + ); + } +} -module.exports = { - ExternalDocumentNonStandardF: validEntityDecorator( - ExternalDocumentNonStandardF, - ), -}; +export type RawExternalDocumentNonStandardF = + ExcludeMethods; diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardG.test.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardG.test.ts index 1eaafae9271..e963a19ef8c 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardG.test.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardG.test.ts @@ -1,61 +1,70 @@ -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { ExternalDocumentFactory } = require('./ExternalDocumentFactory'); -const { getTextByCount } = require('../../utilities/getTextByCount'); +import { ExternalDocumentFactory } from './ExternalDocumentFactory'; +import { ExternalDocumentNonStandardG } from './ExternalDocumentNonStandardG'; +import { getTextByCount } from '../../utilities/getTextByCount'; describe('ExternalDocumentNonStandardG', () => { describe('validation', () => { it('should have error messages for missing fields', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentG = ExternalDocumentFactory({ scenario: 'Nonstandard G', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - category: VALIDATION_ERROR_MESSAGES.category, - documentType: VALIDATION_ERROR_MESSAGES.documentType[1], - ordinalValue: VALIDATION_ERROR_MESSAGES.ordinalValue, + + expect(externalDocumentG.getFormattedValidationErrors()).toEqual({ + category: + ExternalDocumentNonStandardG.VALIDATION_ERROR_MESSAGES.category, + documentType: + ExternalDocumentNonStandardG.VALIDATION_ERROR_MESSAGES + .documentType[1], + ordinalValue: + ExternalDocumentNonStandardG.VALIDATION_ERROR_MESSAGES.ordinalValue, }); }); it('should be valid when all fields are present', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentG = ExternalDocumentFactory({ category: 'Answer', documentTitle: '[First, Second, etc.] Amendment to Answer', documentType: 'Amendment to Answer', ordinalValue: 'First', scenario: 'Nonstandard G', }); - expect(extDoc.getFormattedValidationErrors()).toEqual(null); + + expect(externalDocumentG.getFormattedValidationErrors()).toEqual(null); }); it('should be invalid when documentTitle is over 3000 characters', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentG = ExternalDocumentFactory({ category: 'Answer', documentTitle: getTextByCount(3001), documentType: 'Amendment to Answer', ordinalValue: 'First', scenario: 'Nonstandard G', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - documentTitle: VALIDATION_ERROR_MESSAGES.documentTitle, + + expect(externalDocumentG.getFormattedValidationErrors()).toEqual({ + documentTitle: + ExternalDocumentNonStandardG.VALIDATION_ERROR_MESSAGES.documentTitle, }); }); }); describe('title generation', () => { it('should generate valid title', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentG = ExternalDocumentFactory({ category: 'Answer', documentTitle: '[First, Second, etc.] Amendment to Answer', documentType: 'Amendment to Answer', ordinalValue: '1', scenario: 'Nonstandard G', }); - expect(extDoc.getDocumentTitle()).toEqual('First Amendment to Answer'); + + expect(externalDocumentG.getDocumentTitle()).toEqual( + 'First Amendment to Answer', + ); }); it('should generate title with an otherIteration defined when ordinalValue is "Other"', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentG = ExternalDocumentFactory({ category: 'Answer', documentTitle: '[First, Second, etc.] Amendment to Answer', documentType: 'Amendment to Answer', @@ -63,7 +72,10 @@ describe('ExternalDocumentNonStandardG', () => { otherIteration: 50, scenario: 'Nonstandard G', }); - expect(extDoc.getDocumentTitle()).toEqual('Fiftieth Amendment to Answer'); + + expect(externalDocumentG.getDocumentTitle()).toEqual( + 'Fiftieth Amendment to Answer', + ); }); }); }); diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardG.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardG.ts index a30bcac3a11..1ab778eb225 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardG.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardG.ts @@ -1,65 +1,44 @@ -const joi = require('joi'); -const { - baseExternalDocumentValidation, - externalDocumentDecorator, -} = require('./ExternalDocumentBase'); -const { - joiValidationDecorator, - validEntityDecorator, -} = require('../JoiValidationDecorator'); -const { - transformFormValueToTitleCaseOrdinal, -} = require('../../utilities/transformFormValueToTitleCaseOrdinal'); -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { JoiValidationConstants } = require('../JoiValidationConstants'); -const { replaceBracketed } = require('../../utilities/replaceBracketed'); +import { ExternalDocumentBase } from './ExternalDocumentBase'; +import { JoiValidationConstants } from '../JoiValidationConstants'; +import { replaceBracketed } from '../../utilities/replaceBracketed'; +import { transformFormValueToTitleCaseOrdinal } from '../../utilities/transformFormValueToTitleCaseOrdinal'; +import joi from 'joi'; -/** - * - * @param {object} rawProps the raw document data - * @constructor - */ -function ExternalDocumentNonStandardG() {} -ExternalDocumentNonStandardG.prototype.init = function init(rawProps) { - externalDocumentDecorator(this, rawProps); - this.ordinalValue = rawProps.ordinalValue; - this.otherIteration = rawProps.otherIteration; -}; +export class ExternalDocumentNonStandardG extends ExternalDocumentBase { + public ordinalValue: string; + public otherIteration?: number; -ExternalDocumentNonStandardG.prototype.getDocumentTitle = function () { - return replaceBracketed( - this.documentTitle, - this.ordinalValue === 'Other' - ? transformFormValueToTitleCaseOrdinal(this.otherIteration) - : transformFormValueToTitleCaseOrdinal(this.ordinalValue), - this.documentType, - ); -}; + constructor(rawProps) { + super(rawProps, 'ExternalDocumentNonStandardG'); -ExternalDocumentNonStandardG.VALIDATION_ERROR_MESSAGES = { - ...VALIDATION_ERROR_MESSAGES, -}; + this.ordinalValue = rawProps.ordinalValue; + this.otherIteration = rawProps.otherIteration; + } -ExternalDocumentNonStandardG.schema = { - ...baseExternalDocumentValidation, - ordinalValue: JoiValidationConstants.STRING.required(), - otherIteration: joi.when('ordinalValue', { - is: 'Other', - otherwise: joi.optional().allow(null), - then: joi.number().max(999).required(), - }), -}; + static VALIDATION_RULES = { + ...ExternalDocumentBase.VALIDATION_RULES, + ordinalValue: JoiValidationConstants.STRING.required(), + otherIteration: joi.when('ordinalValue', { + is: 'Other', + otherwise: joi.optional().allow(null), + then: joi.number().max(999).required(), + }), + }; -joiValidationDecorator( - ExternalDocumentNonStandardG, - joi.object(ExternalDocumentNonStandardG.schema), - ExternalDocumentNonStandardG.VALIDATION_ERROR_MESSAGES, -); + getValidationRules() { + return ExternalDocumentNonStandardG.VALIDATION_RULES; + } -module.exports = { - ExternalDocumentNonStandardG: validEntityDecorator( - ExternalDocumentNonStandardG, - ), -}; + getDocumentTitle(): string { + return replaceBracketed( + this.documentTitle, + this.ordinalValue === 'Other' + ? transformFormValueToTitleCaseOrdinal(this.otherIteration) + : transformFormValueToTitleCaseOrdinal(this.ordinalValue), + this.documentType, + ); + } +} + +export type RawExternalDocumentNonStandardG = + ExcludeMethods; diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardH.test.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardH.test.ts index e0cdb501409..bbcdb411cdb 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardH.test.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardH.test.ts @@ -1,27 +1,32 @@ -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { ExternalDocumentFactory } = require('./ExternalDocumentFactory'); -const { getTextByCount } = require('../../utilities/getTextByCount'); +import { ExternalDocumentFactory } from './ExternalDocumentFactory'; +import { ExternalDocumentNonStandardH } from './ExternalDocumentNonStandardH'; +import { getTextByCount } from '../../utilities/getTextByCount'; describe('ExternalDocumentNonStandardH', () => { describe('validation', () => { it('should have error messages for missing fields', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentH = ExternalDocumentFactory({ scenario: 'Nonstandard H', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - category: VALIDATION_ERROR_MESSAGES.category, - documentType: VALIDATION_ERROR_MESSAGES.documentType[1], + + expect(externalDocumentH.getFormattedValidationErrors()).toEqual({ + category: + ExternalDocumentNonStandardH.VALIDATION_ERROR_MESSAGES.category, + documentType: + ExternalDocumentNonStandardH.VALIDATION_ERROR_MESSAGES + .documentType[1], secondaryDocument: { - category: VALIDATION_ERROR_MESSAGES.category, - documentType: VALIDATION_ERROR_MESSAGES.documentType[1], + category: + ExternalDocumentNonStandardH.VALIDATION_ERROR_MESSAGES.category, + documentType: + ExternalDocumentNonStandardH.VALIDATION_ERROR_MESSAGES + .documentType[1], }, }); }); it('should be valid when all fields are present', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentH = ExternalDocumentFactory({ category: 'Motion', documentTitle: 'Motion for Leave to File [Document Name]', documentType: 'Motion for Leave to File', @@ -32,11 +37,12 @@ describe('ExternalDocumentNonStandardH', () => { documentType: 'Application for Waiver of Filing Fee', }, }); - expect(extDoc.getFormattedValidationErrors()).toEqual(null); + + expect(externalDocumentH.getFormattedValidationErrors()).toEqual(null); }); it('should have error messages for nonstandard secondary document', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentH = ExternalDocumentFactory({ category: 'Motion', documentTitle: 'Motion for Leave to File [Document Name]', documentType: 'Motion for Leave to File', @@ -45,18 +51,24 @@ describe('ExternalDocumentNonStandardH', () => { scenario: 'Nonstandard A', }, }); - expect(() => extDoc.validate()).toThrow(); - expect(extDoc.getFormattedValidationErrors()).toEqual({ + + expect(() => externalDocumentH.validate()).toThrow(); + expect(externalDocumentH.getFormattedValidationErrors()).toEqual({ secondaryDocument: { - category: VALIDATION_ERROR_MESSAGES.category, - documentType: VALIDATION_ERROR_MESSAGES.documentType[1], - previousDocument: VALIDATION_ERROR_MESSAGES.previousDocument, + category: + ExternalDocumentNonStandardH.VALIDATION_ERROR_MESSAGES.category, + documentType: + ExternalDocumentNonStandardH.VALIDATION_ERROR_MESSAGES + .documentType[1], + previousDocument: + ExternalDocumentNonStandardH.VALIDATION_ERROR_MESSAGES + .previousDocument, }, }); }); it('should be invalid when documentTitle is over 3000 characters', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentH = ExternalDocumentFactory({ category: 'Motion', documentTitle: getTextByCount(3001), documentType: 'Motion for Leave to File', @@ -67,14 +79,16 @@ describe('ExternalDocumentNonStandardH', () => { documentType: 'Application for Waiver of Filing Fee', }, }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - documentTitle: VALIDATION_ERROR_MESSAGES.documentTitle, + + expect(externalDocumentH.getFormattedValidationErrors()).toEqual({ + documentTitle: + ExternalDocumentNonStandardH.VALIDATION_ERROR_MESSAGES.documentTitle, }); }); }); it('should be valid when all nonstandard secondary document fields are present', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentH = ExternalDocumentFactory({ category: 'Motion', documentTitle: 'Motion for Leave to File [Document Name]', documentType: 'Motion for Leave to File', @@ -87,13 +101,14 @@ describe('ExternalDocumentNonStandardH', () => { scenario: 'Nonstandard A', }, }); - expect(() => extDoc.validate()).not.toThrow(); - expect(extDoc.getFormattedValidationErrors()).toEqual(null); + + expect(() => externalDocumentH.validate()).not.toThrow(); + expect(externalDocumentH.getFormattedValidationErrors()).toEqual(null); }); describe('title generation', () => { it('should generate valid title', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentH = ExternalDocumentFactory({ category: 'Motion', documentTitle: 'Motion for Leave to File [Document Name]', documentType: 'Motion for Leave to File', @@ -106,7 +121,8 @@ describe('ExternalDocumentNonStandardH', () => { scenario: 'Nonstandard A', }, }); - expect(extDoc.getDocumentTitle()).toEqual( + + expect(externalDocumentH.getDocumentTitle()).toEqual( 'Motion for Leave to File Brief in Support of Petition', ); }); diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardH.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardH.ts index 3e21f75b35d..42264be6de6 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardH.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardH.ts @@ -1,59 +1,36 @@ -const joi = require('joi'); -const { - baseExternalDocumentValidation, - externalDocumentDecorator, -} = require('./ExternalDocumentBase'); -const { - joiValidationDecorator, - validEntityDecorator, -} = require('../JoiValidationDecorator'); -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { replaceBracketed } = require('../../utilities/replaceBracketed'); +import { ExternalDocumentBase } from './ExternalDocumentBase'; +import { ExternalDocumentFactory } from './ExternalDocumentFactory'; +import { replaceBracketed } from '../../utilities/replaceBracketed'; +import joi from 'joi'; -/** - * - * @param {object} rawProps the raw document data - * @param {ExternalDocumentFactory} ExternalDocumentFactory the factory for the secondary document - * @constructor - */ -function ExternalDocumentNonStandardH() {} -ExternalDocumentNonStandardH.prototype.init = function init( - rawProps, - ExternalDocumentFactory, -) { - externalDocumentDecorator(this, rawProps); +export class ExternalDocumentNonStandardH extends ExternalDocumentBase { + public secondaryDocument: any; - const { secondaryDocument } = rawProps; - this.secondaryDocument = ExternalDocumentFactory(secondaryDocument || {}); -}; + constructor(rawProps) { + super(rawProps, 'ExternalDocumentNonStandardH'); -ExternalDocumentNonStandardH.prototype.getDocumentTitle = function () { - return replaceBracketed( - this.documentTitle, - this.secondaryDocument.getDocumentTitle(), - ); -}; + this.secondaryDocument = ExternalDocumentFactory( + rawProps.secondaryDocument || {}, + ); + } -ExternalDocumentNonStandardH.VALIDATION_ERROR_MESSAGES = { - ...VALIDATION_ERROR_MESSAGES, -}; + static VALIDATION_RULES = { + ...ExternalDocumentBase.VALIDATION_RULES, + secondaryDocument: joi.object().required(), + secondaryDocumentFile: joi.object().optional(), + }; -ExternalDocumentNonStandardH.schema = { - ...baseExternalDocumentValidation, - secondaryDocument: joi.object().required(), - secondaryDocumentFile: joi.object().optional(), -}; + getValidationRules() { + return ExternalDocumentNonStandardH.VALIDATION_RULES; + } -joiValidationDecorator( - ExternalDocumentNonStandardH, - ExternalDocumentNonStandardH.schema, - ExternalDocumentNonStandardH.VALIDATION_ERROR_MESSAGES, -); + getDocumentTitle(): string { + return replaceBracketed( + this.documentTitle, + this.secondaryDocument.getDocumentTitle(), + ); + } +} -module.exports = { - ExternalDocumentNonStandardH: validEntityDecorator( - ExternalDocumentNonStandardH, - ), -}; +export type RawExternalDocumentNonStandardH = + ExcludeMethods; diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardI.test.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardI.test.ts index ff3ef5a0a12..3a8651d1915 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardI.test.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardI.test.ts @@ -1,25 +1,30 @@ -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { ExternalDocumentFactory } = require('./ExternalDocumentFactory'); -const { getTextByCount } = require('../../utilities/getTextByCount'); +import { ExternalDocumentFactory } from './ExternalDocumentFactory'; +import { ExternalDocumentNonStandardI } from './ExternalDocumentNonStandardI'; +import { getTextByCount } from '../../utilities/getTextByCount'; describe('ExternalDocumentNonStandardI', () => { describe('validation', () => { it('should have error messages for missing fields', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentI = ExternalDocumentFactory({ scenario: 'Nonstandard I', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - category: VALIDATION_ERROR_MESSAGES.category, - documentType: VALIDATION_ERROR_MESSAGES.documentType[1], - freeText: VALIDATION_ERROR_MESSAGES.freeText[0].message, - ordinalValue: VALIDATION_ERROR_MESSAGES.ordinalValue, + + expect(externalDocumentI.getFormattedValidationErrors()).toEqual({ + category: + ExternalDocumentNonStandardI.VALIDATION_ERROR_MESSAGES.category, + documentType: + ExternalDocumentNonStandardI.VALIDATION_ERROR_MESSAGES + .documentType[1], + freeText: + ExternalDocumentNonStandardI.VALIDATION_ERROR_MESSAGES.freeText[0] + .message, + ordinalValue: + ExternalDocumentNonStandardI.VALIDATION_ERROR_MESSAGES.ordinalValue, }); }); it('should be valid when all fields are present', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentI = ExternalDocumentFactory({ category: 'Miscellaneous', documentTitle: '[First, Second, etc.] Amendment to [anything]', documentType: 'Amendment [anything]', @@ -27,11 +32,12 @@ describe('ExternalDocumentNonStandardI', () => { ordinalValue: 'First', scenario: 'Nonstandard I', }); - expect(extDoc.getFormattedValidationErrors()).toEqual(null); + + expect(externalDocumentI.getFormattedValidationErrors()).toEqual(null); }); it('should be invalid when freeText is over 1000 characters', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentI = ExternalDocumentFactory({ category: 'Miscellaneous', documentTitle: '[First, Second, etc.] Amendment to [anything]', documentType: 'Amendment [anything]', @@ -40,13 +46,15 @@ describe('ExternalDocumentNonStandardI', () => { scenario: 'Nonstandard I', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - freeText: VALIDATION_ERROR_MESSAGES.freeText[1].message, + expect(externalDocumentI.getFormattedValidationErrors()).toEqual({ + freeText: + ExternalDocumentNonStandardI.VALIDATION_ERROR_MESSAGES.freeText[1] + .message, }); }); it('should be invalid when documentTitle is over 3000 characters', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentI = ExternalDocumentFactory({ category: 'Miscellaneous', documentTitle: getTextByCount(3001), documentType: 'Amendment [anything]', @@ -54,15 +62,17 @@ describe('ExternalDocumentNonStandardI', () => { ordinalValue: 'First', scenario: 'Nonstandard I', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - documentTitle: VALIDATION_ERROR_MESSAGES.documentTitle, + + expect(externalDocumentI.getFormattedValidationErrors()).toEqual({ + documentTitle: + ExternalDocumentNonStandardI.VALIDATION_ERROR_MESSAGES.documentTitle, }); }); }); describe('title generation', () => { it('should generate valid title', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentI = ExternalDocumentFactory({ category: 'Miscellaneous', documentTitle: '[First, Second, etc.] Amendment to [anything]', documentType: 'Amendment [anything]', @@ -70,11 +80,14 @@ describe('ExternalDocumentNonStandardI', () => { ordinalValue: '1', scenario: 'Nonstandard I', }); - expect(extDoc.getDocumentTitle()).toEqual('First Amendment to Test'); + + expect(externalDocumentI.getDocumentTitle()).toEqual( + 'First Amendment to Test', + ); }); it('should generate title with an otherIteration defined when ordinalValue is "Other"', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentI = ExternalDocumentFactory({ category: 'Miscellaneous', documentTitle: '[First, Second, etc.] Amendment to [anything]', documentType: 'Amendment [anything]', @@ -83,7 +96,10 @@ describe('ExternalDocumentNonStandardI', () => { otherIteration: 50, scenario: 'Nonstandard I', }); - expect(extDoc.getDocumentTitle()).toEqual('Fiftieth Amendment to Test'); + + expect(externalDocumentI.getDocumentTitle()).toEqual( + 'Fiftieth Amendment to Test', + ); }); }); }); diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardI.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardI.ts index f963fa6cb9e..1d4fffbb341 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardI.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardI.ts @@ -1,68 +1,47 @@ -const joi = require('joi'); -const { - baseExternalDocumentValidation, - externalDocumentDecorator, -} = require('./ExternalDocumentBase'); -const { - joiValidationDecorator, - validEntityDecorator, -} = require('../JoiValidationDecorator'); -const { - transformFormValueToTitleCaseOrdinal, -} = require('../../utilities/transformFormValueToTitleCaseOrdinal'); -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { JoiValidationConstants } = require('../JoiValidationConstants'); -const { replaceBracketed } = require('../../utilities/replaceBracketed'); +import { ExternalDocumentBase } from './ExternalDocumentBase'; +import { JoiValidationConstants } from '../JoiValidationConstants'; +import { replaceBracketed } from '../../utilities/replaceBracketed'; +import { transformFormValueToTitleCaseOrdinal } from '../../utilities/transformFormValueToTitleCaseOrdinal'; +import joi from 'joi'; -/** - * - * @param {object} rawProps the raw document data - * @constructor - */ -function ExternalDocumentNonStandardI() {} +export class ExternalDocumentNonStandardI extends ExternalDocumentBase { + public freeText: string; + public ordinalValue: string; + public otherIteration?: number; -ExternalDocumentNonStandardI.prototype.init = function init(rawProps) { - externalDocumentDecorator(this, rawProps); - this.freeText = rawProps.freeText; - this.ordinalValue = rawProps.ordinalValue; - this.otherIteration = rawProps.otherIteration; -}; + constructor(rawProps) { + super(rawProps, 'ExternalDocumentNonStandardI'); -ExternalDocumentNonStandardI.prototype.getDocumentTitle = function () { - return replaceBracketed( - this.documentTitle, - this.ordinalValue === 'Other' - ? transformFormValueToTitleCaseOrdinal(this.otherIteration) - : transformFormValueToTitleCaseOrdinal(this.ordinalValue), - this.freeText, - ); -}; + this.freeText = rawProps.freeText; + this.ordinalValue = rawProps.ordinalValue; + this.otherIteration = rawProps.otherIteration; + } -ExternalDocumentNonStandardI.VALIDATION_ERROR_MESSAGES = { - ...VALIDATION_ERROR_MESSAGES, -}; + static VALIDATION_RULES = { + ...ExternalDocumentBase.VALIDATION_RULES, + freeText: JoiValidationConstants.STRING.max(1000).required(), + ordinalValue: JoiValidationConstants.STRING.required(), + otherIteration: joi.when('ordinalValue', { + is: 'Other', + otherwise: joi.optional().allow(null), + then: joi.number().max(999).required(), + }), + }; -ExternalDocumentNonStandardI.schema = { - ...baseExternalDocumentValidation, - freeText: JoiValidationConstants.STRING.max(1000).required(), - ordinalValue: JoiValidationConstants.STRING.required(), - otherIteration: joi.when('ordinalValue', { - is: 'Other', - otherwise: joi.optional().allow(null), - then: joi.number().max(999).required(), - }), -}; + getValidationRules() { + return ExternalDocumentNonStandardI.VALIDATION_RULES; + } -joiValidationDecorator( - ExternalDocumentNonStandardI, - ExternalDocumentNonStandardI.schema, - ExternalDocumentNonStandardI.VALIDATION_ERROR_MESSAGES, -); + getDocumentTitle(): string { + return replaceBracketed( + this.documentTitle, + this.ordinalValue === 'Other' + ? transformFormValueToTitleCaseOrdinal(this.otherIteration) + : transformFormValueToTitleCaseOrdinal(this.ordinalValue), + this.freeText, + ); + } +} -module.exports = { - ExternalDocumentNonStandardI: validEntityDecorator( - ExternalDocumentNonStandardI, - ), -}; +export type RawExternalDocumentNonStandardI = + ExcludeMethods; diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardJ.test.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardJ.test.ts index d5984a77e2b..5344b697482 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardJ.test.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardJ.test.ts @@ -1,25 +1,31 @@ -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { ExternalDocumentFactory } = require('./ExternalDocumentFactory'); -const { getTextByCount } = require('../../utilities/getTextByCount'); +import { ExternalDocumentFactory } from './ExternalDocumentFactory'; +import { ExternalDocumentNonStandardJ } from './ExternalDocumentNonStandardJ'; +import { getTextByCount } from '../../utilities/getTextByCount'; describe('ExternalDocumentNonStandardJ', () => { describe('validation', () => { it('should have error messages for missing fields', () => { - const extDoc = ExternalDocumentFactory({ + const exexternalDocumentJDoc = ExternalDocumentFactory({ scenario: 'Nonstandard J', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - category: VALIDATION_ERROR_MESSAGES.category, - documentType: VALIDATION_ERROR_MESSAGES.documentType[1], - freeText: VALIDATION_ERROR_MESSAGES.freeText[0].message, - freeText2: VALIDATION_ERROR_MESSAGES.freeText2[0].message, + + expect(exexternalDocumentJDoc.getFormattedValidationErrors()).toEqual({ + category: + ExternalDocumentNonStandardJ.VALIDATION_ERROR_MESSAGES.category, + documentType: + ExternalDocumentNonStandardJ.VALIDATION_ERROR_MESSAGES + .documentType[1], + freeText: + ExternalDocumentNonStandardJ.VALIDATION_ERROR_MESSAGES.freeText[0] + .message, + freeText2: + ExternalDocumentNonStandardJ.VALIDATION_ERROR_MESSAGES.freeText2[0] + .message, }); }); it('should be valid when all fields are present', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentJ = ExternalDocumentFactory({ category: 'Decision', documentTitle: 'Stipulated Decision Entered [judge] [anything]', documentType: 'Stipulated Decision', @@ -27,11 +33,12 @@ describe('ExternalDocumentNonStandardJ', () => { freeText2: 'Test2', scenario: 'Nonstandard J', }); - expect(extDoc.getFormattedValidationErrors()).toEqual(null); + + expect(externalDocumentJ.getFormattedValidationErrors()).toEqual(null); }); it('should not be valid when freeText or freeText2 is over 1000 characters', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentJ = ExternalDocumentFactory({ category: 'Decision', documentTitle: 'Stipulated Decision Entered [judge] [anything]', documentType: 'Stipulated Decision', @@ -39,14 +46,19 @@ describe('ExternalDocumentNonStandardJ', () => { freeText2: getTextByCount(1001), scenario: 'Nonstandard J', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - freeText: VALIDATION_ERROR_MESSAGES.freeText[1].message, - freeText2: VALIDATION_ERROR_MESSAGES.freeText2[1].message, + + expect(externalDocumentJ.getFormattedValidationErrors()).toEqual({ + freeText: + ExternalDocumentNonStandardJ.VALIDATION_ERROR_MESSAGES.freeText[1] + .message, + freeText2: + ExternalDocumentNonStandardJ.VALIDATION_ERROR_MESSAGES.freeText2[1] + .message, }); }); it('should be invalid when documentTitle is over 3000 characters', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentJ = ExternalDocumentFactory({ category: 'Decision', documentTitle: getTextByCount(3001), documentType: 'Stipulated Decision', @@ -54,15 +66,17 @@ describe('ExternalDocumentNonStandardJ', () => { freeText2: 'Test2', scenario: 'Nonstandard J', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - documentTitle: VALIDATION_ERROR_MESSAGES.documentTitle, + + expect(externalDocumentJ.getFormattedValidationErrors()).toEqual({ + documentTitle: + ExternalDocumentNonStandardJ.VALIDATION_ERROR_MESSAGES.documentTitle, }); }); }); describe('title generation', () => { it('should generate valid title', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentJ = ExternalDocumentFactory({ category: 'Decision', documentTitle: 'Stipulated Decision Entered [judge] [anything]', documentType: 'Stipulated Decision', @@ -70,7 +84,8 @@ describe('ExternalDocumentNonStandardJ', () => { freeText2: 'Test2', scenario: 'Nonstandard J', }); - expect(extDoc.getDocumentTitle()).toEqual( + + expect(externalDocumentJ.getDocumentTitle()).toEqual( 'Stipulated Decision Entered Test Test2', ); }); diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardJ.ts b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardJ.ts index 4a2fa93c677..86b77c321a1 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardJ.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentNonStandardJ.ts @@ -1,52 +1,32 @@ -const { - baseExternalDocumentValidation, - externalDocumentDecorator, -} = require('./ExternalDocumentBase'); -const { - joiValidationDecorator, - validEntityDecorator, -} = require('../JoiValidationDecorator'); -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { JoiValidationConstants } = require('../JoiValidationConstants'); -const { replaceBracketed } = require('../../utilities/replaceBracketed'); +import { ExternalDocumentBase } from './ExternalDocumentBase'; +import { JoiValidationConstants } from '../JoiValidationConstants'; +import { replaceBracketed } from '../../utilities/replaceBracketed'; -/** - * - * @param {object} rawProps the raw document data - * @constructor - */ -function ExternalDocumentNonStandardJ() {} +export class ExternalDocumentNonStandardJ extends ExternalDocumentBase { + public freeText: string; + public freeText2: string; -ExternalDocumentNonStandardJ.prototype.init = function init(rawProps) { - externalDocumentDecorator(this, rawProps); - this.freeText = rawProps.freeText; - this.freeText2 = rawProps.freeText2; -}; + constructor(rawProps) { + super(rawProps, 'ExternalDocumentNonStandardJ'); -ExternalDocumentNonStandardJ.prototype.getDocumentTitle = function () { - return replaceBracketed(this.documentTitle, this.freeText, this.freeText2); -}; + this.freeText = rawProps.freeText; + this.freeText2 = rawProps.freeText2; + } -ExternalDocumentNonStandardJ.VALIDATION_ERROR_MESSAGES = { - ...VALIDATION_ERROR_MESSAGES, -}; + static VALIDATION_RULES = { + ...ExternalDocumentBase.VALIDATION_RULES, + freeText: JoiValidationConstants.STRING.max(1000).required(), + freeText2: JoiValidationConstants.STRING.max(1000).required(), + }; -ExternalDocumentNonStandardJ.schema = { - ...baseExternalDocumentValidation, - freeText: JoiValidationConstants.STRING.max(1000).required(), - freeText2: JoiValidationConstants.STRING.max(1000).required(), -}; + getValidationRules() { + return ExternalDocumentNonStandardJ.VALIDATION_RULES; + } -joiValidationDecorator( - ExternalDocumentNonStandardJ, - ExternalDocumentNonStandardJ.schema, - ExternalDocumentNonStandardJ.VALIDATION_ERROR_MESSAGES, -); + getDocumentTitle(): string { + return replaceBracketed(this.documentTitle, this.freeText, this.freeText2); + } +} -module.exports = { - ExternalDocumentNonStandardJ: validEntityDecorator( - ExternalDocumentNonStandardJ, - ), -}; +export type RawExternalDocumentNonStandardJ = + ExcludeMethods; diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentStandard.test.ts b/shared/src/business/entities/externalDocument/ExternalDocumentStandard.test.ts index 1ca3ffd79f5..29c36bcd0d8 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentStandard.test.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentStandard.test.ts @@ -1,64 +1,75 @@ -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { ExternalDocumentFactory } = require('./ExternalDocumentFactory'); -const { getTextByCount } = require('../../utilities/getTextByCount'); +import { ExternalDocumentFactory } from './ExternalDocumentFactory'; +import { ExternalDocumentStandard } from './ExternalDocumentStandard'; +import { getTextByCount } from '../../utilities/getTextByCount'; describe('ExternalDocumentStandard', () => { describe('validation', () => { it('should have error messages for missing fields', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentStandard = ExternalDocumentFactory({ scenario: 'Standard', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - category: VALIDATION_ERROR_MESSAGES.category, - documentType: VALIDATION_ERROR_MESSAGES.documentType[1], + + expect(externalDocumentStandard.getFormattedValidationErrors()).toEqual({ + category: ExternalDocumentStandard.VALIDATION_ERROR_MESSAGES.category, + documentType: + ExternalDocumentStandard.VALIDATION_ERROR_MESSAGES.documentType[1], }); }); it('should be valid when all fields are present', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentStandard = ExternalDocumentFactory({ category: 'Application', documentTitle: 'Application for Waiver of Filing Fee', documentType: 'Application for Waiver of Filing Fee', scenario: 'Standard', }); - expect(extDoc.getFormattedValidationErrors()).toEqual(null); + + expect(externalDocumentStandard.getFormattedValidationErrors()).toEqual( + null, + ); }); it('should be invalid when documentTitle is over 3000 characters', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentStandard = ExternalDocumentFactory({ category: 'Application', documentTitle: getTextByCount(3001), documentType: 'Application for Waiver of Filing Fee', scenario: 'Standard', }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ - documentTitle: VALIDATION_ERROR_MESSAGES.documentTitle, + + expect(externalDocumentStandard.getFormattedValidationErrors()).toEqual({ + documentTitle: + ExternalDocumentStandard.VALIDATION_ERROR_MESSAGES.documentTitle, }); }); describe('Proposed Stipulated Decision', () => { it('should be allowed to have "Proposed Stipulated Decision"', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentStandard = ExternalDocumentFactory({ category: 'Decision', documentTitle: 'Proposed Stipulated Decision', documentType: 'Proposed Stipulated Decision', scenario: 'Standard', }); - expect(extDoc.getFormattedValidationErrors()).toEqual(null); + + expect(externalDocumentStandard.getFormattedValidationErrors()).toEqual( + null, + ); }); describe('Consolidated Case filing to multiple cases', () => { it('should not be allowed to have "Proposed Stipulated Decision"', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentStandard = ExternalDocumentFactory({ category: 'Decision', documentTitle: 'Proposed Stipulated Decision', documentType: 'Proposed Stipulated Decision', scenario: 'Standard', selectedCases: ['101-19', '102-19'], }); - expect(extDoc.getFormattedValidationErrors()).toEqual({ + + expect( + externalDocumentStandard.getFormattedValidationErrors(), + ).toEqual({ documentType: 'Proposed Stipulated Decision must be filed separately in each case', }); @@ -69,13 +80,14 @@ describe('ExternalDocumentStandard', () => { describe('title generation', () => { it('should generate valid title', () => { - const extDoc = ExternalDocumentFactory({ + const externalDocumentStandard = ExternalDocumentFactory({ category: 'Application', documentTitle: 'Application for Waiver of Filing Fee', documentType: 'Application for Waiver of Filing Fee', scenario: 'Standard', }); - expect(extDoc.getDocumentTitle()).toEqual( + + expect(externalDocumentStandard.getDocumentTitle()).toEqual( 'Application for Waiver of Filing Fee', ); }); diff --git a/shared/src/business/entities/externalDocument/ExternalDocumentStandard.ts b/shared/src/business/entities/externalDocument/ExternalDocumentStandard.ts index baefe882047..5d14cef4207 100644 --- a/shared/src/business/entities/externalDocument/ExternalDocumentStandard.ts +++ b/shared/src/business/entities/externalDocument/ExternalDocumentStandard.ts @@ -1,51 +1,34 @@ -const joi = require('joi'); -const { - baseExternalDocumentValidation, - externalDocumentDecorator, -} = require('./ExternalDocumentBase'); -const { - joiValidationDecorator, - validEntityDecorator, -} = require('../JoiValidationDecorator'); -const { - VALIDATION_ERROR_MESSAGES, -} = require('./ExternalDocumentInformationFactory'); -const { JoiValidationConstants } = require('../JoiValidationConstants'); +import { ExternalDocumentBase } from './ExternalDocumentBase'; +import { JoiValidationConstants } from '../JoiValidationConstants'; +import joi from 'joi'; -/** - * - * @param {object} rawProps the raw document data - * @constructor - */ -function ExternalDocumentStandard() {} -ExternalDocumentStandard.prototype.init = function init(rawProps) { - externalDocumentDecorator(this, rawProps); - this.selectedCases = rawProps.selectedCases; -}; +export class ExternalDocumentStandard extends ExternalDocumentBase { + public selectedCases?: string[]; -ExternalDocumentStandard.prototype.getDocumentTitle = function () { - return this.documentTitle; -}; + constructor(rawProps) { + super(rawProps, 'ExternalDocumentStandard'); -ExternalDocumentStandard.VALIDATION_ERROR_MESSAGES = { - ...VALIDATION_ERROR_MESSAGES, -}; + this.selectedCases = rawProps.selectedCases; + } -ExternalDocumentStandard.schema = joi.object({ - ...baseExternalDocumentValidation, - documentType: JoiValidationConstants.STRING.required().when('selectedCases', { - is: joi.array().min(1).required(), - then: JoiValidationConstants.STRING.invalid('Proposed Stipulated Decision'), - }), - selectedCases: joi.array().items(JoiValidationConstants.STRING).optional(), -}); + static VALIDATION_RULES = { + ...ExternalDocumentBase.VALIDATION_RULES, + documentType: JoiValidationConstants.STRING.required().when( + 'selectedCases', + { + is: joi.array().min(1).required(), + then: JoiValidationConstants.STRING.invalid( + 'Proposed Stipulated Decision', + ), + }, + ), + selectedCases: joi.array().items(JoiValidationConstants.STRING).optional(), + }; -joiValidationDecorator( - ExternalDocumentStandard, - ExternalDocumentStandard.schema, - ExternalDocumentStandard.VALIDATION_ERROR_MESSAGES, -); + getValidationRules() { + return ExternalDocumentStandard.VALIDATION_RULES; + } +} -module.exports = { - ExternalDocumentStandard: validEntityDecorator(ExternalDocumentStandard), -}; +export type RawExternalDocumentStandard = + ExcludeMethods; diff --git a/shared/src/persistence/s3/getDownloadPolicyUrl.test.ts b/shared/src/persistence/s3/getDownloadPolicyUrl.test.ts index ef412618c55..a84c9cced49 100644 --- a/shared/src/persistence/s3/getDownloadPolicyUrl.test.ts +++ b/shared/src/persistence/s3/getDownloadPolicyUrl.test.ts @@ -24,7 +24,6 @@ describe('getDownloadPolicyUrl', () => { applicationContext, filename: 'file.pdf', key: '123', - useTempBucket: false, }); expect(result).toEqual({ url: 'http://localhost' }); @@ -43,6 +42,17 @@ describe('getDownloadPolicyUrl', () => { expect(applicationContext.getTempDocumentsBucketName).toHaveBeenCalled(); }); + it('should return a URL intended for viewing inline in a web browser when filename has NOT been provided', async () => { + const result = await getDownloadPolicyUrl({ + applicationContext, + filename: undefined, + key: '123', + useTempBucket: true, + }); + + expect(result).toEqual({ url: 'http://localhost' }); + }); + it('rejects if an error is thrown', async () => { applicationContext.getStorageClient.mockReturnValue({ getSignedUrl: getSignedUrlErrorMock,