Skip to content

Commit 5451a5c

Browse files
authored
Release ZipCase (#155)
2 parents 5e4a0d9 + 20066e3 commit 5451a5c

2 files changed

Lines changed: 38 additions & 14 deletions

File tree

serverless/lib/CaseSearchProcessor.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CaseSearchRequest, CaseSearchResponse, SearchResult, FetchStatus } from '../../shared/types';
1+
import { CaseSearchRequest, CaseSearchResponse, SearchResult, FetchStatus, ZipCase } from '../../shared/types';
22
import QueueClient from './QueueClient';
33
import SearchParser from './SearchParser';
44
import StorageClient from './StorageClient';
@@ -117,22 +117,24 @@ export async function processCaseSearchRequest(req: CaseSearchRequest): Promise<
117117
case 'processing':
118118
// We requeue 'queued' and 'processing' because they might be stuck.
119119
// When they get picked up from the queue, we'll see whether they became 'complete' in the mean time and exit early.
120+
const zipCase = results[caseNumber].zipCase;
121+
122+
zipCase.fetchStatus = { status: 'queued' };
123+
124+
await StorageClient.saveCase(zipCase);
125+
120126
casesToQueue.push(caseNumber);
121127
}
122128
} else {
123129
// Case doesn't exist yet - create it with queued status and add to queue
124-
results[caseNumber] = {
125-
zipCase: {
126-
caseNumber,
127-
fetchStatus: { status: 'queued' },
128-
},
129-
};
130-
131-
// Save the new case to storage
132-
await StorageClient.saveCase({
130+
const zipCase: ZipCase = {
133131
caseNumber,
134132
fetchStatus: { status: 'queued' },
135-
});
133+
};
134+
135+
results[caseNumber] = { zipCase: zipCase };
136+
137+
await StorageClient.saveCase(zipCase);
136138

137139
casesToQueue.push(caseNumber);
138140
}

serverless/lib/__tests__/CaseSearchProcessor.test.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,13 @@ describe('CaseSearchProcessor', () => {
221221
// Should queue for search (processing cases get re-queued in case they're stuck)
222222
expect(mockQueueClient.queueCasesForSearch).toHaveBeenCalledWith(['22CR123456-789'], 'test-user-id', 'Test Agent');
223223
expect(mockQueueClient.queueCaseForDataRetrieval).not.toHaveBeenCalled();
224-
expect(mockStorageClient.saveCase).not.toHaveBeenCalled();
224+
// Status should be saved to DynamoDB as 'queued'
225+
expect(mockStorageClient.saveCase).toHaveBeenCalledWith({
226+
caseNumber: '22CR123456-789',
227+
fetchStatus: { status: 'queued' },
228+
caseId: 'test-case-id',
229+
lastUpdated: expect.any(String),
230+
});
225231
});
226232

227233
it('should handle cases with notFound status (should queue for search retry)', async () => {
@@ -244,7 +250,15 @@ describe('CaseSearchProcessor', () => {
244250
// Should queue for search retry, in case the record is not actually in-queue
245251
expect(mockQueueClient.queueCaseForDataRetrieval).not.toHaveBeenCalled();
246252
expect(mockQueueClient.queueCasesForSearch).toHaveBeenCalledWith(['22CR123456-789'], 'test-user-id', 'Test Agent');
247-
expect(mockStorageClient.saveCase).not.toHaveBeenCalled();
253+
// Status should be saved to DynamoDB as 'queued'
254+
expect(mockStorageClient.saveCase).toHaveBeenCalledWith({
255+
caseNumber: '22CR123456-789',
256+
fetchStatus: { status: 'queued' },
257+
caseId: undefined,
258+
lastUpdated: expect.any(String),
259+
});
260+
// Status should be updated to 'queued' in the response for the UI
261+
expect(result.results['22CR123456-789'].zipCase.fetchStatus.status).toBe('queued');
248262
});
249263

250264
it('should handle cases with failed status (should queue for search)', async () => {
@@ -267,7 +281,15 @@ describe('CaseSearchProcessor', () => {
267281
// Should queue for search (failed status gets re-queued)
268282
expect(mockQueueClient.queueCasesForSearch).toHaveBeenCalledWith(['22CR123456-789'], 'test-user-id', 'Test Agent');
269283
expect(mockQueueClient.queueCaseForDataRetrieval).not.toHaveBeenCalled();
270-
expect(mockStorageClient.saveCase).not.toHaveBeenCalled();
284+
// Status should be saved to DynamoDB as 'queued'
285+
expect(mockStorageClient.saveCase).toHaveBeenCalledWith({
286+
caseNumber: '22CR123456-789',
287+
fetchStatus: { status: 'queued' },
288+
caseId: undefined,
289+
lastUpdated: expect.any(String),
290+
});
291+
// Status should be updated to 'queued' in the response for the UI
292+
expect(result.results['22CR123456-789'].zipCase.fetchStatus.status).toBe('queued');
271293
});
272294

273295
it('should handle new cases (not in storage)', async () => {

0 commit comments

Comments
 (0)