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

Fix/1448 cqc banner for subs #6300

Open
wants to merge 14 commits into
base: main
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
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ Thumbs.db
fecoverage

# localhost config variations
/server/config/localhost.*.yaml
/server/config/localhost-*.yaml
/server/config/localhost.yaml
backend/server/config/localhost.yaml

// nodemon localisations
nodemon.json
Expand Down
4 changes: 4 additions & 0 deletions backend/server/config/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ jwt:
ttl:
login: 60
db:
host: localhost
pool:
min: 15
max: 15
ssl: false
username: sfcadmin

redis:
url: redis://localhost:6379

log:
sequelize: false

Expand Down
41 changes: 0 additions & 41 deletions backend/server/config/localhost.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, convertToParamMap } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { Establishment } from '@core/model/establishment.model';
import { EstablishmentService } from '@core/services/establishment.service';
import { MockEstablishmentService } from '@core/test-utils/MockEstablishmentService';
import { of } from 'rxjs';

import { CqcStatusCheckResolver } from './cqcStatusCheck.resolver';

describe('CqcStatusCheckResolver', () => {
const setup = () => {
const setup = (establishmentuid = null) => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule, RouterTestingModule.withRoutes([])],
providers: [
Expand All @@ -17,29 +19,82 @@ describe('CqcStatusCheckResolver', () => {
provide: EstablishmentService,
useClass: MockEstablishmentService,
},
{
provide: ActivatedRoute,
useValue: { snapshot: { paramMap: convertToParamMap({ establishmentuid }) } },
},
],
});

const resolver = TestBed.inject(CqcStatusCheckResolver);
const route = TestBed.inject(ActivatedRoute);

const establishmentService = TestBed.inject(EstablishmentService);
const getCqcRegistrationStatusSpy = spyOn(establishmentService, 'getCQCRegistrationStatus').and.callFake(() =>
of({ cqcStatusMatch: false }),
);

return { resolver, route, establishmentService };
return { resolver, establishmentService, route, establishmentuid, getCqcRegistrationStatusSpy };
};

it('should be created', async () => {
const { resolver } = await setup();
expect(resolver).toBeTruthy();
});

it('should call getCQCRegistrationStatus', async () => {
const { resolver, route, establishmentService } = await setup();
const getCqcRegistrationStatusSpy = spyOn(establishmentService, 'getCQCRegistrationStatus').and.callThrough();
resolver.resolve(route.snapshot);
it('should call getEstablishment with establishment ID in service when no uid in params', async () => {
const { resolver, establishmentService, route, getCqcRegistrationStatusSpy } = await setup();
const establishment = {
locationId: '1-11111111',
postcode: 'ABC123',
mainService: { name: 'Care' },
} as Establishment;

const getEstablishmentSpy = spyOn(establishmentService, 'getEstablishment').and.callFake(() => of(establishment));

resolver.resolve(route.snapshot).subscribe(() => {
expect(getEstablishmentSpy).toHaveBeenCalledWith(establishmentService.establishmentId);

expect(getCqcRegistrationStatusSpy).toHaveBeenCalledWith(establishment.locationId, {
postcode: establishment.postcode,
mainService: establishment.mainService.name,
});
});
});

it('should call getCQCRegistrationStatus when workplace has location ID', async () => {
const establishmentuid = 'ab131231dsa2321321a';
const { resolver, establishmentService, route, getCqcRegistrationStatusSpy } = await setup(establishmentuid);
const establishment = {
locationId: '1-11111111',
postcode: 'ABC123',
mainService: { name: 'Care' },
} as Establishment;

const getEstablishmentSpy = spyOn(establishmentService, 'getEstablishment').and.callFake(() => of(establishment));

resolver.resolve(route.snapshot).subscribe(() => {
expect(getEstablishmentSpy).toHaveBeenCalledWith(establishmentuid);

expect(getCqcRegistrationStatusSpy).toHaveBeenCalledWith(establishment.locationId, {
postcode: establishment.postcode,
mainService: establishment.mainService.name,
});
});
});

it('should not call getCQCRegistrationStatus when workplace does not have location ID', async () => {
const { resolver, establishmentService, route, establishmentuid, getCqcRegistrationStatusSpy } = await setup();
const establishment = {
locationId: null,
postcode: 'ABC123',
mainService: { name: 'Care' },
} as Establishment;

spyOn(establishmentService, 'getEstablishment').and.callFake(() => of(establishment));

expect(getCqcRegistrationStatusSpy).toHaveBeenCalledWith('1-11111111', {
postcode: 'AB1 2CD',
mainService: 'Care',
resolver.resolve(route.snapshot).subscribe(() => {
expect(getCqcRegistrationStatusSpy).not.toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
import { EstablishmentService } from '@core/services/establishment.service';
import { of } from 'rxjs';
import { catchError, tap } from 'rxjs/operators';
import { Observable, of } from 'rxjs';
import { catchError, switchMap } from 'rxjs/operators';

export class CQCRegistrationStatusResponse {
cqcStatusMatch: boolean;
}

@Injectable()
export class CqcStatusCheckResolver implements Resolve<any> {
constructor(private establishmentService: EstablishmentService) {}

resolve(route: ActivatedRouteSnapshot) {
const { locationId, postcode, mainService } = this.establishmentService.primaryWorkplace;
resolve(route: ActivatedRouteSnapshot): Observable<CQCRegistrationStatusResponse> {
const workplaceUid = route.paramMap.get('establishmentuid')
? route.paramMap.get('establishmentuid')
: this.establishmentService.establishmentId;

if (locationId) {
return this.establishmentService
.getCQCRegistrationStatus(locationId, {
postcode,
mainService: mainService.name,
})
.pipe(
tap(({ cqcStatusMatch }) => {
this.establishmentService.setCheckCQCDetailsBanner(cqcStatusMatch === false);
}),
)
.pipe(
catchError(() => {
return of(null);
}),
);
}
return this.establishmentService.getEstablishment(workplaceUid).pipe(
switchMap(({ locationId, postcode, mainService }) => {
if (locationId) {
return this.establishmentService.getCQCRegistrationStatus(locationId, {
postcode,
mainService: mainService.name,
});
}
return of(null);
}),
catchError(() => {
return of(null);
}),
);
}
}
15 changes: 0 additions & 15 deletions frontend/src/app/core/services/establishment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export class EstablishmentService {
private _establishment$: BehaviorSubject<Establishment> = new BehaviorSubject<Establishment>(null);
private returnTo$ = new BehaviorSubject<URLStructure>(null);
private _primaryWorkplace$: BehaviorSubject<Establishment> = new BehaviorSubject<Establishment>(null);
private _checkCQCDetailsBanner$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
public previousEstablishmentId: string;
public isSameLoggedInUser: boolean;
public mainServiceCQC: boolean = null;
Expand Down Expand Up @@ -144,7 +143,6 @@ export class EstablishmentService {
this._establishment$.next(establishment);
if (this.primaryWorkplace && establishment.uid === this.primaryWorkplace.uid) {
this.setPrimaryWorkplace(this.establishment);
this.setCheckCQCDetailsBanner(false);
}
}

Expand All @@ -154,7 +152,6 @@ export class EstablishmentService {
this._inStaffRecruitmentFlow = false;
this.standAloneAccount = false;
this.setPrimaryWorkplace(null);
this.setCheckCQCDetailsBanner(false);
}

public get establishmentId() {
Expand Down Expand Up @@ -196,18 +193,6 @@ export class EstablishmentService {
this.returnTo$.next(returnTo);
}

public get checkCQCDetailsBanner$(): Observable<boolean> {
return this._checkCQCDetailsBanner$.asObservable();
}

public get checkCQCDetailsBanner(): boolean {
return this._checkCQCDetailsBanner$.value;
}

public setCheckCQCDetailsBanner(data: boolean) {
this._checkCQCDetailsBanner$.next(data);
}

public get inStaffRecruitmentFlow() {
if (this._inStaffRecruitmentFlow) {
return this._inStaffRecruitmentFlow;
Expand Down
17 changes: 0 additions & 17 deletions frontend/src/app/core/test-utils/MockEstablishmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,20 +391,3 @@ export class MockEstablishmentServiceWithNoEmployerType extends MockEstablishmen
return;
}
}

@Injectable()
export class MockEstablishmentServiceCheckCQCDetails extends MockEstablishmentService {
private cqcDetailsBanner;

public static factory(checkCqcDetailsBanner = false) {
return (httpClient: HttpClient) => {
const service = new MockEstablishmentServiceCheckCQCDetails(httpClient);
service.cqcDetailsBanner = checkCqcDetailsBanner;
return service;
};
}

public get checkCQCDetailsBanner(): boolean {
return this.cqcDetailsBanner;
}
}
5 changes: 2 additions & 3 deletions frontend/src/app/features/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { ActivatedRoute } from '@angular/router';
import { Establishment } from '@core/model/establishment.model';
import { TrainingCounts } from '@core/model/trainingAndQualifications.model';
import { Worker } from '@core/model/worker.model';
import { BenchmarksServiceBase } from '@core/services/benchmarks-base.service';
import { AlertService } from '@core/services/alert.service';
import { AuthService } from '@core/services/auth.service';
import { BenchmarksServiceBase } from '@core/services/benchmarks-base.service';
import { EstablishmentService } from '@core/services/establishment.service';
import { PermissionsService } from '@core/services/permissions/permissions.service';
import { UserService } from '@core/services/user.service';
Expand Down Expand Up @@ -55,15 +55,14 @@ export class DashboardComponent implements OnInit, OnDestroy {
async ngOnInit(): Promise<void> {
this.showBanner = history.state?.showBanner;
this.authService.isOnAdminScreen = false;
this.showCQCDetailsBanner = this.establishmentService.checkCQCDetailsBanner;
this.showCQCDetailsBanner = this.route.snapshot.data?.cqcStatusCheck?.cqcStatusMatch === false;
this.workplace = this.establishmentService.primaryWorkplace;
this.showSharingPermissionsBanner = this.workplace.showSharingPermissionsBanner;
this.workplaceUid = this.workplace ? this.workplace.uid : null;
this.establishmentService.setInStaffRecruitmentFlow(false);
this.newDataAreaFlag = this.featureFlagsService.newBenchmarksDataArea;
this.canSeeNewDataArea = [1, 2, 8].includes(this.workplace.mainService.reportingID);


if (this.workplace) {
this.getPermissions();
this.totalStaffRecords = this.route.snapshot.data.totalStaffRecords;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[workersNotCompleted]="workersNotCompleted"
[(navigateToTab)]="navigateToTab"
[canViewEstablishment]="canViewEstablishment"
[showCheckCqcDetails]="showCheckCqcDetails"
[noOfWorkersWhoRequireInternationalRecruitment]="noOfWorkersWhoRequireInternationalRecruitment"
></app-summary-section>
</div>
Expand Down
Loading
Loading