Remove name property from Developer
MODIFY
src/app/components/admin/create-developer/create-developer.component.html
src/app/components/admin/create-developer/create-developer.component.html
<app-client-mapping #clientmapping [assignedClients]="[]"></app-client-mapping>
<p>
<button
- [disabled]="!this.checkDeveloperNotExists(this.userFormGroup.get('username').value) || !userFormGroup.valid"
+ [disabled]="!this.checkDeveloperNotExists(this.userFormGroup.get('username').value) || !this.checkUserExistsInKeycloak(this.userFormGroup.get('username').value) || !userFormGroup.valid"
(click)="insertDeveloper()">Save
</button>
<button routerLink="/admin">Cancel</button>

MODIFY
src/app/components/admin/create-developer/create-developer.component.spec.ts
src/app/components/admin/create-developer/create-developer.component.spec.ts
@@ -20,9 +20,7 @@ describe('CreateDeveloperComponent', () => {
let component: CreateDeveloperComponent;
let fixture: ComponentFixture<CreateDeveloperComponent>;
- const adminService = jasmine.createSpyObj('adminService', ['getKeycloakUsers', 'getAllClients']);
- adminService.getKeycloakUsers.and.returnValue(from(
- [{
+ const keycloakUsers = [{
id: 'cf79aa9e-6443-4d1b-99cb-a743d335b2b7',
username: 'admin',
enabled: false,
@@ -41,7 +39,11 @@ describe('CreateDeveloperComponent', () => {
impersonate: false,
manage: true
}
- }]
+ }];
+
+ const adminService = jasmine.createSpyObj('adminService', ['getKeycloakUsers', 'getAllClients']);
+ adminService.getKeycloakUsers.and.returnValue(from(
+ keycloakUsers
));
adminService.getAllClients.and.returnValue(from(
[
@@ -79,7 +81,6 @@ describe('CreateDeveloperComponent', () => {
const toasterService = jasmine.createSpyObj('toasterService', ['pop']);
const loadingSpinnerService = jasmine.createSpyObj('loadingSpinnerService', ['startWaiting', 'stopWaiting']);
-
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CreateDeveloperComponent, ClientMappingComponent ],
@@ -106,7 +107,7 @@ describe('CreateDeveloperComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(CreateDeveloperComponent);
component = fixture.componentInstance;
- fixture.detectChanges();
+ component.ngOnInit();
});
it('should create', () => {
expect(component).toBeTruthy();
@@ -115,8 +116,17 @@ describe('CreateDeveloperComponent', () => {
it('checkDeveloperNotExists', () => {
expect(developerDataCache.developers).not.toBe(null);
expect(developerDataCache.developers).not.toBe(undefined);
- expect(component.checkDeveloperNotExists(undefined)).toBeFalsy();
+ // expects true for undefined input to hide the notification in the UI
+ expect(component.checkDeveloperNotExists(undefined)).toBeTruthy();
expect(component.checkDeveloperNotExists('Alice')).toBeFalsy();
expect(component.checkDeveloperNotExists('Bob')).toBeTruthy();
});
+
+ it('checkUserExistsInKeycloak', () => {
+ component.keycloakUsers = keycloakUsers;
+ expect(component.checkUserExistsInKeycloak(undefined)).toBeFalsy();
+ expect(component.checkUserExistsInKeycloak(null)).toBeFalsy();
+ expect(component.checkUserExistsInKeycloak('alice')).toBeFalsy();
+ expect(component.checkUserExistsInKeycloak('admin')).toBeTruthy();
+ });
});

MODIFY
src/app/components/admin/create-developer/create-developer.component.ts
src/app/components/admin/create-developer/create-developer.component.ts
@@ -102,7 +102,7 @@ export class CreateDeveloperComponent implements OnInit, OnDestroy {
this.toasterService.pop('error', errorMessage, error.message);
const developerIndexToDelete = this.developerDataCache.developers
- .findIndex(developer => developer.name.toLowerCase() === developerToCreate.name.toLowerCase());
+ .findIndex(developer => developer.id.toLowerCase() === developerToCreate.id.toLowerCase());
if (developerIndexToDelete !== -1) {
this.developerDataCache.developers.splice(developerIndexToDelete, 1);
}
@@ -114,9 +114,20 @@ export class CreateDeveloperComponent implements OnInit, OnDestroy {
* @param username the developer username
*/
checkDeveloperNotExists(username: string) {
+ if (username && username.length !== 0) {
return this.developerDataCache.developers
- && username !== undefined
- && this.developerDataCache.developers.find((d) => d.name.toLowerCase() === username.toLowerCase()) === undefined;
+ && this.developerDataCache.developers.find((d) => d.id.toLowerCase() === username.toLowerCase()) === undefined;
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * Check if the user exists in keycloak
+ * @param username the developer username
+ */
+ checkUserExistsInKeycloak(username: string) {
+ return this.keycloakUsers.find((u) => u.username.toLowerCase() === username) !== undefined;
}
/**

MODIFY
src/app/components/admin/edit-developer/edit-developer.component.html
src/app/components/admin/edit-developer/edit-developer.component.html
-<h1 *ngIf="developer">Edit Developer&#58; {{developer.name}}</h1>
+<h1 *ngIf="developer">Edit Developer&#58; {{developer.id}}</h1>
<div class="wrapper">
<h3>Update Client-Mapping</h3>

MODIFY
src/app/components/admin/services/admin.service.ts
src/app/components/admin/services/admin.service.ts
@@ -79,7 +79,6 @@ export class AdminService {
public updateDeveloper(developer: Developer) {
const url = this.apiMgmtUiRestUrl + '/developers/' + developer.id;
return this.http.put(url, {
- name: developer.name,
clients: developer.clients
});
}

MODIFY
src/app/services/api-data.service.ts
src/app/services/api-data.service.ts
@@ -118,7 +118,6 @@ export interface ClientMapping {
*/
export interface Developer {
id: string;
- name: string;
clients: Array<ClientMapping>;
}

MODIFY
src/app/type-definitions/developerImpl.ts
src/app/type-definitions/developerImpl.ts
@@ -6,5 +6,4 @@ import {ClientMapping, Developer} from '../services/api-data.service';
export class DeveloperImpl implements Developer {
clients: Array<ClientMapping>;
id: string;
- name: string;
}

GW-378: Remove name property from Developer