Skip to content

Commit

Permalink
Merge pull request #5599 from flexion/4611-submit-create-order
Browse files Browse the repository at this point in the history
4611: submit order from message and add as attachment
  • Loading branch information
rachaelparris authored Jun 24, 2020
2 parents e290c4e + 2298ea8 commit 4b8ba2f
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 3 deletions.
6 changes: 6 additions & 0 deletions shared/src/business/entities/CaseMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,10 @@ CaseMessage.prototype.markAsCompleted = function ({ message, user }) {
return this;
};

CaseMessage.prototype.addAttachment = function (attachmentToAdd) {
this.attachments.push(attachmentToAdd);

return this;
};

module.exports = { CaseMessage };
38 changes: 37 additions & 1 deletion shared/src/business/entities/CaseMessage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,43 @@ describe('CaseMessage', () => {
createdAt: expect.anything(),
isCompleted: true,
});
expect(1).toEqual(1);
});
});

describe('addAttachment', () => {
it('should add the passed in attachment to the attachments array', () => {
const message = new CaseMessage(
{
caseId: '3079c990-cc6c-4b99-8fca-8e31f2d9e7a8',
caseStatus: 'General Docket - Not at Issue',
caseTitle: 'Test Petitioner',
createdAt: '2019-01-01T17:29:13.122Z',
docketNumber: '123-45',
docketNumberWithSuffix: '123-45S',
from: 'gg',
fromSection: 'petitions',
fromUserId: '6805d1ab-18d0-43ec-bafb-654e83405416',
message: 'hello world',
subject: 'hey!',
to: 'bob',
toSection: 'petitions',
toUserId: '6805d1ab-18d0-43ec-bafb-654e83405416',
},
{ applicationContext },
);

message.addAttachment({
documentId: '1f63acc7-d3f1-4115-9310-0570559a023a',
documentTitle: 'Petition',
});

expect(message.isValid()).toBeTruthy();
expect(message.attachments).toMatchObject([
{
documentId: '1f63acc7-d3f1-4115-9310-0570559a023a',
documentTitle: 'Petition',
},
]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {
ROLE_PERMISSIONS,
} = require('../../../authorization/authorizationClientService');
const { Case } = require('../../entities/cases/Case');
const { CaseMessage } = require('../../entities/CaseMessage');
const { Document } = require('../../entities/Document');
const { UnauthorizedError } = require('../../../errors/errors');

Expand Down Expand Up @@ -123,5 +124,28 @@ exports.fileCourtIssuedOrderInteractor = async ({
caseToUpdate: caseEntity.validate().toRawObject(),
});

if (documentMetadata.messageId) {
const message = await applicationContext
.getPersistenceGateway()
.getCaseMessage({
applicationContext,
caseId,
messageId: documentMetadata.messageId,
});

const caseMessageEntity = new CaseMessage(message, {
applicationContext,
}).validate();
caseMessageEntity.addAttachment({
documentId: documentEntity.documentId,
documentTitle: documentEntity.documentTitle,
});

await applicationContext.getPersistenceGateway().updateCaseMessage({
applicationContext,
caseMessage: caseMessageEntity.validate().toRawObject(),
});
}

return caseEntity.toRawObject();
};
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('fileCourtIssuedOrderInteractor', () => {
preferredTrialCity: 'Fresno, California',
procedureType: 'Regular',
role: ROLES.petitioner,
status: 'New',
userId: 'ddd6c900-388b-4151-8014-b3378076bfb0',
};

Expand Down Expand Up @@ -250,6 +251,55 @@ describe('fileCourtIssuedOrderInteractor', () => {
).not.toEqual(-1);
});

it('should add order document to case message if a messageId is passed in', async () => {
applicationContext.getPersistenceGateway().getCaseMessage.mockReturnValue({
caseId: caseRecord.caseId,
caseStatus: caseRecord.status,
caseTitle: 'Petitioner',
createdAt: '2019-03-01T21:40:46.415Z',
docketNumber: caseRecord.docketNumber,
from: 'Test Petitionsclerk',
fromSection: 'petitions',
fromUserId: '4791e892-14ee-4ab1-8468-0c942ec379d2',
message: 'hey there',
messageId: 'a10d6855-f3ee-4c11-861c-c7f11cba4dff',
parentMessageId: '31687a1e-3640-42cd-8e7e-a8e6df39ce9a',
subject: 'hello',
to: 'Test Petitionsclerk2',
toSection: 'petitions',
toUserId: '449b916e-3362-4a5d-bf56-b2b94ba29c12',
});

await fileCourtIssuedOrderInteractor({
applicationContext,
documentMetadata: {
caseId: caseRecord.caseId,
docketNumber: '45678-18',
documentTitle: 'Order to do anything',
documentType: 'Order',
eventCode: 'O',
messageId: '6c1fd626-c1e1-4367-bca6-e00f9ef98cf5',
signedAt: '2019-03-01T21:40:46.415Z',
signedByUserId: mockUserId,
signedJudgeName: 'Dredd',
},
primaryDocumentFileId: 'c54ba5a9-b37b-479d-9201-067ec6e335bb',
});

expect(
applicationContext.getPersistenceGateway().updateCaseMessage,
).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().updateCaseMessage.mock
.calls[0][0].caseMessage.attachments,
).toEqual([
{
documentId: 'c54ba5a9-b37b-479d-9201-067ec6e335bb',
documentTitle: 'Order to do anything',
},
]);
});

it('should throw an error if fails to parse pdf', async () => {
applicationContext
.getUtilities()
Expand Down
20 changes: 20 additions & 0 deletions shared/src/persistence/dynamo/messages/getCaseMessage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { get } = require('../../dynamodbClientService');

/**
* getCaseMessage
*
* @param {object} providers the providers object
* @param {object} providers.applicationContext the application context
* @param {string} providers.caseId the id of the case
* @param {string} providers.messageId the id of the message
* @returns {object} the created case message
*/
exports.getCaseMessage = async ({ applicationContext, caseId, messageId }) => {
return await get({
Key: {
pk: `case|${caseId}`,
sk: `message|${messageId}`,
},
applicationContext,
});
};
37 changes: 37 additions & 0 deletions shared/src/persistence/dynamo/messages/getCaseMessage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const {
applicationContext,
} = require('../../../business/test/createTestApplicationContext');
const { getCaseMessage } = require('./getCaseMessage');

const mockCaseMessage = {
caseId: 'b3f09a45-b27c-4383-acc1-2ab1f99e6725',
createdAt: '2019-03-01T21:40:46.415Z',
from: 'Test Petitionsclerk',
fromSection: 'petitions',
fromUserId: '4791e892-14ee-4ab1-8468-0c942ec379d2',
message: 'hey there',
messageId: 'a10d6855-f3ee-4c11-861c-c7f11cba4dff',
subject: 'hello',
to: 'Test Petitionsclerk2',
toSection: 'petitions',
toUserId: '449b916e-3362-4a5d-bf56-b2b94ba29c12',
};

describe('getCaseMessage', () => {
beforeAll(() => {
applicationContext.environment.stage = 'dev';
applicationContext.getDocumentClient().get.mockReturnValue({
promise: () => Promise.resolve({ Item: mockCaseMessage }),
});
});

it('retrieves the case message from persistence', async () => {
const retrievedMessage = await getCaseMessage({
applicationContext,
caseId: mockCaseMessage.caseId,
messageId: mockCaseMessage.messageId,
});

expect(retrievedMessage).toEqual(mockCaseMessage);
});
});
4 changes: 4 additions & 0 deletions web-api/src/applicationContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ const {
const {
getCaseInventoryReportInteractor,
} = require('../../shared/src/business/useCases/caseInventoryReport/getCaseInventoryReportInteractor');
const {
getCaseMessage,
} = require('../../shared/src/persistence/dynamo/messages/getCaseMessage');
const {
getCaseMessagesByCaseId,
} = require('../../shared/src/persistence/dynamo/messages/getCaseMessagesByCaseId');
Expand Down Expand Up @@ -1241,6 +1244,7 @@ module.exports = appContextUser => {
getCaseByDocketNumber,
getCaseDeadlinesByCaseId,
getCaseInventoryReport,
getCaseMessage,
getCaseMessageThreadByParentId,
getCaseMessagesByCaseId,
getCasesByCaseIds,
Expand Down
4 changes: 2 additions & 2 deletions web-api/storage/fixtures/seed/case-messages.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"caseId": "0bc59d5b-c2b9-41f7-92a7-03b8cadffcc0",
"caseId": "28caad58-df69-4a4d-af15-6554aee7fbd6",
"caseStatus": "General Docket - Not at Issue",
"createdAt": "2020-06-05T18:02:25.280Z",
"caseTitle": "Bill Burr",
Expand All @@ -13,7 +13,7 @@
"gsi1pk": "message|eb0a139a-8951-4de1-8b83-f02a27504105",
"message": "hello!",
"messageId": "eb0a139a-8951-4de1-8b83-f02a27504105",
"pk": "case|0bc59d5b-c2b9-41f7-92a7-03b8cadffcc0",
"pk": "case|28caad58-df69-4a4d-af15-6554aee7fbd6",
"sk": "message|eb0a139a-8951-4de1-8b83-f02a27504105",
"parentMessageId": "eb0a139a-8951-4de1-8b83-f02a27504105",
"subject": "message to myself",
Expand Down

0 comments on commit 4b8ba2f

Please sign in to comment.