Skip to content

Commit

Permalink
Merge pull request #962 from flexion/latest-with-5311
Browse files Browse the repository at this point in the history
Latest to Migration (with 5311)
  • Loading branch information
matthopson authored Mar 25, 2021
2 parents 872e221 + 4fe1832 commit 908125d
Show file tree
Hide file tree
Showing 18 changed files with 437 additions and 28 deletions.
75 changes: 75 additions & 0 deletions docs/api/v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,37 @@ paths:
$ref: '#/components/responses/NotFoundError'
'500':
$ref: '#/components/responses/ServerError'
/reconciliation-report/{date}:
get:
summary: fetches a list of docket entries served on a date
operationId:
tags:
- irs
description: |
By passing in a date, you can retrieve a list of docket entries served on that date
parameters:
- in: path
name: date
description: A specific date, Eastern time with format YYYY-MM-DD; or 'today'
required: true
schema:
type: string
responses:
'200':
description:
content:
application/json:
schema:
$ref: '#/components/schemas/Report'
'401':
$ref: '#/components/responses/UnauthorizedError'
'403':
$ref: '#/components/responses/ForbiddenError'
'404':
$ref: '#/components/responses/NotFoundError'
'500':
$ref: '#/components/responses/ServerError'
components:
securitySchemes:
bearerAuth:
Expand Down Expand Up @@ -256,3 +287,47 @@ components:
properties:
message:
type: string
Report:
type: object
properties:
docketEntries:
type: array
items:
$ref: '#/components/schemas/ServedDocument'
reportTitle:
type: string
example: Reconciliation Report
totalDocketEntries:
type: number
example: 0
reconcilationDate:
type: string
format: date
example: '2020-03-19'
ServedDocument:
type: object
properties:
docketNumber:
type: string
example: '123-20'
description:
type: string
example: 'Request for Place of Trial at Lubbock, Texas'
docketEntryId:
type: string
example: 'e6ab9240-ed8b-4bde-95a8-eb3bccbd6200'
eventCode:
type: string
example: 'RQT'
filedBy:
type: string
example: 'Petr. John Doe'
filingDate:
type: string
example: '2021-01-26T17:25:38.186Z'
caseCaption:
type: string
example: 'John Doe, Petitioner'
servedAt:
type: string
example: '2021-01-05T21:14:09.031Z'
4 changes: 4 additions & 0 deletions shared/src/authorization/authorizationClientService.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ exports.AUTHORIZATION_MAP = AUTHORIZATION_MAP;
* @returns {boolean} true if user is authorized, false otherwise
*/
exports.isAuthorized = (user, action, owner) => {
if (!user) {
return false;
}

if (user.userId && user.userId === owner) {
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions shared/src/authorization/authorizationClientService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const {
const { ROLES } = require('../business/entities/EntityConstants');

describe('Authorization client service', () => {
it('returns false for undefined user', () => {
expect(isAuthorized(undefined, 'unknown action', 'someUser')).toBeFalsy();
});
it('returns true for any user whose userId matches the 3rd owner argument, in this case "someUser" === "someUser"', () => {
expect(
isAuthorized(
Expand Down
29 changes: 28 additions & 1 deletion shared/src/business/entities/DocketEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const {
EXTERNAL_DOCUMENT_TYPES,
NOTICE_OF_CHANGE_CONTACT_INFORMATION_EVENT_CODES,
PRACTITIONER_ASSOCIATION_DOCUMENT_TYPES,
ROLES,
SERVED_PARTIES_CODES,
TRACKED_DOCUMENT_TYPES_EVENT_CODES,
} = require('./EntityConstants');
const {
Expand Down Expand Up @@ -200,6 +202,7 @@ DocketEntry.prototype.setAsServed = function (servedParties = null) {

if (servedParties) {
this.servedParties = servedParties;
this.servedPartiesCode = getServedPartiesCode(servedParties);
}
};

Expand Down Expand Up @@ -370,4 +373,28 @@ const isServed = function (rawDocketEntry) {
return !!rawDocketEntry.servedAt || !!rawDocketEntry.isLegacyServed;
};

module.exports = { DocketEntry: validEntityDecorator(DocketEntry), isServed };
/**
* Determines the servedPartiesCode based on the given servedParties
*
* @returns {String} served parties code
*/
const getServedPartiesCode = servedParties => {
let servedPartiesCode = '';
if (servedParties && servedParties.length > 0) {
if (
servedParties.length === 1 &&
servedParties[0].role === ROLES.irsSuperuser
) {
servedPartiesCode = SERVED_PARTIES_CODES.RESPONDENT;
} else {
servedPartiesCode = SERVED_PARTIES_CODES.BOTH;
}
}
return servedPartiesCode;
};

module.exports = {
DocketEntry: validEntityDecorator(DocketEntry),
getServedPartiesCode,
isServed,
};
49 changes: 48 additions & 1 deletion shared/src/business/entities/DocketEntry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ const {
ORDER_TYPES,
PETITIONS_SECTION,
ROLES,
SERVED_PARTIES_CODES,
TRANSCRIPT_EVENT_CODE,
} = require('./EntityConstants');
const {
DocketEntry,
getServedPartiesCode,
isServed,
} = require('./DocketEntry');
const { applicationContext } = require('../test/createTestApplicationContext');
const { DocketEntry, isServed } = require('./DocketEntry');
const { omit } = require('lodash');
const { WorkItem } = require('./WorkItem');

Expand Down Expand Up @@ -153,6 +158,48 @@ describe('DocketEntry entity', () => {
});
});

describe('getServedPartiesCode', () => {
it('returns an empty string if servedParties is undefined', () => {
const servedPartiesCode = getServedPartiesCode();
expect(servedPartiesCode).toEqual('');
});

it('returns an empty string if servedParties is an empty array', () => {
const servedPartiesCode = getServedPartiesCode([]);
expect(servedPartiesCode).toEqual('');
});

it('returns the servedParties code for respondent if the only party in the given servedParties array has the irsSuperUser role', () => {
const servedPartiesCode = getServedPartiesCode([
{
role: ROLES.irsSuperuser,
},
]);
expect(servedPartiesCode).toEqual(SERVED_PARTIES_CODES.RESPONDENT);
});

it('returns the servedParties code for both if the only party in the given servedParties array does not have the irsSuperUser role', () => {
const servedPartiesCode = getServedPartiesCode([
{
role: ROLES.petitioner,
},
]);
expect(servedPartiesCode).toEqual(SERVED_PARTIES_CODES.BOTH);
});

it('returns the servedParties code for both if the the given servedParties array contains multiple servedParties', () => {
const servedPartiesCode = getServedPartiesCode([
{
role: ROLES.irsSuperuser,
},
{
role: ROLES.petitioner,
},
]);
expect(servedPartiesCode).toEqual(SERVED_PARTIES_CODES.BOTH);
});
});

describe('signedAt', () => {
it('should implicitly set a signedAt for Notice event codes', () => {
const myDoc = new DocketEntry(
Expand Down
2 changes: 2 additions & 0 deletions shared/src/business/entities/cases/Case.js
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,8 @@ Case.prototype.removePrivatePractitioner = function (practitionerToRemove) {
* @param {object} docketEntryEntity the docket entry to add to the case
*/
Case.prototype.addDocketEntry = function (docketEntryEntity) {
docketEntryEntity.docketNumber = this.docketNumber;

if (docketEntryEntity.isOnDocketRecord) {
const updateIndex = shouldGenerateDocketRecordIndex({
caseDetail: this,
Expand Down
5 changes: 3 additions & 2 deletions shared/src/business/entities/cases/Case.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1576,10 +1576,10 @@ describe('Case entity', () => {
});
});

describe('addDocument', () => {
describe('addDocketEntry', () => {
it('attaches the docket entry to the case', () => {
const caseToVerify = new Case(
{},
{ docketNumber: '123-45' },
{
applicationContext,
},
Expand All @@ -1592,6 +1592,7 @@ describe('Case entity', () => {
expect(caseToVerify.docketEntries.length).toEqual(1);
expect(caseToVerify.docketEntries[0]).toMatchObject({
docketEntryId: '123',
docketNumber: '123-45',
documentType: 'Answer',
userId: 'irsPractitioner',
});
Expand Down
3 changes: 1 addition & 2 deletions shared/src/business/test/createTestApplicationContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const {
formatCase,
formatCaseDeadlines,
formatDocketEntry,
getServedPartiesCode,
sortDocketEntries,
} = require('../../../src/business/utilities/getFormattedCaseDetail');
const {
Expand Down Expand Up @@ -159,7 +158,7 @@ const { filterEmptyStrings } = require('../utilities/filterEmptyStrings');
const { formatDollars } = require('../utilities/formatDollars');
const { getConstants } = require('../../../../web-client/src/getConstants');
const { getItem } = require('../../persistence/localStorage/getItem');
const { isServed } = require('../entities/DocketEntry');
const { getServedPartiesCode, isServed } = require('../entities/DocketEntry');
const { removeItem } = require('../../persistence/localStorage/removeItem');
const { replaceBracketed } = require('../utilities/replaceBracketed');
const { ROLES } = require('../entities/EntityConstants');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const {
const {
ReconciliationReportEntry,
} = require('../entities/ReconciliationReportEntry');
const { map } = require('lodash');
const { UnauthorizedError } = require('../../errors/errors');

const isValidDate = dateString => {
Expand Down Expand Up @@ -89,10 +88,15 @@ const assignCaseCaptionFromPersistence = async (
applicationContext,
docketEntries,
) => {
const docketNumbers = map(docketEntries, 'docketNumber');
const docketNumbers = docketEntries.map(e => {
const docketNumber = e.docketNumber || e.pk.substr(e.pk.indexOf('|') + 1);
e.docketNumber = docketNumber;
return e.docketNumber;
});
const casesDetails = await applicationContext
.getPersistenceGateway()
.getCasesByDocketNumbers({ applicationContext, docketNumbers });

docketEntries.forEach(docketEntry => {
docketEntry.caseCaption = casesDetails.find(
detail => detail.docketNumber === docketEntry.docketNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ describe('getReconciliationReportInteractor', () => {
{
caseCaption: mockCaseCaption,
docketNumber: '135-20',
pk: 'case|135-20',
sk: 'case|135-20',
},
]);
applicationContext.getCurrentUser.mockReturnValue({
Expand Down Expand Up @@ -134,4 +136,33 @@ describe('getReconciliationReportInteractor', () => {
reconciliationDateStart: '2021-01-01T05:00:00.000Z',
});
});

it('should call the getCasesByDocketNumbers method with a docket number extracted from pk if the record has no defined value for the docketNumber attribute', async () => {
const docketEntries = [
{
docketEntryId: '3d27e02e-6954-4595-8b3f-0e91bbc1b51e',
docketNumber: undefined,
documentTitle: 'Petition',
eventCode: 'P',
filedBy: 'Petr. Kaitlin Chaney',
filingDate: '2021-01-05T21:14:09.031Z',
pk: 'case|135-20',
servedAt: '2021-01-05T21:14:09.031Z',
},
];

applicationContext
.getPersistenceGateway()
.getReconciliationReport.mockReturnValue(docketEntries);

const reconciliationDate = '2021-01-01';
await getReconciliationReportInteractor(applicationContext, {
reconciliationDate,
});

expect(
applicationContext.getPersistenceGateway().getCasesByDocketNumbers.mock
.calls[0][0].docketNumbers,
).toEqual(['135-20']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ exports.saveSignedDocumentInteractor = async (
{
createdAt: applicationContext.getUtilities().createISODateString(),
docketEntryId: signedDocketEntryId,
docketNumber: caseRecord.docketNumber,
documentTitle:
SIGNED_DOCUMENT_TYPES.signedStipulatedDecision.documentType,
documentType:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const {
DOCUMENT_PROCESSING_STATUS_OPTIONS,
PETITIONS_SECTION,
SIGNED_DOCUMENT_TYPES,
} = require('../entities/EntityConstants');
const {
saveSignedDocumentInteractor,
Expand Down Expand Up @@ -100,6 +101,12 @@ describe('saveSignedDocumentInteractor', () => {
);

expect(caseEntity.docketEntries.length).toEqual(MOCK_DOCUMENTS.length + 1);
const signedDocument = caseEntity.docketEntries.find(
e =>
e.documentType ===
SIGNED_DOCUMENT_TYPES.signedStipulatedDecision.documentType,
);
expect(signedDocument.docketNumber).toEqual(caseEntity.docketNumber);

const signedDocketEntryEntity = caseEntity.docketEntries.find(
doc =>
Expand Down
19 changes: 1 addition & 18 deletions shared/src/business/utilities/getFormattedCaseDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,7 @@ const {
} = require('../entities/EntityConstants');
const { Case } = require('../entities/cases/Case');
const { cloneDeep, isEmpty, sortBy } = require('lodash');
const { isServed } = require('../entities/DocketEntry');
const { ROLES } = require('../entities/EntityConstants');

const getServedPartiesCode = servedParties => {
let servedPartiesCode = '';
if (servedParties && servedParties.length > 0) {
if (
servedParties.length === 1 &&
servedParties[0].role === ROLES.irsSuperuser
) {
servedPartiesCode = SERVED_PARTIES_CODES.RESPONDENT;
} else {
servedPartiesCode = SERVED_PARTIES_CODES.BOTH;
}
}
return servedPartiesCode;
};
const { getServedPartiesCode, isServed } = require('../entities/DocketEntry');

const TRANSCRIPT_AGE_DAYS_MIN = 90;
const documentMeetsAgeRequirements = doc => {
Expand Down Expand Up @@ -596,6 +580,5 @@ module.exports = {
formatDocketEntry,
getFilingsAndProceedings,
getFormattedCaseDetail,
getServedPartiesCode,
sortDocketEntries,
};
Loading

0 comments on commit 908125d

Please sign in to comment.