Skip to content

Commit

Permalink
VIH-10324 allow users to edit justice user properties (#1308)
Browse files Browse the repository at this point in the history
* Updated form

* updated chart pr value

* Test tweak

* Added back end validation failure display in ui

* number

* added an additional test for coverage of validation fail condition

* code coverage

* updated package

(cherry picked from commit ccc12df)
  • Loading branch information
will-craig committed Nov 29, 2023
1 parent 5a533ae commit ad38c3c
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 22 deletions.
6 changes: 3 additions & 3 deletions AdminWebsite/AdminWebsite.IntegrationTests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
},
"BookingsApi.Client": {
"type": "Transitive",
"resolved": "1.49.10",
"contentHash": "oXH1qyRZhkrbVbdZB7QsO8O0a/6SRCrB71Hb0leiRNUGr/xb0IYdqpaTr6imTeo6zimGxieMiu9uKMsnFpVA/w==",
"resolved": "1.49.13",
"contentHash": "3+T2Q9IbsFFTVFRY7vTpNbfChHjilgQQIrAm4ptwPoH6HP9UWtrrM/JOj8/esfOMlajZvBziSXd7qfQPPnepuA==",
"dependencies": {
"Microsoft.AspNetCore.Mvc.Core": "2.2.5"
}
Expand Down Expand Up @@ -2101,7 +2101,7 @@
"type": "Project",
"dependencies": {
"AspNetCore.HealthChecks.Uris": "[6.0.3, )",
"BookingsApi.Client": "[1.49.10, )",
"BookingsApi.Client": "[1.49.13, )",
"FluentValidation.AspNetCore": "[10.4.0, )",
"LaunchDarkly.ServerSdk": "[7.0.3, )",
"MicroElements.Swashbuckle.FluentValidation": "[5.7.0, )",
Expand Down
6 changes: 3 additions & 3 deletions AdminWebsite/AdminWebsite.UnitTests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
},
"BookingsApi.Client": {
"type": "Transitive",
"resolved": "1.49.10",
"contentHash": "oXH1qyRZhkrbVbdZB7QsO8O0a/6SRCrB71Hb0leiRNUGr/xb0IYdqpaTr6imTeo6zimGxieMiu9uKMsnFpVA/w==",
"resolved": "1.49.13",
"contentHash": "3+T2Q9IbsFFTVFRY7vTpNbfChHjilgQQIrAm4ptwPoH6HP9UWtrrM/JOj8/esfOMlajZvBziSXd7qfQPPnepuA==",
"dependencies": {
"Microsoft.AspNetCore.Mvc.Core": "2.2.5"
}
Expand Down Expand Up @@ -1979,7 +1979,7 @@
"type": "Project",
"dependencies": {
"AspNetCore.HealthChecks.Uris": "[6.0.3, )",
"BookingsApi.Client": "[1.49.10, )",
"BookingsApi.Client": "[1.49.13, )",
"FluentValidation.AspNetCore": "[10.4.0, )",
"LaunchDarkly.ServerSdk": "[7.0.3, )",
"MicroElements.Swashbuckle.FluentValidation": "[5.7.0, )",
Expand Down
2 changes: 1 addition & 1 deletion AdminWebsite/AdminWebsite/AdminWebsite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="6.0.3" />
<PackageReference Include="BookingsApi.Client" Version="1.49.10" />
<PackageReference Include="BookingsApi.Client" Version="1.49.13" />
<PackageReference Include="LaunchDarkly.ServerSdk" Version="7.0.3" />
<PackageReference Include="MicroElements.Swashbuckle.FluentValidation" Version="5.7.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.51.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ describe('JusticeUserFormComponent', () => {
component.ngOnChanges(changes);

// assert
expect(component.form.controls.contactTelephone.disabled).toBeTruthy();
expect(component.form.controls.firstName.disabled).toBeTruthy();
expect(component.form.controls.lastName.disabled).toBeTruthy();
expect(component.form.controls.contactTelephone.disabled).toBeFalsy();
expect(component.form.controls.firstName.disabled).toBeFalsy();
expect(component.form.controls.lastName.disabled).toBeFalsy();
expect(component.form.controls.username.disabled).toBeTruthy();
});
});
Expand Down Expand Up @@ -189,7 +189,7 @@ describe('JusticeUserFormComponent', () => {
expect(component.failedSaveMessage).toBe(Constants.Error.JusticeUserForm.SaveErrorDuplicateUser);
}));

it('should set control errors for properties returned by a validationproblem object from the api', fakeAsync(() => {
it('should set control errors for properties returned by a validationproblem object from the api, from add mode', fakeAsync(() => {
// arrange
const validationProblem = new ValidationProblemDetails({
errors: {
Expand All @@ -210,6 +210,37 @@ describe('JusticeUserFormComponent', () => {

// act
component.onSave();
component.mode = 'add';
tick();

// assert
expect(component.failedSaveMessage).toBe(validationProblem.title);
expect(component.form.controls.firstName.errors.errorMessage).toContain(validationProblem.errors.FirstName);
expect(component.form.controls.lastName.errors.errorMessage).toContain(validationProblem.errors.LastName);
}));

it('should set control errors for properties returned by a validationproblem object from the api, from edit endpoint', fakeAsync(() => {
// arrange
const validationProblem = new ValidationProblemDetails({
errors: {
FirstName: ['First name is required'],
LastName: ['Last Name is required'],
ContactEmail: ['Contact Email is required']
},
type: 'https://tools.ietf.org/html/rfc7231#section-6.5.1',
title: 'One or more validation errors occurred.',
status: 400
});

justiceUsersServiceSpy.editJusticeUser.and.returnValue(
throwError(
() => new BookHearingException('Bad Request', 400, 'One or more validation errors occurred.', null, validationProblem)
)
);

// act
component.mode = 'edit';
component.onSave();
tick();

// assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class JusticeUserFormComponent implements OnChanges {
ngOnChanges(changes: SimpleChanges): void {
const mode = changes['mode'];
if (mode.currentValue === 'edit') {
['firstName', 'lastName', 'username', 'contactTelephone'].forEach(field => this.form.controls[field].disable());
['username'].forEach(field => this.form.controls[field].disable());
}
}

Expand Down Expand Up @@ -170,10 +170,23 @@ export class JusticeUserFormComponent implements OnChanges {

private updateExistingUser() {
const roles = this.getRoles();
this.justiceUserService.editJusticeUser(this._justiceUser.id, this.form.getRawValue().username, roles).subscribe({
next: newJusticeUser => this.onSaveSucceeded(newJusticeUser),
error: (error: string | BookHearingException) => this.onSaveFailed(error)
});
this.justiceUserService
.editJusticeUser(
this._justiceUser.id,
this.form.getRawValue().username,
this.form.getRawValue().firstName,
this.form.getRawValue().lastName,
this.form.getRawValue().contactTelephone,
roles
)
.pipe(
catchError((error: string | BookHearingException) => {
this.onSaveFailed(error);
this.cdRef.markForCheck();
return NEVER;
})
)
.subscribe((newJusticeUser: JusticeUserResponse) => this.onSaveSucceeded(newJusticeUser));
}

private getRoles(): JusticeUserRole[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8286,6 +8286,9 @@ export class EditJusticeUserRequest implements IEditJusticeUserRequest {
id?: string;
username?: string | undefined;
roles?: JusticeUserRole[] | undefined;
first_name?: string | undefined;
last_name?: string | undefined;
contact_telephone?: string | undefined;

constructor(data?: IEditJusticeUserRequest) {
if (data) {
Expand All @@ -8303,6 +8306,9 @@ export class EditJusticeUserRequest implements IEditJusticeUserRequest {
this.roles = [] as any;
for (let item of _data['roles']) this.roles!.push(item);
}
this.first_name = _data['first_name'];
this.last_name = _data['last_name'];
this.contact_telephone = _data['contact_telephone'];
}
}

Expand All @@ -8321,6 +8327,9 @@ export class EditJusticeUserRequest implements IEditJusticeUserRequest {
data['roles'] = [];
for (let item of this.roles) data['roles'].push(item);
}
data['first_name'] = this.first_name;
data['last_name'] = this.last_name;
data['contact_telephone'] = this.contact_telephone;
return data;
}
}
Expand All @@ -8329,6 +8338,9 @@ export interface IEditJusticeUserRequest {
id?: string;
username?: string | undefined;
roles?: JusticeUserRole[] | undefined;
first_name?: string | undefined;
last_name?: string | undefined;
contact_telephone?: string | undefined;
}

export enum JusticeUserRole {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,13 @@ describe('JusticeUsersService', () => {
const request = new EditJusticeUserRequest({
id,
username,
first_name: firstName,
last_name: lastName,
contact_telephone: telephone,
roles: roles
});

combineLatest([service.allUsers$, service.editJusticeUser(id, username, roles)]).subscribe(
combineLatest([service.allUsers$, service.editJusticeUser(id, username, firstName, lastName, telephone, roles)]).subscribe(
([_, result]: [JusticeUserResponse[], JusticeUserResponse]) => {
expect(clientApiSpy.getUserList).toHaveBeenCalledTimes(2);
expect(result).toEqual(existingUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ export class JusticeUsersService {
return this.apiClient.addNewJusticeUser(request).pipe(tap(() => this.refresh$.next()));
}

editJusticeUser(id: string, username: string, roles: JusticeUserRole[]) {
editJusticeUser(id: string, username: string, firstName: string, lastName: string, telephone: string, roles: JusticeUserRole[]) {
const request = new EditJusticeUserRequest({
id,
username,
first_name: firstName,
last_name: lastName,
contact_telephone: telephone,
roles
});
return this.apiClient.editJusticeUser(request).pipe(tap(() => this.refresh$.next()));
Expand Down
6 changes: 3 additions & 3 deletions AdminWebsite/AdminWebsite/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
},
"BookingsApi.Client": {
"type": "Direct",
"requested": "[1.49.10, )",
"resolved": "1.49.10",
"contentHash": "oXH1qyRZhkrbVbdZB7QsO8O0a/6SRCrB71Hb0leiRNUGr/xb0IYdqpaTr6imTeo6zimGxieMiu9uKMsnFpVA/w==",
"requested": "[1.49.13, )",
"resolved": "1.49.13",
"contentHash": "3+T2Q9IbsFFTVFRY7vTpNbfChHjilgQQIrAm4ptwPoH6HP9UWtrrM/JOj8/esfOMlajZvBziSXd7qfQPPnepuA==",
"dependencies": {
"Microsoft.AspNetCore.Mvc.Core": "2.2.5"
}
Expand Down
2 changes: 1 addition & 1 deletion charts/vh-admin-web/values.dev.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ java:
AZUREAD__POSTLOGOUTREDIRECTURI: https://${SERVICE_FQDN}/logout
AZUREAD__REDIRECTURI: https://${SERVICE_FQDN}/home
DOM1__POSTLOGOUTREDIRECTURI: https://${SERVICE_FQDN}/logout
DOM1__REDIRECTURI: https://${SERVICE_FQDN}/home
DOM1__REDIRECTURI: https://${SERVICE_FQDN}/home

0 comments on commit ad38c3c

Please sign in to comment.