Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
Jira ticket: CAMS-421
  • Loading branch information
jamesobrooks authored and btposey committed Jan 31, 2025
1 parent 019788f commit 4ad6feb
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 11 deletions.
21 changes: 21 additions & 0 deletions backend/lib/adapters/gateways/dxtr/cases.dxtr.gateway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,5 +783,26 @@ describe('Test DXTR Gateway', () => {
const result = await testCasesDxtrGateway.getCaseIdsAndMaxTxIdToSync(applicationContext, '0');
expect(result).toEqual(expectedReturn);
});

test('should return an empty array and the existing max tx id', async () => {
const mockResults: QueryResults = {
success: true,
results: {
recordset: [],
},
message: '',
};
const expectedReturn = {
caseIds: [],
lastTxId: '0',
};

querySpy.mockImplementationOnce(async () => {
return Promise.resolve(mockResults);
});

const result = await testCasesDxtrGateway.getCaseIdsAndMaxTxIdToSync(applicationContext, '0');
expect(result).toEqual(expectedReturn);
});
});
});
42 changes: 39 additions & 3 deletions backend/lib/adapters/gateways/mongo/cases.mongo.repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ApplicationContext } from '../../types/basic';
import { CasesMongoRepository } from './cases.mongo.repository';
import { MongoCollectionAdapter } from './utils/mongo-adapter';
import * as crypto from 'crypto';
import { UnknownError } from '../../../common-errors/unknown-error';

describe('Cases repository', () => {
let repo: CasesMongoRepository;
Expand Down Expand Up @@ -225,12 +226,12 @@ describe('Cases repository', () => {
});

test('should createConsolidationTo', async () => {
const consolidaitonTo = MockData.getConsolidationTo();
const consolidationTo = MockData.getConsolidationTo();
const insertOneSpy = jest
.spyOn(MongoCollectionAdapter.prototype, 'insertOne')
.mockResolvedValue(crypto.randomUUID().toString());
const result = await repo.createConsolidationTo(consolidaitonTo);
expect(insertOneSpy).toHaveBeenCalledWith(consolidaitonTo);
const result = await repo.createConsolidationTo(consolidationTo);
expect(insertOneSpy).toHaveBeenCalledWith(consolidationTo);

expect(result).not.toBeNull();
});
Expand Down Expand Up @@ -324,4 +325,39 @@ describe('Cases repository', () => {
'Unknown CAMS Error',
);
});

test('should persist the case to sync', async () => {
const bCase = MockData.getSyncedCase();
const replaceSpy = jest
.spyOn(MongoCollectionAdapter.prototype, 'replaceOne')
.mockResolvedValue(null);

const expected = {
conjunction: 'AND',
values: [
{
condition: 'EQUALS',
attributeName: 'caseId',
value: bCase.caseId,
},
{
condition: 'EQUALS',
attributeName: 'documentType',
value: 'SYNCED_CASE',
},
],
};

await repo.syncDxtrCase(bCase);
expect(replaceSpy).toHaveBeenCalledWith(expected, bCase, true);
});

test('should throw when replaceOne throws error', async () => {
const bCase = MockData.getSyncedCase();
jest
.spyOn(MongoCollectionAdapter.prototype, 'replaceOne')
.mockRejectedValue(new Error('some error'));

await expect(repo.syncDxtrCase(bCase)).rejects.toThrow(UnknownError);
});
});
9 changes: 1 addition & 8 deletions backend/lib/use-cases/cases/case-management.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,14 +526,7 @@ describe('Case management tests', () => {

describe('syncCase tests', () => {
test('should persist a SyncedCase', async () => {
const bCase = MockData.getCaseDetail({
override: {
judgeName: undefined,
debtorAttorney: undefined,
transfers: undefined,
consolidation: undefined,
},
});
const bCase = MockData.getDxtrCase();
const expected: SyncedCase = {
...bCase,
documentType: 'SYNCED_CASE',
Expand Down
27 changes: 27 additions & 0 deletions common/src/cams/test-utilities/mock-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
CaseDocketEntryDocument,
CaseNote,
CaseSummary,
DxtrCase,
SyncedCase,
} from '../cases';
import {
ConsolidationOrder,
Expand Down Expand Up @@ -44,6 +46,7 @@ import { CamsRole } from '../roles';
import { MOCKED_USTP_OFFICES_ARRAY } from '../offices';
import { REGION_02_GROUP_NY } from './mock-user';
import { RoleAndOfficeGroupNames } from '../privileged-identity';
import { SYSTEM_USER_REFERENCE } from '../auditable';

type EntityType = 'company' | 'person';
type BankruptcyChapters = '9' | '11' | '12' | '15';
Expand Down Expand Up @@ -220,6 +223,28 @@ function getCaseDetail(
return { ...caseDetail, _actions, ...override };
}

function getDxtrCase(options: Options<DxtrCase> = { entityType: 'person', override: {} }) {
const { entityType, override } = options;
const dxtrCase: DxtrCase = {
...getCaseSummary({ entityType }),
closedDate: undefined,
dismissedDate: undefined,
reopenedDate: undefined,
};
return { ...dxtrCase, ...override };
}

function getSyncedCase(options: Options<SyncedCase> = { entityType: 'person', override: {} }) {
const { entityType, override } = options;
const syncedCase: SyncedCase = {
...getDxtrCase({ entityType }),
documentType: 'SYNCED_CASE',
updatedBy: SYSTEM_USER_REFERENCE,
updatedOn: someDateBeforeThisDate(new Date().toISOString()),
};
return { ...syncedCase, ...override };
}

/**
* @param {T} data There is no simple way to determine what type T is and generate
* random data accordingly, so it is required to provide it. We could modify to behave like
Expand Down Expand Up @@ -646,6 +671,8 @@ export const MockData = {
getCaseBasics,
getCaseSummary,
getCaseDetail,
getDxtrCase,
getSyncedCase,
getCourts,
getOffices,
getParty,
Expand Down

0 comments on commit 4ad6feb

Please sign in to comment.