Skip to content

Commit 1dcdd02

Browse files
authored
Merge pull request #1636 from ustaxcourt/test
Merge Test into Staging
2 parents 0ae8cd1 + 6c6b2c8 commit 1dcdd02

10 files changed

+478
-0
lines changed

shared/src/business/useCases/saveCaseDetailInternalEditInteractor.js

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ exports.saveCaseDetailInternalEditInteractor = async (
7676
statistics: caseToUpdate.statistics,
7777
};
7878

79+
if (!originalCaseEntity.isPaper) {
80+
editableFields.receivedAt = originalCaseEntity.receivedAt;
81+
}
82+
7983
const caseWithFormEdits = {
8084
...caseRecord,
8185
...editableFields,

shared/src/business/useCases/saveCaseDetailInternalEditInteractor.test.js

+25
Original file line numberDiff line numberDiff line change
@@ -324,4 +324,29 @@ describe('updateCase', () => {
324324
mockCase.petitioners[0].contactId,
325325
]);
326326
});
327+
328+
it('should not allow the recevedAt field to be updated if it is an electronic filing', async () => {
329+
const currentCaseDetail = {
330+
...mockCase,
331+
isPaper: false,
332+
receivedAt: '2021-01-01T16:00:00.000Z',
333+
};
334+
applicationContext
335+
.getPersistenceGateway()
336+
.getCaseByDocketNumber.mockReturnValue({ ...currentCaseDetail });
337+
338+
const result = await saveCaseDetailInternalEditInteractor(
339+
applicationContext,
340+
{
341+
caseToUpdate: {
342+
...mockCase,
343+
contactPrimary: getContactPrimary(mockCase),
344+
receivedAt: '2021-08-08T16:00:00.000Z', // a new receivedAt
345+
},
346+
docketNumber: mockCase.docketNumber,
347+
},
348+
);
349+
350+
expect(result.receivedAt).toEqual(currentCaseDetail.receivedAt);
351+
});
327352
});

web-api/migration-terraform/main/lambdas/migration-segments.js

+18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
const AWS = require('aws-sdk');
22
const createApplicationContext = require('../../../src/applicationContext');
33
const promiseRetry = require('promise-retry');
4+
const {
5+
migrateItems: bugMigration0039,
6+
} = require('./migrations/bug-0039-notice-of-trial-date');
7+
const {
8+
migrateItems: migration0040,
9+
} = require('./migrations/bug-0040-case-received-at');
410
const {
511
migrateItems: validationMigration,
612
} = require('./migrations/0000-validate-all-items');
@@ -29,6 +35,16 @@ const migrateRecords = async ({
2935
// eslint-disable-next-line no-unused-vars
3036
ranMigrations = {},
3137
}) => {
38+
if (!ranMigrations['bug-0040-case-received-at.js']) {
39+
applicationContext.logger.debug('about to run migration 0040');
40+
items = await migration0040(items, documentClient);
41+
}
42+
43+
if (!ranMigrations['bug-0039-notice-of-trial-date.js']) {
44+
applicationContext.logger.debug('about to run bug migration 0039');
45+
items = await bugMigration0039(items, documentClient);
46+
}
47+
3248
applicationContext.logger.debug('about to run validation migration');
3349
items = await validationMigration(items);
3450

@@ -131,6 +147,8 @@ exports.handler = async event => {
131147

132148
const ranMigrations = {
133149
// ...(await hasMigrationRan('bug-999-example-migration-file.js')),
150+
...(await hasMigrationRan('bug-0039-notice-of-trial-date.js')),
151+
...(await hasMigrationRan('bug-0040-case-received-at.js')),
134152
};
135153

136154
await scanTableSegment(segment, totalSegments, ranMigrations);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const createApplicationContext = require('../../../../src/applicationContext');
2+
const {
3+
aggregateCaseItems,
4+
} = require('../../../../../shared/src/persistence/dynamo/helpers/aggregateCaseItems');
5+
const {
6+
Case,
7+
} = require('../../../../../shared/src/business/entities/cases/Case');
8+
const {
9+
SYSTEM_GENERATED_DOCUMENT_TYPES,
10+
} = require('../../../../../shared/src/business/entities/EntityConstants');
11+
const { queryFullCase } = require('../utilities');
12+
const applicationContext = createApplicationContext({});
13+
14+
const migrateItems = async (items, documentClient) => {
15+
const itemsAfter = [];
16+
17+
for (const item of items) {
18+
if (item.pk.startsWith('case|') && item.sk.startsWith('case|')) {
19+
const fullCase = await queryFullCase(documentClient, item.docketNumber);
20+
21+
const caseRecord = aggregateCaseItems(fullCase);
22+
23+
const hasNoticeOfTrial = !!caseRecord.docketEntries.find(
24+
entry =>
25+
entry.eventCode ===
26+
SYSTEM_GENERATED_DOCUMENT_TYPES.noticeOfTrial.eventCode,
27+
);
28+
29+
if (item.noticeOfTrialDate && !hasNoticeOfTrial) {
30+
// there is no notice of trial document, so remove the noticeOfTrialDate
31+
item.noticeOfTrialDate = undefined;
32+
33+
applicationContext.logger.info(
34+
'Removing noticeOfTrialDate for case without NTD on docket record.',
35+
{
36+
pk: item.pk,
37+
sk: item.sk,
38+
},
39+
);
40+
}
41+
42+
new Case(item, { applicationContext }).validateWithLogging(
43+
applicationContext,
44+
);
45+
}
46+
47+
itemsAfter.push(item);
48+
}
49+
return itemsAfter;
50+
};
51+
52+
exports.migrateItems = migrateItems;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
const {
2+
SYSTEM_GENERATED_DOCUMENT_TYPES,
3+
} = require('../../../../../shared/src/business/entities/EntityConstants');
4+
const { migrateItems } = require('./bug-0039-notice-of-trial-date');
5+
const { MOCK_CASE } = require('../../../../../shared/src/test/mockCase');
6+
7+
describe('migrateItems', () => {
8+
let mockCaseItem;
9+
let mockDocketEntryItems;
10+
let documentClient;
11+
12+
beforeEach(() => {
13+
mockCaseItem = {
14+
...MOCK_CASE,
15+
pk: `case|${MOCK_CASE.docketNumber}`,
16+
sk: `case|${MOCK_CASE.docketNumber}`,
17+
};
18+
19+
mockDocketEntryItems = [
20+
{
21+
archived: false,
22+
docketEntryId: '83b77e98-4cf6-4fb4-b8c0-f5f90fd68f3c',
23+
documentType: 'Answer',
24+
eventCode: 'A',
25+
filedBy: 'Test Petitioner',
26+
pk: `case|${MOCK_CASE.docketNumber}`,
27+
sk: 'docket-entry|83b77e98-4cf6-4fb4-b8c0-f5f90fd68f3c',
28+
userId: '8bbfcd5a-b02b-4983-8e9c-6cc50d3d566c',
29+
},
30+
];
31+
32+
documentClient = {
33+
query: jest.fn().mockImplementation(() => ({
34+
promise: async () => ({
35+
Items: [mockCaseItem, ...mockDocketEntryItems],
36+
}),
37+
})),
38+
};
39+
});
40+
41+
it('should return and not modify records that are NOT case records', async () => {
42+
const items = [
43+
{
44+
noticeOfTrialDate: '2025-04-10T04:00:00.000Z',
45+
pk: `case|${MOCK_CASE.docketNumber}`,
46+
sk: 'user|6d74eadc-0181-4ff5-826c-305200e8733d',
47+
},
48+
{
49+
noticeOfTrialDate: '2025-04-10T04:00:00.000Z',
50+
pk: `case|${MOCK_CASE.docketNumber}`,
51+
sk: 'docket-entry|83b77e98-4cf6-4fb4-b8c0-f5f90fd68f3c',
52+
},
53+
];
54+
const results = await migrateItems(items, documentClient);
55+
56+
expect(results).toEqual([
57+
{
58+
noticeOfTrialDate: '2025-04-10T04:00:00.000Z', // field doesn't belong here, but proving it is unmodified
59+
pk: `case|${MOCK_CASE.docketNumber}`,
60+
sk: 'user|6d74eadc-0181-4ff5-826c-305200e8733d',
61+
},
62+
{
63+
noticeOfTrialDate: '2025-04-10T04:00:00.000Z', // field doesn't belong here, but proving it is unmodified
64+
pk: `case|${MOCK_CASE.docketNumber}`,
65+
sk: 'docket-entry|83b77e98-4cf6-4fb4-b8c0-f5f90fd68f3c',
66+
},
67+
]);
68+
69+
expect(documentClient.query).not.toHaveBeenCalled();
70+
});
71+
72+
it('should unset the noticeOfTrialDate field for the given case if a notice of trial IS NOT found on the docket record', async () => {
73+
const items = [
74+
{
75+
...mockCaseItem,
76+
noticeOfTrialDate: '2025-04-10T04:00:00.000Z',
77+
},
78+
];
79+
80+
const results = await migrateItems(items, documentClient);
81+
82+
expect(results[0].noticeOfTrialDate).toBeUndefined();
83+
});
84+
85+
it('should NOT unset the noticeOfTrialDate field for the given case if a notice of trial IS found on the docket record', async () => {
86+
mockDocketEntryItems.push({
87+
archived: false,
88+
docketEntryId: '99977e98-4cf6-4fb4-b8c0-f5f90fd68f3c',
89+
documentType: SYSTEM_GENERATED_DOCUMENT_TYPES.noticeOfTrial.documentType,
90+
eventCode: SYSTEM_GENERATED_DOCUMENT_TYPES.noticeOfTrial.eventCode,
91+
filedBy: 'Test Petitioner',
92+
pk: `case|${MOCK_CASE.docketNumber}`,
93+
sk: 'docket-entry|99977e98-4cf6-4fb4-b8c0-f5f90fd68f3c',
94+
userId: '8bbfcd5a-b02b-4983-8e9c-6cc50d3d566c',
95+
});
96+
97+
const items = [
98+
{
99+
...mockCaseItem,
100+
noticeOfTrialDate: '2025-04-10T04:00:00.000Z',
101+
},
102+
];
103+
104+
const results = await migrateItems(items, documentClient);
105+
106+
expect(results[0].noticeOfTrialDate).toEqual('2025-04-10T04:00:00.000Z');
107+
});
108+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const createApplicationContext = require('../../../../src/applicationContext');
2+
const {
3+
aggregateCaseItems,
4+
} = require('../../../../../shared/src/persistence/dynamo/helpers/aggregateCaseItems');
5+
const {
6+
Case,
7+
} = require('../../../../../shared/src/business/entities/cases/Case');
8+
const {
9+
INITIAL_DOCUMENT_TYPES,
10+
} = require('../../../../../shared/src/business/entities/EntityConstants');
11+
const { queryFullCase } = require('../utilities');
12+
const applicationContext = createApplicationContext({});
13+
14+
const isElectronicCase = item => {
15+
const isCaseItem = item.pk.startsWith('case|') && item.sk.startsWith('case|');
16+
17+
return isCaseItem && !item.isPaper === true;
18+
};
19+
20+
const migrateItems = async (items, documentClient) => {
21+
const itemsAfter = [];
22+
23+
for (const item of items) {
24+
if (isElectronicCase(item)) {
25+
const fullCase = await queryFullCase(documentClient, item.docketNumber);
26+
27+
const caseRecord = aggregateCaseItems(fullCase);
28+
29+
const petitionItem = caseRecord.docketEntries.find(
30+
entry => entry.eventCode === INITIAL_DOCUMENT_TYPES.petition.eventCode,
31+
);
32+
33+
const daysDiff = applicationContext
34+
.getUtilities()
35+
.calculateDifferenceInDays(item.receivedAt, petitionItem.receivedAt);
36+
37+
if (daysDiff !== 0) {
38+
// an electronic filing where the received at was changed from that of the petition
39+
40+
applicationContext.logger.info(
41+
`Updating case.receivedAt from ${item.receivedAt} to ${petitionItem.receivedAt} to match petition. Difference in days: ${daysDiff}`,
42+
{
43+
pk: item.pk,
44+
sk: item.sk,
45+
},
46+
);
47+
48+
item.receivedAt = petitionItem.receivedAt;
49+
}
50+
51+
new Case(item, { applicationContext }).validateWithLogging(
52+
applicationContext,
53+
);
54+
}
55+
56+
itemsAfter.push(item);
57+
}
58+
return itemsAfter;
59+
};
60+
61+
exports.migrateItems = migrateItems;

0 commit comments

Comments
 (0)