Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 13 additions & 11 deletions serverless/lib/CaseSearchProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CaseSearchRequest, CaseSearchResponse, SearchResult, FetchStatus } from '../../shared/types';
import { CaseSearchRequest, CaseSearchResponse, SearchResult, FetchStatus, ZipCase } from '../../shared/types';
import QueueClient from './QueueClient';
import SearchParser from './SearchParser';
import StorageClient from './StorageClient';
Expand Down Expand Up @@ -117,22 +117,24 @@ export async function processCaseSearchRequest(req: CaseSearchRequest): Promise<
case 'processing':
// We requeue 'queued' and 'processing' because they might be stuck.
// When they get picked up from the queue, we'll see whether they became 'complete' in the mean time and exit early.
const zipCase = results[caseNumber].zipCase;

zipCase.fetchStatus = { status: 'queued' };

await StorageClient.saveCase(zipCase);

casesToQueue.push(caseNumber);
}
} else {
// Case doesn't exist yet - create it with queued status and add to queue
results[caseNumber] = {
zipCase: {
caseNumber,
fetchStatus: { status: 'queued' },
},
};

// Save the new case to storage
await StorageClient.saveCase({
const zipCase: ZipCase = {
caseNumber,
fetchStatus: { status: 'queued' },
});
};

results[caseNumber] = { zipCase: zipCase };

await StorageClient.saveCase(zipCase);

casesToQueue.push(caseNumber);
}
Expand Down
28 changes: 25 additions & 3 deletions serverless/lib/__tests__/CaseSearchProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,13 @@ describe('CaseSearchProcessor', () => {
// Should queue for search (processing cases get re-queued in case they're stuck)
expect(mockQueueClient.queueCasesForSearch).toHaveBeenCalledWith(['22CR123456-789'], 'test-user-id', 'Test Agent');
expect(mockQueueClient.queueCaseForDataRetrieval).not.toHaveBeenCalled();
expect(mockStorageClient.saveCase).not.toHaveBeenCalled();
// Status should be saved to DynamoDB as 'queued'
expect(mockStorageClient.saveCase).toHaveBeenCalledWith({
caseNumber: '22CR123456-789',
fetchStatus: { status: 'queued' },
caseId: 'test-case-id',
lastUpdated: expect.any(String),
});
});

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

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

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