-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #938 from US-Trustee-Program/CAMS-283-add-mock-off…
…ices-repo CAMS-283 - Add MockOfficesRepository
- Loading branch information
Showing
4 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
backend/functions/lib/testing/mock-gateways/mock-offices.repository.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { createMockApplicationContext } from '../testing-utilities'; | ||
import { MockOfficesRepository } from './mock-offices.repository'; | ||
|
||
describe('MockOfficesRepository', () => { | ||
test('should return expected attorney lists by office code', async () => { | ||
const context = await createMockApplicationContext(); | ||
const repo = new MockOfficesRepository(); | ||
|
||
const nyAttys = await repo.getOfficeAttorneys(context, 'USTP_CAMS_Region_2_Office_Manhattan'); | ||
expect(nyAttys.map((atty) => atty.name)).toEqual([ | ||
'Jessica Pearson', | ||
'Jack McCoy', | ||
"Martha's Son", | ||
]); | ||
|
||
const buAttys = await repo.getOfficeAttorneys(context, 'USTP_CAMS_Region_2_Office_Buffalo'); | ||
expect(buAttys.map((atty) => atty.name)).toEqual([]); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
backend/functions/lib/testing/mock-gateways/mock-offices.repository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { CamsRole } from '../../../../../common/src/cams/roles'; | ||
import MockUsers from '../../../../../common/src/cams/test-utilities/mock-user'; | ||
import { AttorneyUser, CamsUserReference } from '../../../../../common/src/cams/users'; | ||
import { ApplicationContext } from '../../adapters/types/basic'; | ||
import { getStorageGateway } from '../../factory'; | ||
import { OfficesRepository } from '../../use-cases/gateways.types'; | ||
|
||
export class MockOfficesRepository implements OfficesRepository { | ||
async getOfficeAttorneys( | ||
context: ApplicationContext, | ||
officeCode: string, | ||
): Promise<AttorneyUser[]> { | ||
// TODO: Remap the office code to use the user.offices when user.offices is changed to use UstpOfficeDetail. | ||
const storageGateway = getStorageGateway(context); | ||
const ustpOffices = storageGateway.getUstpOffices(); | ||
if (!ustpOffices.has(officeCode)) { | ||
return Promise.resolve([]); | ||
} | ||
const ustpOffice = ustpOffices.get(officeCode); | ||
const users: AttorneyUser[] = MockUsers.filter( | ||
(mockUser) => | ||
mockUser.user.roles.includes(CamsRole.TrialAttorney) && | ||
!!mockUser.user.offices.find( | ||
(office) => !!ustpOffice.groups.find((o) => o.groupDesignator === office.groupDesignator), | ||
), | ||
).map<AttorneyUser>((mockUser) => mockUser.user); | ||
return Promise.resolve(users); | ||
} | ||
|
||
putOfficeStaff( | ||
_context: ApplicationContext, | ||
_officeCode: string, | ||
_user: CamsUserReference, | ||
): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters