diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.html b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.html index 7f6e1de77122d3dfabd81e867bfdca9d24001600..0db247eb4db913930d20be531f19e78a5382f440 100644 --- a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.html +++ b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.html @@ -6,14 +6,14 @@ ></admin-organisationseinheit-form> <admin-secondary-button - (clickEmitter)="newGroup()" + (clickEmitter)="openDialogForNewGroup()" data-test-id="organisationseinheit-open-dialog-button" label="Neue Organisationseinheit anlegen" > </admin-secondary-button> <admin-organisationseinheit-list - [organisationseinheitItems]="(groupState$ | async).organisationseinheitItems" + [organisationseinheitItems]="(organisationseinheitState$ | async).organisationseinheitItems" (editOrganisationseinheit)="editOrganisationseinheit($event)" (deleteOrganisationseinheit)="deleteOrganisationseinheit($event)" data-test-id="organisationseinheit-list" diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.spec.ts b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.spec.ts index b00110409ca1a7d07f26d47af409735468c4e26a..3aef9ca92941f669520fbce4c3aeb2bf5d3f6184 100644 --- a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.spec.ts +++ b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.spec.ts @@ -23,7 +23,7 @@ describe('OrganisationseinheitContainerComponent', () => { let component: OrganisationseinheitContainerComponent; let fixture: ComponentFixture<OrganisationseinheitContainerComponent>; - const keycloakService: Mock<UserService> = mock(UserService); + const userService: Mock<UserService> = mock(UserService); const dialogOpenButtonSelector: string = getDataTestIdOf( 'organisationseinheit-open-dialog-button', @@ -42,13 +42,13 @@ describe('OrganisationseinheitContainerComponent', () => { MockComponent(OrganisationseinheitFormComponent), MockComponent(OrganisationseinheitListComponent), ], - providers: [{ provide: UserService, useValue: keycloakService }], + providers: [{ provide: UserService, useValue: userService }], }).compileComponents(); fixture = TestBed.createComponent(OrganisationseinheitContainerComponent); component = fixture.componentInstance; - keycloakService.getOrganisationseinheitState = jest + userService.getOrganisationseinheitState = jest .fn() .mockReturnValue(of(createOrganisationseinheitState(organisationseinheitItems))); fixture.detectChanges(); @@ -77,21 +77,21 @@ describe('OrganisationseinheitContainerComponent', () => { }); it('should open form for editing on editGroup event', () => { - const group: any = organisationseinheitItems[0]; + const organisationseinheit: Organisationseinheit = organisationseinheitItems[0]; formComponent.openEdit = jest.fn(); - listComponent.editOrganisationseinheit.emit(group); + listComponent.editOrganisationseinheit.emit(organisationseinheit); - expect(formComponent.openEdit).toHaveBeenCalledWith(group); + expect(formComponent.openEdit).toHaveBeenCalledWith(organisationseinheit); }); it('should call delete form on deleteGroup event', () => { - const group: any = organisationseinheitItems[0]; + const organisationseinheit: Organisationseinheit = organisationseinheitItems[0]; formComponent.delete = jest.fn(); - listComponent.deleteOrganisationseinheit.emit(group); + listComponent.deleteOrganisationseinheit.emit(organisationseinheit); - expect(formComponent.delete).toHaveBeenCalledWith(group); + expect(formComponent.delete).toHaveBeenCalledWith(organisationseinheit); }); }); }); diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.ts b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.ts index 282a5b9257c4be36eb7f9abd0efa5693d53318e5..6738fcfddc59c4cd913f1e95d466bd9c33f4e57b 100644 --- a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.ts +++ b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.ts @@ -9,18 +9,18 @@ import { OrganisationseinheitFormComponent } from './organisationseinheit-form/o templateUrl: './organisationseinheit-container.component.html', }) export class OrganisationseinheitContainerComponent implements OnInit { - groupState$: Observable<OrganisationseinheitState>; + organisationseinheitState$: Observable<OrganisationseinheitState>; @ViewChild(OrganisationseinheitFormComponent) private form!: OrganisationseinheitFormComponent; - constructor(private keycloakService: UserService) {} + constructor(private userService: UserService) {} ngOnInit(): void { - this.groupState$ = this.keycloakService.getOrganisationseinheitState(); + this.organisationseinheitState$ = this.userService.getOrganisationseinheitState(); } - newGroup() { + openDialogForNewGroup() { this.form.open(); } diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.html b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.html index 922736dff9492c7536f0027d362367cad3c80229..b2f802746800eba012216c7670f9ea2d27ad63cf 100644 --- a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.html +++ b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.html @@ -17,12 +17,12 @@ <text-field label="Name" data-test-id="organisationseinheit-name" - [formControlName]="OrganisationseinheitFormService.ORGANISATIONS_EINHEIT_NAME_FIELD" + [formControlName]="OrganisationseinheitFormService.ORGANISATIONSEINHEIT_NAME_FIELD" ></text-field> <text-field label="OrganisationseinheitID" data-test-id="organisationseinheit-id" - [formControlName]="OrganisationseinheitFormService.ORGANISATIONS_EINHEIT_IDS_FIELD" + [formControlName]="OrganisationseinheitFormService.ORGANISATIONSEINHEIT_IDS_FIELD" ></text-field> <admin-primary-button diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.spec.ts b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.spec.ts index d76267b8ab937b4d792dbb2ba1f2977715566fd6..2d0893b6f270dbcaec4df67938b142659738c3e2 100644 --- a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.spec.ts +++ b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.spec.ts @@ -62,12 +62,12 @@ describe('OrganisationseinheitFormComponent', () => { describe('form element', () => { const fields: string[][] = [ [ - OrganisationseinheitFormservice.ORGANISATIONS_EINHEIT_NAME_FIELD, + OrganisationseinheitFormservice.ORGANISATIONSEINHEIT_NAME_FIELD, 'Name', 'organisationseinheit-name', ], [ - OrganisationseinheitFormservice.ORGANISATIONS_EINHEIT_IDS_FIELD, + OrganisationseinheitFormservice.ORGANISATIONSEINHEIT_IDS_FIELD, 'OrganisationseinheitID', 'organisationseinheit-id', ], diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit.formservice.spec.ts b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit.formservice.spec.ts index 413c0651b0329bd6c8e121adf824b0c2e89097fb..d7d9d2d97ec2b926c0e6086bdfa57f08524d87fb 100644 --- a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit.formservice.spec.ts +++ b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit.formservice.spec.ts @@ -3,8 +3,8 @@ import { OrganisationseinheitFormservice } from './organisationseinheit.formserv import { Mock, mock, useFromMock } from '@alfa-client/test-utils'; import { UserService } from '../../../user/user.service'; import { - createKeycloakAdminError, createOrganisationseinheit, + createOrganisationseinheitError, } from '../../../../../test/keycloak/keycloak'; import { Organisationseinheit, @@ -28,8 +28,8 @@ describe('OrganisationseinheitFormService', () => { formService = new OrganisationseinheitFormservice(formBuilder, useFromMock(userService)); organisationseinheit = createOrganisationseinheit(); formService.form.setValue({ - [OrganisationseinheitFormservice.ORGANISATIONS_EINHEIT_NAME_FIELD]: organisationseinheit.name, - [OrganisationseinheitFormservice.ORGANISATIONS_EINHEIT_IDS_FIELD]: + [OrganisationseinheitFormservice.ORGANISATIONSEINHEIT_NAME_FIELD]: organisationseinheit.name, + [OrganisationseinheitFormservice.ORGANISATIONSEINHEIT_IDS_FIELD]: organisationseinheit.organisationseinheitIds.join(','), }); }); @@ -44,7 +44,7 @@ describe('OrganisationseinheitFormService', () => { }); it('should call handle error with service call observable', fakeAsync(() => { - const error: OrganisationseinheitError = createKeycloakAdminError(); + const error: OrganisationseinheitError = createOrganisationseinheitError(); formService.callService = jest.fn().mockReturnValue(throwError(() => error)); formService.submit().subscribe(); @@ -54,7 +54,7 @@ describe('OrganisationseinheitFormService', () => { })); it('should emit emit progress as false on error', () => { - const error: OrganisationseinheitError = createKeycloakAdminError(); + const error: OrganisationseinheitError = createOrganisationseinheitError(); formService.callService = jest.fn().mockReturnValue(hot('a#', { a: true }, error)); const progressObservable: Observable<boolean> = formService.submit(); @@ -74,7 +74,7 @@ describe('OrganisationseinheitFormService', () => { describe('call service', () => { it('should use create if is not patch', () => { formService.isPatch = jest.fn().mockReturnValue(false); - formService.callCreateOrganisationseinheit = jest.fn().mockReturnValue(singleHot(true)); + formService.create = jest.fn().mockReturnValue(singleHot(true)); const progressObservable: Observable<boolean> = formService.callService(); @@ -83,7 +83,7 @@ describe('OrganisationseinheitFormService', () => { it('should use save if is patch', () => { formService.isPatch = jest.fn().mockReturnValue(true); - formService.callSaveOrganisationseinheit = jest.fn().mockReturnValue(singleHot(true)); + formService.save = jest.fn().mockReturnValue(singleHot(true)); const progressObservable: Observable<boolean> = formService.callService(); @@ -108,9 +108,9 @@ describe('OrganisationseinheitFormService', () => { }); }); - describe('call create organisationseinheit', () => { + describe('create', () => { it('should call create organisationseinheit', () => { - formService.callCreateOrganisationseinheit(); + formService.create(); expect(userService.createOrganisationseinheit).toHaveBeenCalledWith( organisationseinheit.name, @@ -120,10 +120,10 @@ describe('OrganisationseinheitFormService', () => { it('should call create organisationseinheit with empty form', () => { formService.form.setValue({ - [OrganisationseinheitFormservice.ORGANISATIONS_EINHEIT_NAME_FIELD]: null, - [OrganisationseinheitFormservice.ORGANISATIONS_EINHEIT_IDS_FIELD]: null, + [OrganisationseinheitFormservice.ORGANISATIONSEINHEIT_NAME_FIELD]: null, + [OrganisationseinheitFormservice.ORGANISATIONSEINHEIT_IDS_FIELD]: null, }); - formService.callCreateOrganisationseinheit(); + formService.create(); expect(userService.createOrganisationseinheit).toHaveBeenCalledWith(null, []); }); @@ -131,17 +131,17 @@ describe('OrganisationseinheitFormService', () => { it('should return progress observable', () => { userService.createOrganisationseinheit.mockReturnValue(singleCold(true)); - const progressObservable: Observable<boolean> = formService.callCreateOrganisationseinheit(); + const progressObservable: Observable<boolean> = formService.create(); expect(progressObservable).toBeObservable(singleCold(true)); }); }); - describe('call save organisationseinheit', () => { + describe('save', () => { it('should call save organisationseinheit', () => { formService.source = createOrganisationseinheit(); - formService.callSaveOrganisationseinheit(); + formService.save(); expect(userService.saveOrganisationseinheit).toHaveBeenCalledWith({ id: formService.source.id, @@ -153,10 +153,10 @@ describe('OrganisationseinheitFormService', () => { it('should call save organisationseinheit with empty form', () => { formService.source = createOrganisationseinheit(); formService.form.setValue({ - [OrganisationseinheitFormservice.ORGANISATIONS_EINHEIT_NAME_FIELD]: null, - [OrganisationseinheitFormservice.ORGANISATIONS_EINHEIT_IDS_FIELD]: null, + [OrganisationseinheitFormservice.ORGANISATIONSEINHEIT_NAME_FIELD]: null, + [OrganisationseinheitFormservice.ORGANISATIONSEINHEIT_IDS_FIELD]: null, }); - formService.callSaveOrganisationseinheit(); + formService.save(); expect(userService.saveOrganisationseinheit).toHaveBeenCalledWith({ id: formService.source.id, @@ -168,7 +168,7 @@ describe('OrganisationseinheitFormService', () => { it('should return progress observable', () => { userService.saveOrganisationseinheit.mockReturnValue(singleCold(true)); - const progressObservable: Observable<boolean> = formService.callSaveOrganisationseinheit(); + const progressObservable: Observable<boolean> = formService.save(); expect(progressObservable).toBeObservable(singleCold(true)); }); @@ -180,20 +180,20 @@ describe('OrganisationseinheitFormService', () => { OrganisationseinheitErrorType.NAME_MISSING, ])('should set error on name field on %s', (type: OrganisationseinheitErrorType) => { const error: OrganisationseinheitError = { - ...createKeycloakAdminError(), + ...createOrganisationseinheitError(), errorType: type, }; formService.handleError(error); const errorMessage = formService.form.getError( type, - OrganisationseinheitFormservice.ORGANISATIONS_EINHEIT_NAME_FIELD, + OrganisationseinheitFormservice.ORGANISATIONSEINHEIT_NAME_FIELD, ); expect(errorMessage).toEqual(getOrganisationseinheitErrorMessage(error)); }); it('should not set error on name field for unknown errors', () => { - const unknownError: OrganisationseinheitError = createKeycloakAdminError(undefined); + const unknownError: OrganisationseinheitError = createOrganisationseinheitError(undefined); formService.handleError(unknownError); @@ -214,7 +214,7 @@ describe('OrganisationseinheitFormService', () => { formService.patch(organisationseinheit); const formControl: AbstractControl = formService.form.get( - OrganisationseinheitFormservice.ORGANISATIONS_EINHEIT_NAME_FIELD, + OrganisationseinheitFormservice.ORGANISATIONSEINHEIT_NAME_FIELD, ); expect(formControl.value).toEqual(organisationseinheit.name); }); @@ -223,7 +223,7 @@ describe('OrganisationseinheitFormService', () => { formService.patch(organisationseinheit); const formControl: AbstractControl = formService.form.get( - OrganisationseinheitFormservice.ORGANISATIONS_EINHEIT_IDS_FIELD, + OrganisationseinheitFormservice.ORGANISATIONSEINHEIT_IDS_FIELD, ); expect(formControl.value).toEqual(organisationseinheit.organisationseinheitIds.join(', ')); }); diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit.formservice.ts b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit.formservice.ts index d12162663e91555caff67e0618aa88ace726074c..73ff18ade3415b5bc09ab1576ffd2cba62ebed50 100644 --- a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit.formservice.ts +++ b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit.formservice.ts @@ -12,8 +12,8 @@ import { isNotNil } from '@alfa-client/tech-shared'; @Injectable() export class OrganisationseinheitFormservice { - public static readonly ORGANISATIONS_EINHEIT_NAME_FIELD: string = 'group'; - public static readonly ORGANISATIONS_EINHEIT_IDS_FIELD: string = 'organisationseinheit'; + public static readonly ORGANISATIONSEINHEIT_NAME_FIELD: string = 'name'; + public static readonly ORGANISATIONSEINHEIT_IDS_FIELD: string = 'organisationseinheit'; form: UntypedFormGroup; @@ -24,8 +24,8 @@ export class OrganisationseinheitFormservice { private userService: UserService, ) { this.form = this.formBuilder.group({ - [OrganisationseinheitFormservice.ORGANISATIONS_EINHEIT_NAME_FIELD]: new FormControl(''), - [OrganisationseinheitFormservice.ORGANISATIONS_EINHEIT_IDS_FIELD]: new FormControl(''), + [OrganisationseinheitFormservice.ORGANISATIONSEINHEIT_NAME_FIELD]: new FormControl(''), + [OrganisationseinheitFormservice.ORGANISATIONSEINHEIT_IDS_FIELD]: new FormControl(''), }); } @@ -39,19 +39,17 @@ export class OrganisationseinheitFormservice { } callService(): Observable<boolean> { - return this.isPatch() ? - this.callSaveOrganisationseinheit() - : this.callCreateOrganisationseinheit(); + return this.isPatch() ? this.save() : this.create(); } - callCreateOrganisationseinheit(): Observable<boolean> { + create(): Observable<boolean> { return this.userService.createOrganisationseinheit( this.getName(), this.getOrganisationseinheitIds(), ); } - callSaveOrganisationseinheit(): Observable<boolean> { + save(): Observable<boolean> { return this.userService.saveOrganisationseinheit({ ...this.source, name: this.getName(), @@ -60,12 +58,12 @@ export class OrganisationseinheitFormservice { } private getName(): string { - return this.form.get(OrganisationseinheitFormservice.ORGANISATIONS_EINHEIT_NAME_FIELD).value; + return this.form.get(OrganisationseinheitFormservice.ORGANISATIONSEINHEIT_NAME_FIELD).value; } private getOrganisationseinheitIds(): string[] { return this.splitOrganisationseinheitIds( - this.form.get(OrganisationseinheitFormservice.ORGANISATIONS_EINHEIT_IDS_FIELD).value ?? '', + this.form.get(OrganisationseinheitFormservice.ORGANISATIONSEINHEIT_IDS_FIELD).value ?? '', ); } @@ -79,7 +77,7 @@ export class OrganisationseinheitFormservice { error.errorType === OrganisationseinheitErrorType.NAME_MISSING ) { const control: AbstractControl = this.form.get( - OrganisationseinheitFormservice.ORGANISATIONS_EINHEIT_NAME_FIELD, + OrganisationseinheitFormservice.ORGANISATIONSEINHEIT_NAME_FIELD, ); control.setErrors({ [error.errorType]: getOrganisationseinheitErrorMessage(error), @@ -98,8 +96,8 @@ export class OrganisationseinheitFormservice { this.form.reset(); this.source = organisationseinheit; this.form.patchValue({ - [OrganisationseinheitFormservice.ORGANISATIONS_EINHEIT_NAME_FIELD]: organisationseinheit.name, - [OrganisationseinheitFormservice.ORGANISATIONS_EINHEIT_IDS_FIELD]: + [OrganisationseinheitFormservice.ORGANISATIONSEINHEIT_NAME_FIELD]: organisationseinheit.name, + [OrganisationseinheitFormservice.ORGANISATIONSEINHEIT_IDS_FIELD]: organisationseinheit.organisationseinheitIds.join(', '), }); } diff --git a/alfa-client/libs/admin-settings/src/lib/user/user-repository.service.ts b/alfa-client/libs/admin-settings/src/lib/user/user.repository.service.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/user/user-repository.service.ts rename to alfa-client/libs/admin-settings/src/lib/user/user.repository.service.ts diff --git a/alfa-client/libs/admin-settings/src/lib/user/user.repository.spec.ts b/alfa-client/libs/admin-settings/src/lib/user/user.repository.spec.ts index 36bcec24ebf9352c0bab55f80a2f4f78eb7976d3..7550e9d514f0d3f3e449541af8b181068e4f6ee0 100644 --- a/alfa-client/libs/admin-settings/src/lib/user/user.repository.spec.ts +++ b/alfa-client/libs/admin-settings/src/lib/user/user.repository.spec.ts @@ -1,12 +1,12 @@ import { fakeAsync, TestBed, tick } from '@angular/core/testing'; -import { UserRepository } from './user-repository.service'; +import { UserRepository } from './user.repository.service'; import KcAdminClient, { NetworkError } from '@keycloak/keycloak-admin-client'; import { Mock, mock } from '@alfa-client/test-utils'; import { createGroupRepresentation, - createKeycloakAdminError, createNetworkError, createOrganisationseinheit, + createOrganisationseinheitError, } from '../../../test/keycloak/keycloak'; import GroupRepresentation from '@keycloak/keycloak-admin-client/lib/defs/groupRepresentation'; import { @@ -20,9 +20,9 @@ import { faker } from '@faker-js/faker'; import { OAuthService } from 'angular-oauth2-oidc'; import { Groups } from '@keycloak/keycloak-admin-client/lib/resources/groups'; -describe('KeycloakRepository', () => { +describe('UserRepository', () => { const accessToken: string = faker.random.alphaNumeric(40); - const error: OrganisationseinheitError = createKeycloakAdminError(); + const error: OrganisationseinheitError = createOrganisationseinheitError(); const networkError: NetworkError = createNetworkError(400, ''); let repository: UserRepository; @@ -272,7 +272,7 @@ describe('KeycloakRepository', () => { describe('map create groups network error', () => { it('should interpret 409 status as name conflict', () => { - const keycloakError: OrganisationseinheitError = createKeycloakAdminError( + const keycloakError: OrganisationseinheitError = createOrganisationseinheitError( OrganisationseinheitErrorType.NAME_CONFLICT, ); const networkError: NetworkError = createNetworkError(409, keycloakError.detail); @@ -283,7 +283,7 @@ describe('KeycloakRepository', () => { }); it('should interpret 400 status as name missing', () => { - const keycloakError: OrganisationseinheitError = createKeycloakAdminError( + const keycloakError: OrganisationseinheitError = createOrganisationseinheitError( OrganisationseinheitErrorType.NAME_MISSING, ); const networkError: NetworkError = createNetworkError(400, keycloakError.detail); diff --git a/alfa-client/libs/admin-settings/src/lib/user/user.service.spec.ts b/alfa-client/libs/admin-settings/src/lib/user/user.service.spec.ts index c70dfd6d59b0c63ec895167391d731284d2f1f40..70da66080051d7c7a391b359a33b378dccb7c0f3 100644 --- a/alfa-client/libs/admin-settings/src/lib/user/user.service.spec.ts +++ b/alfa-client/libs/admin-settings/src/lib/user/user.service.spec.ts @@ -1,5 +1,5 @@ import { UserService } from './user.service'; -import { UserRepository } from './user-repository.service'; +import { UserRepository } from './user.repository.service'; import { mock, Mock, useFromMock } from '@alfa-client/test-utils'; import { createOrganisationseinheit } from '../../../test/keycloak/keycloak'; import { firstValueFrom, lastValueFrom, Observable, of } from 'rxjs'; @@ -7,7 +7,7 @@ import { Organisationseinheit } from './user.model'; import { cold } from 'jest-marbles'; import { fakeAsync, tick } from '@angular/core/testing'; -describe('KeycloakService', () => { +describe('UserService', () => { let service: UserService; let repository: Mock<UserRepository>; const sortedNames: string[] = ['BBBB', 'CCCC', 'XXXX']; @@ -162,24 +162,30 @@ describe('KeycloakService', () => { }); describe('create organisationseinheit', () => { - const newGroup: Organisationseinheit = createOrganisationseinheit(); + const organisationseinheit: Organisationseinheit = createOrganisationseinheit(); beforeEach(() => { - repository.createOrganisationseinheit.mockReturnValue(of(newGroup)); + repository.createOrganisationseinheit.mockReturnValue(of(organisationseinheit)); }); it('should use set loading until first', () => { - service.createOrganisationseinheit(newGroup.name, newGroup.organisationseinheitIds); + service.createOrganisationseinheit( + organisationseinheit.name, + organisationseinheit.organisationseinheitIds, + ); expect(setLoadingUntilFirstSpy).toHaveBeenCalled(); }); it('should call repository for save', () => { - service.createOrganisationseinheit(newGroup.name, newGroup.organisationseinheitIds); + service.createOrganisationseinheit( + organisationseinheit.name, + organisationseinheit.organisationseinheitIds, + ); expect(repository.createOrganisationseinheit).toHaveBeenCalledWith( - newGroup.name, - newGroup.organisationseinheitIds, + organisationseinheit.name, + organisationseinheit.organisationseinheitIds, ); }); @@ -188,13 +194,16 @@ describe('KeycloakService', () => { setOrganisationseinheitItemsSpy.mockClear(); service - .createOrganisationseinheit(newGroup.name, newGroup.organisationseinheitIds) + .createOrganisationseinheit( + organisationseinheit.name, + organisationseinheit.organisationseinheitIds, + ) .subscribe(); tick(); expect(setOrganisationseinheitItemsSpy).toHaveBeenCalledWith([ ...sortedOrganisationseinheitItems, - newGroup, + organisationseinheit, ]); })); }); diff --git a/alfa-client/libs/admin-settings/src/lib/user/user.service.ts b/alfa-client/libs/admin-settings/src/lib/user/user.service.ts index 358d8b8ed11e8b5086b33cee9a79279956eaaaad..bed9ae6491b4d9a0ee0c74cb72e60c933bcb0442 100644 --- a/alfa-client/libs/admin-settings/src/lib/user/user.service.ts +++ b/alfa-client/libs/admin-settings/src/lib/user/user.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { Organisationseinheit, OrganisationseinheitState } from './user.model'; import { BehaviorSubject, first, map, Observable, startWith, tap } from 'rxjs'; -import { UserRepository } from './user-repository.service'; +import { UserRepository } from './user.repository.service'; @Injectable({ providedIn: 'root', diff --git a/alfa-client/libs/admin-settings/src/lib/user/user.util.spec.ts b/alfa-client/libs/admin-settings/src/lib/user/user.util.spec.ts index a6b90c8b256244acf61a19d37bd6b7f68fc8d525..ed900a255e048d6b6e7c69a26ce7a4a4dcd1773e 100644 --- a/alfa-client/libs/admin-settings/src/lib/user/user.util.spec.ts +++ b/alfa-client/libs/admin-settings/src/lib/user/user.util.spec.ts @@ -1,10 +1,10 @@ -import { createKeycloakAdminError } from '../../../test/keycloak/keycloak'; +import { createOrganisationseinheitError } from '../../../test/keycloak/keycloak'; import { OrganisationseinheitError, OrganisationseinheitErrorType } from './user.model'; import { getOrganisationseinheitErrorMessage, KEYCLOAK_ERROR_MESSAGES } from './user.util'; describe('get organisationseinheit error message', () => { it('should map known error message', () => { - const nameConflictError: OrganisationseinheitError = createKeycloakAdminError( + const nameConflictError: OrganisationseinheitError = createOrganisationseinheitError( OrganisationseinheitErrorType.NAME_CONFLICT, ); const expectedMessage: string = KEYCLOAK_ERROR_MESSAGES[nameConflictError.errorType]; @@ -14,7 +14,7 @@ describe('get organisationseinheit error message', () => { }); it('should map unknown error message to empty string', () => { - const nameConflictError: OrganisationseinheitError = createKeycloakAdminError(null); + const nameConflictError: OrganisationseinheitError = createOrganisationseinheitError(null); const message: string = getOrganisationseinheitErrorMessage(nameConflictError); expect(message).toEqual(''); diff --git a/alfa-client/libs/admin-settings/test/keycloak/keycloak.ts b/alfa-client/libs/admin-settings/test/keycloak/keycloak.ts index 161357f92b2bea76b2ba1b909a18cf85c9ebfeb6..6668ac960823f7ae965dfefed7d37a883eb9116f 100644 --- a/alfa-client/libs/admin-settings/test/keycloak/keycloak.ts +++ b/alfa-client/libs/admin-settings/test/keycloak/keycloak.ts @@ -38,7 +38,7 @@ export function createOrganisationseinheitState( }; } -export function createKeycloakAdminError( +export function createOrganisationseinheitError( errorType: OrganisationseinheitErrorType = OrganisationseinheitErrorType.NAME_MISSING, ): OrganisationseinheitError { return {