Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9684 Message Display: Display Place and Date of Trial Session When Case is Calendared #2894

Merged
merged 36 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
82ec8d7
9684: adding barebones test for story [skip ci]
mrinsin Dec 5, 2022
ee7cc44
9684: Add more setup to integration test [skip ci]
rachelschneiderman Dec 5, 2022
8a0bba8
9684: adding failing expectations and updating ES case mappings
mrinsin Dec 5, 2022
e89aeda
9684: add trialDate and trialLocation to GET_PARENT_CLAUSE includes a…
shumway-tm Dec 5, 2022
2bf466c
9684: ccreating message decorator to use for inheritance
mrinsin Dec 5, 2022
5ed6ecf
9684: Add DTO for messages [skip ci]
rachelschneiderman Dec 5, 2022
e6ce4bb
9684: added properties that are unique to MessageResult
shumway-tm Dec 5, 2022
7ac6f36
9684: adding more steps before calendaring trial session [skip ci]
mrinsin Dec 5, 2022
450267e
9684: use seed data for calendared case instead of generating dynamic…
shumway-tm Dec 5, 2022
ab1e32d
9684: failing test, receiving undefined [skip ci]
mrinsin Dec 5, 2022
96e878d
9684: initial integration test now green, used MessageResult entity i…
shumway-tm Dec 5, 2022
163e111
9864: writing expectation intentionally [skip ci]
mrinsin Dec 5, 2022
b6b3e48
9684: continue work on unit test for formattedMessages [skip ci]
shumway-tm Dec 5, 2022
5b07711
9684: updating test to check for flag [skip ci]
mrinsin Dec 5, 2022
9899dc1
9684: continue work on unit test
shumway-tm Dec 5, 2022
4e025de
9684: updating to use correct property [skip ci]
mrinsin Dec 5, 2022
42c9c0e
9684: format trialDate to mm/dd/yy
shumway-tm Dec 5, 2022
7aca377
9684: format state to abbreviation, use formatted values in jsx
shumway-tm Dec 6, 2022
997fe74
9684: extracting abbreviation code to utility method
mrinsin Dec 6, 2022
7281c26
9684: add unit test for abbreviateState helper
shumway-tm Dec 6, 2022
fc18862
9684: only formatting trial info is status is calendared, adding tests
mrinsin Dec 6, 2022
5fc4739
9684: add changes to each box and the interactors that feed them, fix…
shumway-tm Dec 6, 2022
7a252a0
9684: fixing failing test
mrinsin Dec 6, 2022
b2570e6
9864: adding validation rules
mrinsin Dec 6, 2022
9d9c38a
9684: fixing lint errors
mrinsin Dec 7, 2022
acdd152
9684: create test for new MessageResult entity
shumway-tm Dec 7, 2022
1f552a1
9684: adding coverage and only abbreviating state if not standalone r…
mrinsin Dec 7, 2022
fa008c8
9684: adding integration tests
mrinsin Dec 7, 2022
fdb62d0
Merge remote-tracking branch 'ustc/test' into 9684-to-test
mrinsin Dec 7, 2022
ec8cd93
9684: fix message interactor tests
shumway-tm Dec 7, 2022
62337d4
9684: fix message interactor tests
shumway-tm Dec 7, 2022
c3ff4a8
9684 - fixing deploy issue on new environment missing cognito pool
codyseibert Dec 8, 2022
83b792a
9684: addressing PR feedback
mrinsin Dec 9, 2022
3232a92
Merge branch '9684-message-display-story' into 9684-to-test
mrinsin Dec 9, 2022
1a3dfd3
Merge remote-tracking branch 'ustc/test' into 9684-to-test
mrinsin Dec 9, 2022
3043357
Revert "9684 - fixing deploy issue on new environment missing cognito…
mrinsin Dec 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 43 additions & 28 deletions shared/src/business/entities/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,49 @@ function Message() {
}

Message.prototype.init = function init(rawMessage, { applicationContext }) {
messageDecorator(this, rawMessage, { applicationContext });
};

const messageDecorator = (
messageEntity,
rawMessage,
{ applicationContext },
) => {
if (!applicationContext) {
throw new TypeError('applicationContext must be defined');
}

this.attachments = (rawMessage.attachments || []).map(attachment => ({
documentId: attachment.documentId,
}));
this.caseStatus = rawMessage.caseStatus;
this.caseTitle = rawMessage.caseTitle;
this.completedAt = rawMessage.completedAt;
this.completedBy = rawMessage.completedBy;
this.completedBySection = rawMessage.completedBySection;
this.completedByUserId = rawMessage.completedByUserId;
this.completedMessage = rawMessage.completedMessage;
this.createdAt = rawMessage.createdAt || createISODateString();
this.leadDocketNumber = rawMessage.leadDocketNumber;
this.docketNumber = rawMessage.docketNumber;
this.docketNumberWithSuffix = rawMessage.docketNumberWithSuffix;
this.from = rawMessage.from;
this.fromSection = rawMessage.fromSection;
this.fromUserId = rawMessage.fromUserId;
this.isCompleted = rawMessage.isCompleted || false;
this.isRead = rawMessage.isRead || false;
this.isRepliedTo = rawMessage.isRepliedTo || false;
this.message = rawMessage.message;
this.messageId = rawMessage.messageId || applicationContext.getUniqueId();
this.parentMessageId = rawMessage.parentMessageId || this.messageId;
this.subject = rawMessage.subject;
this.to = rawMessage.to;
this.toSection = rawMessage.toSection;
this.toUserId = rawMessage.toUserId;
messageEntity.attachments = (rawMessage.attachments || []).map(
attachment => ({
documentId: attachment.documentId,
}),
);
messageEntity.caseStatus = rawMessage.caseStatus;
messageEntity.caseTitle = rawMessage.caseTitle;
messageEntity.completedAt = rawMessage.completedAt;
messageEntity.completedBy = rawMessage.completedBy;
messageEntity.completedBySection = rawMessage.completedBySection;
messageEntity.completedByUserId = rawMessage.completedByUserId;
messageEntity.completedMessage = rawMessage.completedMessage;
messageEntity.createdAt = rawMessage.createdAt || createISODateString();
messageEntity.leadDocketNumber = rawMessage.leadDocketNumber;
messageEntity.docketNumber = rawMessage.docketNumber;
messageEntity.docketNumberWithSuffix = rawMessage.docketNumberWithSuffix;
messageEntity.from = rawMessage.from;
messageEntity.fromSection = rawMessage.fromSection;
messageEntity.fromUserId = rawMessage.fromUserId;
messageEntity.isCompleted = rawMessage.isCompleted || false;
messageEntity.isRead = rawMessage.isRead || false;
messageEntity.isRepliedTo = rawMessage.isRepliedTo || false;
messageEntity.message = rawMessage.message;
messageEntity.messageId =
rawMessage.messageId || applicationContext.getUniqueId();
messageEntity.parentMessageId =
rawMessage.parentMessageId || messageEntity.messageId;
messageEntity.subject = rawMessage.subject;
messageEntity.to = rawMessage.to;
messageEntity.toSection = rawMessage.toSection;
messageEntity.toUserId = rawMessage.toUserId;
};

Message.VALIDATION_ERROR_MESSAGES = {
Expand Down Expand Up @@ -205,4 +217,7 @@ Message.prototype.addAttachment = function (attachmentToAdd) {
return this;
};

exports.Message = validEntityDecorator(Message);
module.exports = {
Message: validEntityDecorator(Message),
messageDecorator,
};
56 changes: 56 additions & 0 deletions shared/src/business/entities/MessageResult.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const joi = require('joi');
const {
joiValidationDecorator,
validEntityDecorator,
} = require('./JoiValidationDecorator');
const {
TRIAL_CITY_STRINGS,
TRIAL_LOCATION_MATCHER,
} = require('./EntityConstants');
const { JoiValidationConstants } = require('./JoiValidationConstants');
const { messageDecorator } = require('./Message');

/**
* constructor
*
* @param {object} rawMessage the raw message data
* @constructor
*/
function MessageResult() {
this.entityName = 'MessageResult';
}

MessageResult.prototype.init = function init(
rawMessage,
{ applicationContext },
) {
messageDecorator(this, rawMessage, { applicationContext });
this.trialDate = rawMessage.trialDate;
this.trialLocation = rawMessage.trialLocation;
};

MessageResult.VALIDATION_RULES = {
trialDate: joi
.alternatives()
.optional()
.description('When this case goes to trial.'),
trialLocation: joi
.alternatives()
.try(
JoiValidationConstants.STRING.valid(...TRIAL_CITY_STRINGS, null),
JoiValidationConstants.STRING.pattern(TRIAL_LOCATION_MATCHER),
JoiValidationConstants.STRING.valid('Standalone Remote'),
)
.optional()
.description(
'Where this case goes to trial. This may be different that the preferred trial location.',
),
};

joiValidationDecorator(
MessageResult,
joi.object().keys(MessageResult.VALIDATION_RULES),
MessageResult.VALIDATION_ERROR_MESSAGES,
);

exports.MessageResult = validEntityDecorator(MessageResult);
47 changes: 47 additions & 0 deletions shared/src/business/entities/MessageResult.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { applicationContext } = require('../test/createTestApplicationContext');
const { CASE_STATUS_TYPES, PETITIONS_SECTION } = require('./EntityConstants');
const { MessageResult } = require('./MessageResult');

describe('MessageResult', () => {
const mockRawMessageResult = {
caseStatus: CASE_STATUS_TYPES.generalDocket,
caseTitle: 'The Land Before Time',
createdAt: '2019-03-01T21:40:46.415Z',
docketNumber: '123-20',
docketNumberWithSuffix: '123-45S',
from: 'Test Petitionsclerk',
fromSection: PETITIONS_SECTION,
fromUserId: '4791e892-14ee-4ab1-8468-0c942ec379d2',
isCompleted: false,
isRead: false,
isRepliedTo: false,
message: 'hey there',
messageId: 'a10d6855-f3ee-4c11-861c-c7f11cba4dff',
parentMessageId: '31687a1e-3640-42cd-8e7e-a8e6df39ce9a',
subject: 'hello',
to: 'Test Petitionsclerk2',
toSection: PETITIONS_SECTION,
toUserId: '449b916e-3362-4a5d-bf56-b2b94ba29c12',
trialDate: '2029-03-01T21:40:46.415Z',
trialLocation: 'Denver, Colorado',
};

it('should create a valid MessageResult', () => {
const messageResult = new MessageResult(mockRawMessageResult, {
applicationContext,
});

expect(messageResult.isValid()).toBeTruthy();
});

it('should fail validation when trialLocation is not one of TRIAL_CITY_STRINGS or StandaloneRemote', () => {
const messageResult = new MessageResult(
{ ...mockRawMessageResult, trialLocation: 'New Delhi, India' },
{
applicationContext,
},
);

expect(messageResult.isValid()).toBeFalsy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('getInboxMessagesForSectionInteractor', () => {
createdAt: '2019-03-01T21:40:46.415Z',
docketNumber: '123-45',
docketNumberWithSuffix: '123-45S',
entityName: 'Message',
entityName: 'MessageResult',
from: 'Test Petitionsclerk2',
fromSection: PETITIONS_SECTION,
fromUserId: 'fe6eeadd-e4e8-4e56-9ddf-0ebe9516df6b',
Expand All @@ -44,6 +44,8 @@ describe('getInboxMessagesForSectionInteractor', () => {
to: 'Test Petitionsclerk',
toSection: PETITIONS_SECTION,
toUserId: 'b427ca37-0df1-48ac-94bb-47aed073d6f7',
trialDate: '2028-03-01T21:40:46.415Z',
trialLocation: 'El Paso, Texas',
};
applicationContext.getCurrentUser.mockReturnValue({
role: ROLES.petitionsClerk,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message } from '../../entities/Message';
import { MessageResult } from '../../entities/MessageResult';
import {
ROLE_PERMISSIONS,
isAuthorized,
Expand Down Expand Up @@ -30,7 +30,7 @@ export const getInboxMessagesForSectionInteractor = async (
section,
});

return Message.validateRawCollection(messages, {
return MessageResult.validateRawCollection(messages, {
applicationContext,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('getInboxMessagesForUserInteractor', () => {
createdAt: '2019-03-01T21:40:46.415Z',
docketNumber: '123-45',
docketNumberWithSuffix: '123-45S',
entityName: 'Message',
entityName: 'MessageResult',
from: 'Test Petitionsclerk2',
fromSection: PETITIONS_SECTION,
fromUserId: 'fe6eeadd-e4e8-4e56-9ddf-0ebe9516df6b',
Expand All @@ -44,6 +44,8 @@ describe('getInboxMessagesForUserInteractor', () => {
to: 'Test Petitionsclerk',
toSection: PETITIONS_SECTION,
toUserId: 'b427ca37-0df1-48ac-94bb-47aed073d6f7',
trialDate: '2028-03-01T21:40:46.415Z',
trialLocation: 'El Paso, Texas',
};
applicationContext.getCurrentUser.mockReturnValue({
role: ROLES.petitionsClerk,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message } from '../../entities/Message';
import { MessageResult } from '../../entities/MessageResult';
import {
ROLE_PERMISSIONS,
isAuthorized,
Expand Down Expand Up @@ -30,7 +30,7 @@ export const getInboxMessagesForUserInteractor = async (
userId,
});

return Message.validateRawCollection(messages, {
return MessageResult.validateRawCollection(messages, {
applicationContext,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('getOutboxMessagesForSectionInteractor', () => {
createdAt: '2019-03-01T21:40:46.415Z',
docketNumber: '123-45',
docketNumberWithSuffix: '123-45S',
entityName: 'Message',
entityName: 'MessageResult',
from: 'Test Petitionsclerk2',
fromSection: PETITIONS_SECTION,
fromUserId: 'fe6eeadd-e4e8-4e56-9ddf-0ebe9516df6b',
Expand All @@ -44,6 +44,8 @@ describe('getOutboxMessagesForSectionInteractor', () => {
to: 'Test Petitionsclerk',
toSection: PETITIONS_SECTION,
toUserId: 'b427ca37-0df1-48ac-94bb-47aed073d6f7',
trialDate: '2028-03-01T21:40:46.415Z',
trialLocation: 'El Paso, Texas',
};
applicationContext.getCurrentUser.mockReturnValue({
role: ROLES.petitionsClerk,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message } from '../../entities/Message';
import { MessageResult } from '../../entities/MessageResult';
import {
ROLE_PERMISSIONS,
isAuthorized,
Expand Down Expand Up @@ -30,7 +30,7 @@ export const getOutboxMessagesForSectionInteractor = async (
section,
});

return Message.validateRawCollection(messages, {
return MessageResult.validateRawCollection(messages, {
applicationContext,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('getOutboxMessagesForUserInteractor', () => {
createdAt: '2019-03-01T21:40:46.415Z',
docketNumber: '123-45',
docketNumberWithSuffix: '123-45S',
entityName: 'Message',
entityName: 'MessageResult',
from: 'Test Petitionsclerk2',
fromSection: PETITIONS_SECTION,
fromUserId: 'fe6eeadd-e4e8-4e56-9ddf-0ebe9516df6b',
Expand All @@ -44,6 +44,8 @@ describe('getOutboxMessagesForUserInteractor', () => {
to: 'Test Petitionsclerk',
toSection: PETITIONS_SECTION,
toUserId: 'b427ca37-0df1-48ac-94bb-47aed073d6f7',
trialDate: '2028-03-01T21:40:46.415Z',
trialLocation: 'El Paso, Texas',
};
applicationContext.getCurrentUser.mockReturnValue({
role: ROLES.petitionsClerk,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message } from '../../entities/Message';
import { MessageResult } from '../../entities/MessageResult';
import {
ROLE_PERMISSIONS,
isAuthorized,
Expand Down Expand Up @@ -30,7 +30,7 @@ export const getOutboxMessagesForUserInteractor = async (
userId,
});

return Message.validateRawCollection(messages, {
return MessageResult.validateRawCollection(messages, {
applicationContext,
});
};
20 changes: 20 additions & 0 deletions shared/src/business/utilities/abbreviateState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { US_STATES } from '../entities/EntityConstants';
import { invert } from 'lodash';

/**
* abbreviates the state given a string with a comma separated city and state
*
* @param {string} locationString the location string to format
* @returns {string} a formatted string with the abbreviated state
*/
const abbreviateState = locationString => {
const cityAndState = locationString.split(', ');
const stateAbbreviation = invert(US_STATES)[cityAndState[1]];
const formattedCityAndState = `${cityAndState[0]}, ${stateAbbreviation}`;

return formattedCityAndState;
};

module.exports = {
abbreviateState,
};
12 changes: 12 additions & 0 deletions shared/src/business/utilities/abbreviateState.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { abbreviateState } = require('./abbreviateState');

describe('abbreviateState', () => {
it('should return a string with an abbreviated state when passed a comma separated city and unabbreviated state', () => {
const locationString = 'Denver, Colorado';
const expectedResult = 'Denver, CO';

const result = abbreviateState(locationString);

expect(result).toEqual(expectedResult);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ const GET_PARENT_CASE = {
has_parent: {
inner_hits: {
_source: {
includes: ['leadDocketNumber', 'docketNumber'],
includes: [
'leadDocketNumber',
'docketNumber',
'trialDate',
'trialLocation',
],
},
name: 'case-mappings',
},
Expand Down
6 changes: 6 additions & 0 deletions web-api/elasticsearch/efcms-case-mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ module.exports = {
'status.S': {
type: 'keyword',
},
'trialDate.S': {
type: 'date',
},
'trialLocation.S': {
type: 'keyword',
},
'userId.S': {
type: 'keyword',
},
Expand Down
9 changes: 8 additions & 1 deletion web-api/storage/fixtures/seed/efcms-local.json
Original file line number Diff line number Diff line change
Expand Up @@ -4552,7 +4552,14 @@
"partySecondary": false,
"pk": "case|103-20",
"documentTitle": "Petition",
"docketNumber": "103-20"
"docketNumber": "103-20",
"servedParties": [
{
"name": "Reuben Blair",
"email": "petitioner@example.com"
}
],
"servedAt": "2020-09-25T19:27:16.630Z"
},
{
"isStricken": false,
Expand Down
Loading