Skip to content

Commit

Permalink
Fix cases-runtime-state test and logging
Browse files Browse the repository at this point in the history
Jira ticket: CAMS-421

Co-authored-by: Brian Posey <[email protected]>
  • Loading branch information
jamesobrooks and btposey committed Mar 4, 2025
1 parent a570f10 commit f7c951d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions backend/lib/use-cases/dataflows/cases-runtime-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,43 @@ describe('storeRuntimeState tests', () => {
jest.restoreAllMocks();
});

test('should persist a new sync state', async () => {
test('should persist a new sync state and log', async () => {
jest.spyOn(MockMongoRepository.prototype, 'read').mockResolvedValue(undefined);
const upsertSpy = jest
.spyOn(MockMongoRepository.prototype, 'upsert')
.mockResolvedValue(undefined);

const lastSyncDate = new Date().toISOString();
const errorLogSpy = jest.spyOn(context.logger, 'camsError');
const infoLogSpy = jest.spyOn(context.logger, 'info');
await CasesRuntimeState.storeRuntimeState(context, lastSyncDate);
expect(upsertSpy).toHaveBeenCalledWith({
documentType: 'CASES_SYNC_STATE',
lastSyncDate,
});
expect(errorLogSpy).not.toHaveBeenCalled();
expect(infoLogSpy).toHaveBeenCalledWith(
expect.any(String),
expect.stringContaining('Wrote runtime state: '),
expect.anything(),
);
});

test('should throw CamsError', async () => {
test('should log CamsError', async () => {
const original: CasesSyncState = {
documentType: 'CASES_SYNC_STATE',
lastSyncDate: '1000',
};
jest.spyOn(MockMongoRepository.prototype, 'read').mockResolvedValue(original);
jest.spyOn(MockMongoRepository.prototype, 'upsert').mockRejectedValue(new Error('some error'));
const errorLogSpy = jest.spyOn(context.logger, 'camsError');
const infoLogSpy = jest.spyOn(context.logger, 'info');
await expect(CasesRuntimeState.storeRuntimeState(context, '1001')).resolves.toBeUndefined();
expect(errorLogSpy).toHaveBeenCalled();
expect(infoLogSpy).not.toHaveBeenCalledWith(
expect.any(String),
expect.stringContaining('Wrote runtime state: '),
expect.anything(),
);
});
});
2 changes: 1 addition & 1 deletion backend/lib/use-cases/dataflows/cases-runtime-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function storeRuntimeState(context: ApplicationContext, lastSyncDate: stri
lastSyncDate,
};
await runtimeStateRepo.upsert(newSyncState);
context.logger.info(MODULE_NAME, `Wrote runtime state: ${newSyncState}.`);
context.logger.info(MODULE_NAME, `Wrote runtime state: `, newSyncState);
} catch (originalError) {
const error = getCamsError(
originalError,
Expand Down

0 comments on commit f7c951d

Please sign in to comment.