diff --git a/docs/entities/Case.md b/docs/entities/Case.md index bc5b18de7be..2d5502cd934 100644 --- a/docs/entities/Case.md +++ b/docs/entities/Case.md @@ -1387,6 +1387,7 @@ presence: "optional" allow: - "" + - null otherwise: type: "any" flags: @@ -1397,6 +1398,7 @@ presence: "optional" allow: - "" + - null filingDate: type: "date" flags: @@ -5505,6 +5507,7 @@ presence: "optional" allow: - "" + - null otherwise: type: "any" flags: @@ -5515,6 +5518,7 @@ presence: "optional" allow: - "" + - null filingDate: type: "date" flags: diff --git a/docs/entities/CaseInternal.md b/docs/entities/CaseInternal.md index ef2833203f2..eeff41e3e8c 100644 --- a/docs/entities/CaseInternal.md +++ b/docs/entities/CaseInternal.md @@ -1394,6 +1394,7 @@ presence: "optional" allow: - "" + - null otherwise: type: "any" flags: @@ -1404,6 +1405,7 @@ presence: "optional" allow: - "" + - null filingDate: type: "date" flags: diff --git a/docs/entities/Document.md b/docs/entities/Document.md index 7132aa9ebc5..bd1434b95c4 100644 --- a/docs/entities/Document.md +++ b/docs/entities/Document.md @@ -1293,6 +1293,7 @@ presence: "optional" allow: - "" + - null otherwise: type: "any" flags: @@ -1303,6 +1304,7 @@ presence: "optional" allow: - "" + - null filingDate: type: "date" flags: diff --git a/shared/src/business/entities/Document.js b/shared/src/business/entities/Document.js index 2aafe23dc03..64be60b0db4 100644 --- a/shared/src/business/entities/Document.js +++ b/shared/src/business/entities/Document.js @@ -262,7 +262,7 @@ Document.VALIDATION_RULES = joi.object().keys({ ...EXTERNAL_DOCUMENT_TYPES, ...INTERNAL_DOCUMENT_TYPES, ), - otherwise: joi.allow('').optional(), + otherwise: joi.allow('', null).optional(), then: joi.when('documentType', { is: JoiValidationConstants.STRING.valid( ...AUTOGENERATED_EXTERNAL_DOCUMENT_TYPES, @@ -271,7 +271,7 @@ Document.VALIDATION_RULES = joi.object().keys({ otherwise: joi.required(), then: joi.when('isAutoGenerated', { is: false, - otherwise: joi.allow('').optional(), + otherwise: joi.allow('', null).optional(), then: joi.required(), }), }), diff --git a/shared/src/business/entities/Document.test.js b/shared/src/business/entities/Document.test.js index 8b4d229553a..9bba34d02ee 100644 --- a/shared/src/business/entities/Document.test.js +++ b/shared/src/business/entities/Document.test.js @@ -248,6 +248,95 @@ describe('Document entity', () => { expect(error).toBeDefined(); }); + it('should not throw an error on valid documents', () => { + let error; + try { + new Document( + { + createdAt: '2019-03-27T00:00:00.000-04:00', + documentId: '0ed63e9d-8fb5-4a55-b268-a7cd10d7cbcd', + documentTitle: + 'ORDER THAT PETR. BY 4/18/19 FILE, UNDER SEAL, A RESPONSE TO THIS ORDER AS STATED HEREIN.', + documentType: 'Order', + entityName: 'Document', + eventCode: 'O', + filedBy: null, + filingDate: '2019-03-27T00:00:00.000-04:00', + isDraft: false, + isFileAttached: true, + isLegacy: true, + isLegacySealed: false, + isSealed: false, + judge: 'Mock Judge', + pending: false, + processingStatus: 'pending', + receivedAt: '2020-08-21T20:07:44.018Z', + servedAt: '2019-03-28T00:00:00.000-04:00', + servedParties: [ + { + name: 'Bernard Lowe', + }, + { + name: 'IRS', + role: 'irsSuperuser', + }, + ], + signedAt: 'Not in Blackstone', + signedByUserId: 'a11077ed-c01d-4add-ab1e-da7aba5eda7a', + signedJudgeName: 'Mock Signed Judge', + userId: 'a11077ed-c01d-4add-ab1e-da7aba5eda7a', + }, + { applicationContext }, + ).validate(); + } catch (err) { + error = err; + } + expect(error).toBeUndefined(); + + try { + new Document( + { + createdAt: '2019-03-27T00:00:00.000-04:00', + documentId: '0ed63e9d-8fb5-4a55-b268-a7cd10d7cbcd', + documentTitle: + 'ORDER THAT PETR. BY 4/18/19 FILE, UNDER SEAL, A RESPONSE TO THIS ORDER AS STATED HEREIN.', + documentType: 'Order', + entityName: 'Document', + eventCode: 'O', + filedBy: '', + filingDate: '2019-03-27T00:00:00.000-04:00', + isDraft: false, + isFileAttached: true, + isLegacy: true, + isLegacySealed: false, + isSealed: false, + judge: 'Mock Judge', + pending: false, + processingStatus: 'pending', + receivedAt: '2020-08-21T20:07:44.018Z', + servedAt: '2019-03-28T00:00:00.000-04:00', + servedParties: [ + { + name: 'Bernard Lowe', + }, + { + name: 'IRS', + role: 'irsSuperuser', + }, + ], + signedAt: 'Not in Blackstone', + signedByUserId: 'a11077ed-c01d-4add-ab1e-da7aba5eda7a', + signedJudgeName: 'Mock Signed Judge', + userId: 'a11077ed-c01d-4add-ab1e-da7aba5eda7a', + }, + { applicationContext }, + ).validate(); + } catch (err) { + error = err; + } + expect(error).toBeUndefined(); + }); + it('should correctly validate with a secondaryDate', () => { const document = new Document( {