Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exui 2770 mc srt pr #4252

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions api/workAllocation/caseWorkerUserDataCacheService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ describe('Caseworker Cache Service', () => {
];
const mockRoleAssignments = [{
id: '123',
// Test specifies jursidiction is not needed
attributes: {},
roleCategory: 'ADMIN',
actorId: '1'
Expand Down
4 changes: 2 additions & 2 deletions api/workAllocation/caseWorkerUserDataCacheService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export async function fetchRoleAssignments(cachedUserData: StaffUserDetails[], r
// cachedUsersWithRoles to ensure rerun if user restarts request early
const roleApiPath: string = prepareRoleApiUrl(baseRoleAssignmentUrl);
const jurisdictions = getStaffSupportedJurisdictionsList();
const payload = prepareRoleApiRequest(jurisdictions);
const payload = prepareRoleApiRequest(jurisdictions, null, true);
const { data } = await handlePostRoleAssignments(roleApiPath, payload, req);
const roleAssignments = data.roleAssignmentResponse;
cachedUsersWithRoles = mapUsersToCachedCaseworkers(cachedUserData, roleAssignments);
Expand All @@ -106,7 +106,7 @@ export async function fetchRoleAssignmentsForNewUsers(cachedUserData: StaffUserD
// cachedUsersWithRoles to ensure rerun if user restarts request early
const roleApiPath: string = prepareRoleApiUrl(baseRoleAssignmentUrl);
const jurisdictions = getStaffSupportedJurisdictionsList();
const payload = prepareRoleApiRequest(jurisdictions);
const payload = prepareRoleApiRequest(jurisdictions, null, true);
const roleAssignmentHeaders = {
...getRequestHeaders(),
pageNumber: 0,
Expand Down
22 changes: 15 additions & 7 deletions api/workAllocation/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export function mapUsersToCachedCaseworkers(users: StaffUserDetails[], roleAssig
idamId: staffUser.staff_profile.id,
lastName: staffUser.staff_profile.last_name,
locations: mapCachedCaseworkerLocation(staffUser.staff_profile.base_location),
roleCategory: getUserRoleCategory(roleAssignments, staffUser.staff_profile),
roleCategory: getUserRoleCategory(roleAssignments, staffUser.staff_profile, staffUser.ccd_service_names),
services: staffUser.ccd_service_names
};
caseworkers.push(thisCaseWorker);
Expand All @@ -301,9 +301,14 @@ export function getRoleCategory(roleAssignments: RoleAssignment[], caseWorkerApi
return roleAssignment ? roleAssignment.roleCategory : null;
}

export function getUserRoleCategory(roleAssignments: RoleAssignment[], user: StaffProfile): string {
export function getUserRoleCategory(roleAssignments: RoleAssignment[], user: StaffProfile, services: string[]): string {
// TODO: Will need to be updated
const roleAssignment = roleAssignments.find((roleAssign) => roleAssign.actorId === user.id);
const roleAssignment = roleAssignments.find((roleAssign) =>
roleAssign.actorId === user.id && roleAssign.roleCategory &&
// added line below to stop irrelevant role setting role category
// note - we know services are already capitalised
(!roleAssign.attributes?.jurisdiction || services.includes(roleAssign.attributes.jurisdiction.toUpperCase()))
);
return roleAssignment ? roleAssignment.roleCategory : null;
}

Expand Down Expand Up @@ -356,10 +361,13 @@ export function mapUserLocation(baseLocation: LocationApi[]): Location {
return thisBaseLocation;
}

export function prepareRoleApiRequest(jurisdictions: string[], locationId?: number): any {
const attributes: any = {
jurisdiction: jurisdictions
};
export function prepareRoleApiRequest(jurisdictions: string[], locationId?: number, allRoles?: boolean): any {
let attributes: any = {};
if (!allRoles) {
attributes = {
jurisdiction: jurisdictions
};
}

const payload = {
attributes,
Expand Down
164 changes: 162 additions & 2 deletions api/workAllocation/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Role } from '../roleAccess/models/roleType';
import { RoleAssignment } from '../user/interfaces/roleAssignment';
import { ASSIGN, CANCEL, CLAIM, CLAIM_AND_GO, COMPLETE, GO, REASSIGN, RELEASE, TaskPermission } from './constants/actions';
import { ServiceCaseworkerData } from './interfaces/caseworkerPayload';
import { Caseworker, CaseworkerApi, CaseworkersByService, Location, LocationApi } from './interfaces/common';
import { CachedCaseworker, Caseworker, CaseworkerApi, CaseworkersByService, Location, LocationApi } from './interfaces/common';
import { PersonRole } from './interfaces/person';
import { RoleCaseData } from './interfaces/roleCaseData';

Expand Down Expand Up @@ -43,6 +43,7 @@ import {
mapCaseworkerData,
mapCaseworkerLocation,
mapRoleType,
mapUsersToCachedCaseworkers,
prepareGetTaskUrl,
preparePaginationUrl,
preparePostTaskUrlAction,
Expand Down Expand Up @@ -351,9 +352,12 @@ describe('workAllocation.utils', () => {
'national-business-centre', 'senior-tribunal-caseworker', 'case-allocator', 'regional-centre-admin'],
validAt: Date.UTC,
roleType: ['ORGANISATION']
};
} as any;
const payload = prepareRoleApiRequest(jurisdictions, locationId);
expect(payload).to.deep.equal(expectedResult);
expectedResult.attributes = { baseLocation: [locationId] };
const allRolesPayload = prepareRoleApiRequest(jurisdictions, locationId, true);
expect(allRolesPayload).to.deep.equal(expectedResult);
});
});

Expand Down Expand Up @@ -1097,6 +1101,162 @@ describe('workAllocation.utils', () => {
});
});

describe('mapUsersToCachedCaseworkers', () => {
// note not making it a case as would have to fill in multiple unnecessary properties
const mockUsers: any[] = [
{
staff_profile: {
id: '123',
email_id: '[email protected]',
first_name: 'Test',
last_name: 'User',
base_location: [
{
location_id: '1',
location: 'testlocation',
is_primary: true,
services: ['IA', 'CIVIL']
}
]
},
ccd_service_names: ['IA', 'CIVIL']
},
{
staff_profile: {
id: '124',
email_id: '[email protected]',
first_name: 'Second',
last_name: 'User',
base_location: [
{
location_id: '2',
location: 'testlocation2',
is_primary: true,
services: ['IA']
},
{
location_id: '3',
location: 'testlocation3',
is_primary: false,
services: ['PRIVATELAW']
}
]
},
ccd_service_names: ['PRIVATELAW', 'IA']
}
];
const mockRoleAssignment: RoleAssignment[] = [
{
id: '1',
actorId: '123',
roleName: 'example-role',
endTime: new Date('01-01-2022'),
beginTime: new Date('01-01-2021'),
roleCategory: 'LEGAL_OPERATIONS',
attributes: {
caseId: '123',
baseLocation: '001',
isNew: true
}
},
{
id: '2',
actorId: '124',
roleName: 'example-role',
endTime: new Date('01-01-2022'),
beginTime: new Date('01-01-2021'),
roleCategory: 'ADMIN',
attributes: {
baseLocation: '001',
isNew: true,
// note: below just confirms jurisdiction is not checked
jurisdiction: 'IA'
}
},
{
id: '3',
actorId: '124',
roleName: 'example-role-2',
endTime: new Date('01-01-2022'),
beginTime: new Date('01-01-2021'),
roleCategory: 'LEGAL_OPERATIONS',
attributes: {
caseId: '456',
baseLocation: '001',
isNew: true
}
}
];

const mockCachedCaseworkers: CachedCaseworker[] = [
{
email: '[email protected]',
firstName: 'Test',
idamId: '123',
lastName: 'User',
locations: [
{
id: '1',
locationName: 'testlocation',
services: ['IA', 'CIVIL']
}
],
roleCategory: 'LEGAL_OPERATIONS',
services: ['IA', 'CIVIL']
},
{
email: '[email protected]',
firstName: 'Second',
idamId: '124',
lastName: 'User',
locations: [
{
id: '2',
locationName: 'testlocation2',
services: ['IA']
}
],
roleCategory: 'ADMIN',
services: ['PRIVATELAW', 'IA']
}
];

it('should return empty list if there are no cached caseworkers', () => {
expect(mapUsersToCachedCaseworkers([], [])).to.deep.equal([]);
expect(mapUsersToCachedCaseworkers([], mockRoleAssignment)).to.deep.equal([]);
expect(mapUsersToCachedCaseworkers([], mockRoleAssignment)).to.deep.equal([]);
expect(mapUsersToCachedCaseworkers([], [])).to.deep.equal([]);
});

it('should return cached caseworkers from data (regardless of if there is no jurisdiction', () => {
const mappedCaseworkers = mapUsersToCachedCaseworkers(mockUsers, mockRoleAssignment);
expect(mappedCaseworkers).to.deep.equal(mockCachedCaseworkers);
});

it('should correctly get the users role category', () => {
expect(util.getUserRoleCategory(mockRoleAssignment, mockUsers[0].staff_profile, mockUsers[0].ccd_service_names)).to.equal('LEGAL_OPERATIONS');
expect(util.getUserRoleCategory(mockRoleAssignment, mockUsers[1].staff_profile, mockUsers[1].ccd_service_names)).to.equal('ADMIN');
const specificMockRole = [{ actorId: '123', roleCategory: 'CTSC', attributes: { jurisdiction: 'ia' } } as RoleAssignment];
expect(util.getUserRoleCategory(specificMockRole, mockUsers[0].staff_profile, mockUsers[0].ccd_service_names)).to.equal('CTSC');
// checks that if service of role does not match, role cateogry not set
expect(util.getUserRoleCategory(specificMockRole, mockUsers[0].staff_profile, ['PRIVATELAW'])).to.equal(null);
specificMockRole[0].attributes = {};
// checks that if role not service specific, role category is set
expect(util.getUserRoleCategory(specificMockRole, mockUsers[0].staff_profile, ['PRIVATELAW'])).to.equal('CTSC');
specificMockRole[0].roleCategory = undefined;
expect(util.getUserRoleCategory(specificMockRole, mockUsers[0].staff_profile, ['PRIVATELAW'])).to.equal(null);
});

it('should correctly get the users location', () => {
expect(util.mapCachedCaseworkerLocation(mockUsers[0].staff_profile.base_location)).to.deep.equal(mockCachedCaseworkers[0].locations);
expect(util.mapCachedCaseworkerLocation(mockUsers[1].staff_profile.base_location)).to.deep.equal(mockCachedCaseworkers[1].locations);
const mockBaseLocations = mockUsers[1].staff_profile.base_location;
mockBaseLocations[0].is_primary = false;
mockBaseLocations[1].is_primary = true;
expect(util.mapCachedCaseworkerLocation(mockBaseLocations)).to.deep.equal([{ id: '3', locationName: 'testlocation3', services: ['PRIVATELAW'] }]);
});
});

describe('getSubstantiveRoles', () => {
const mockRoleAssignment: RoleAssignment[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"@cucumber/cucumber": "^11.0.0",
"@edium/fsm": "^2.1.2",
"@faker-js/faker": "^9.2.0",
"@hmcts/ccd-case-ui-toolkit": "7.1.35",
"@hmcts/ccd-case-ui-toolkit": "7.1.35-rc1",
"@hmcts/ccpay-web-component": "6.2.1",
"@hmcts/frontend": "0.0.50-alpha",
"@hmcts/media-viewer": "4.0.10",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as fromRoot from '../../../app/store';
import { AllocateRoleService } from '../../../role-access/services';
import { WASupportedJurisdictionsService } from '../../../work-allocation/services';
import { CaseViewerContainerComponent } from './case-viewer-container.component';
import { LoggerService } from '../../../app/services/logger/logger.service';

@Component({
selector: 'ccd-case-viewer',
Expand Down Expand Up @@ -172,6 +173,7 @@ class MockAllocateRoleService {
return of([]);
}
}
const loggerServiceMock = jasmine.createSpyObj('loggerService', ['log']);

const TABS: CaseTab[] = [
{
Expand Down Expand Up @@ -260,6 +262,7 @@ describe('CaseViewerContainerComponent', () => {
}
}
},
{ provide: LoggerService, useValue: loggerServiceMock },
{ provide: FeatureToggleService, useClass: MockFeatureToggleService },
{ provide: AllocateRoleService, useClass: MockAllocateRoleService },
{ provide: WASupportedJurisdictionsService, useValue: mockSupportedJurisdictionsService }
Expand Down Expand Up @@ -349,6 +352,7 @@ describe('CaseViewerContainerComponent - Hearings tab visible', () => {
}
}
},
{ provide: LoggerService, useValue: loggerServiceMock },
{ provide: FeatureToggleService, useClass: MockFeatureToggleService },
{ provide: AllocateRoleService, useClass: MockAllocateRoleService },
{ provide: WASupportedJurisdictionsService, useValue: mockSupportedJurisdictionsService }
Expand All @@ -374,6 +378,84 @@ describe('CaseViewerContainerComponent - Hearings tab visible', () => {
});
});

describe('CaseViewerContainerComponent - retrieving user info when no roles are present', () => {
let component: CaseViewerContainerComponent;
let fixture: ComponentFixture<CaseViewerContainerComponent>;
let store = jasmine.createSpyObj('store', ['dispatch']);

const initialState: State = {
routerReducer: null,
appConfig: {
config: {},
termsAndCondition: null,
loaded: true,
loading: true,
termsAndConditions: null,
isTermsAndConditionsFeatureEnabled: null,
useIdleSessionTimeout: null,
userDetails: {
sessionTimeout: {
idleModalDisplayTime: 0,
totalIdleTime: 0
},
canShareCases: true,
userInfo: {
id: '',
active: true,
email: '[email protected]',
forename: 'XUI test',
roles: [],
uid: 'd90ae606-98e8-47f8-b53c-a7ab77fde22b',
surname: 'judge'
},
roleAssignmentInfo: []
},
decorate16digitCaseReferenceSearchBoxInHeader: false
}
};

beforeEach(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule, StoreModule.forRoot(reducers), MatTabsModule, BrowserAnimationsModule],
providers: [
provideMockStore({ initialState }),
{
provide: ActivatedRoute,
useValue: {
snapshot: {
data: {
case: CASE_VIEW
}
}
}
},
{ provide: LoggerService, useValue: loggerServiceMock },
{ provide: FeatureToggleService, useClass: MockFeatureToggleService },
{ provide: AllocateRoleService, useClass: MockAllocateRoleService },
{ provide: WASupportedJurisdictionsService, useValue: mockSupportedJurisdictionsService }
],
declarations: [CaseViewerContainerComponent, CaseViewerComponent]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(CaseViewerContainerComponent);
mockSupportedJurisdictionsService.getWASupportedJurisdictions.and.returnValue(of([]));
component = fixture.componentInstance;
store = TestBed.inject(MockStore);
const blanckUserDetails = { ...initialState.appConfig.userDetails, roles: [] };
store.overrideSelector(fromRoot.getUserDetails, blanckUserDetails);
fixture.detectChanges();
});

it('should call getUserDetails in no roles are found', () => {
spyOn(store, 'dispatch');
component.ngOnInit();
expect(store.dispatch).toHaveBeenCalled();
});
});

describe('CaseViewerContainerComponent - Hearings tab hidden', () => {
let component: CaseViewerContainerComponent;
let fixture: ComponentFixture<CaseViewerContainerComponent>;
Expand Down Expand Up @@ -425,6 +507,7 @@ describe('CaseViewerContainerComponent - Hearings tab hidden', () => {
}
}
},
{ provide: LoggerService, useValue: loggerServiceMock },
{ provide: FeatureToggleService, useClass: MockFeatureToggleService },
{ provide: AllocateRoleService, useClass: MockAllocateRoleService },
{ provide: WASupportedJurisdictionsService, useValue: mockSupportedJurisdictionsService }
Expand Down
Loading