Skip to content

Commit bab68e0

Browse files
committed
#152 set status to queued when reprocessing a failed or incomplete search
1 parent 4f48ddf commit bab68e0

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';
@@ -121,22 +121,24 @@ export async function processCaseSearchRequest(req: CaseSearchRequest): Promise<
121121
case 'processing':
122122
// We requeue 'queued' and 'processing' because they might be stuck.
123123
// When they get picked up from the queue, we'll see whether they became 'complete' in the mean time and exit early.
124+
const zipCase = results[caseNumber].zipCase;
125+
126+
zipCase.fetchStatus = { status: 'queued' };
127+
128+
await StorageClient.saveCase(zipCase);
129+
124130
casesToQueue.push(caseNumber);
125131
}
126132
} else {
127133
// Case doesn't exist yet - create it with queued status and add to queue
128-
results[caseNumber] = {
129-
zipCase: {
130-
caseNumber,
131-
fetchStatus: { status: 'queued' },
132-
},
133-
};
134-
135-
// Save the new case to storage
136-
await StorageClient.saveCase({
134+
const zipCase: ZipCase = {
137135
caseNumber,
138136
fetchStatus: { status: 'queued' },
139-
});
137+
};
138+
139+
results[caseNumber] = { zipCase: zipCase };
140+
141+
await StorageClient.saveCase(zipCase);
140142

141143
casesToQueue.push(caseNumber);
142144
}

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)