From e4ce91fa73fa2d5bb90be43198d2b6baef8e2a53 Mon Sep 17 00:00:00 2001 From: Marie Verdonck Date: Wed, 28 Dec 2022 11:57:48 +0100 Subject: [PATCH 1/2] 97298: #3281 Self-register - type request query param --- .../forgot-email.component.html | 4 ++-- .../register-email-form.component.ts | 12 +++++++----- .../register-email/register-email.component.html | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/app/forgot-password/forgot-password-email/forgot-email.component.html b/src/app/forgot-password/forgot-password-email/forgot-email.component.html index 263f142c2e..8be86f17ae 100644 --- a/src/app/forgot-password/forgot-password-email/forgot-email.component.html +++ b/src/app/forgot-password/forgot-password-email/forgot-email.component.html @@ -1,3 +1,3 @@ - \ No newline at end of file + [MESSAGE_PREFIX]="'forgot-email.form'" [typeRequest]="'forgot'"> + diff --git a/src/app/register-email-form/register-email-form.component.ts b/src/app/register-email-form/register-email-form.component.ts index 9e7b783544..f2a338537d 100644 --- a/src/app/register-email-form/register-email-form.component.ts +++ b/src/app/register-email-form/register-email-form.component.ts @@ -29,6 +29,12 @@ export class RegisterEmailFormComponent implements OnInit { @Input() MESSAGE_PREFIX: string; + /** + * Type of register request to be done, register new email or forgot password (same endpoint) + */ + @Input() + typeRequest: string = null; + validMailDomains: string[]; constructor( @@ -64,12 +70,8 @@ export class RegisterEmailFormComponent implements OnInit { * Register an email address */ register() { - const typeMap = new Map([ - ['register-page.registration', 'register'], - ['forgot-email.form', 'forgot'] - ]); if (!this.form.invalid) { - this.epersonRegistrationService.registerEmail(this.email.value, typeMap.get(this.MESSAGE_PREFIX)).subscribe((response: RemoteData) => { + this.epersonRegistrationService.registerEmail(this.email.value, this.typeRequest).subscribe((response: RemoteData) => { if (response.hasSucceeded) { this.notificationService.success(this.translateService.get(`${this.MESSAGE_PREFIX}.success.head`), this.translateService.get(`${this.MESSAGE_PREFIX}.success.content`, {email: this.email.value})); diff --git a/src/app/register-page/register-email/register-email.component.html b/src/app/register-page/register-email/register-email.component.html index a60dc4c31e..80b6885272 100644 --- a/src/app/register-page/register-email/register-email.component.html +++ b/src/app/register-page/register-email/register-email.component.html @@ -1,3 +1,3 @@ + [MESSAGE_PREFIX]="'register-page.registration'" [typeRequest]="'register'"> From 31b17731f25403f79b04b2d2966f340efbda8198 Mon Sep 17 00:00:00 2001 From: Marie Verdonck Date: Wed, 28 Dec 2022 12:28:27 +0100 Subject: [PATCH 2/2] 97298: #3281 Self-register - test fixes --- .../data/eperson-registration.service.spec.ts | 4 +++- .../core/data/eperson-registration.service.ts | 6 +++++- .../register-email-form.component.spec.ts | 19 ++++++++++++++++--- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/app/core/data/eperson-registration.service.spec.ts b/src/app/core/data/eperson-registration.service.spec.ts index 2407249615..32688d050b 100644 --- a/src/app/core/data/eperson-registration.service.spec.ts +++ b/src/app/core/data/eperson-registration.service.spec.ts @@ -9,6 +9,7 @@ import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-servic import { createSuccessfulRemoteDataObject } from '../../shared/remote-data.utils'; import { of as observableOf } from 'rxjs'; import { TestScheduler } from 'rxjs/testing'; +import { HttpOptions } from '../dspace-rest/dspace-rest.service'; describe('EpersonRegistrationService', () => { let testScheduler; @@ -79,8 +80,9 @@ describe('EpersonRegistrationService', () => { it('should send an email registration', () => { const expected = service.registerEmail('test@mail.org'); + const options: HttpOptions = Object.create({}); - expect(requestService.send).toHaveBeenCalledWith(new PostRequest('request-id', 'rest-url/registrations', registration)); + expect(requestService.send).toHaveBeenCalledWith(new PostRequest('request-id', 'rest-url/registrations', registration, options)); expect(expected).toBeObservable(cold('(a|)', { a: rd })); }); }); diff --git a/src/app/core/data/eperson-registration.service.ts b/src/app/core/data/eperson-registration.service.ts index 24c2263fd1..6a8d9c94f7 100644 --- a/src/app/core/data/eperson-registration.service.ts +++ b/src/app/core/data/eperson-registration.service.ts @@ -13,6 +13,7 @@ import { RegistrationResponseParsingService } from './registration-response-pars import { RemoteData } from './remote-data'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import {HttpParams} from '@angular/common/http'; +import { HttpOptions } from '../dspace-rest/dspace-rest.service'; @Injectable( { @@ -63,7 +64,10 @@ export class EpersonRegistrationService { const href$ = this.getRegistrationEndpoint(); - const options = type ? {params: new HttpParams({fromString:'type=' + type})} : {}; + const options: HttpOptions = Object.create({}); + if (hasValue(type)) { + options.params = type ? new HttpParams({ fromString: 'type=' + type }) : new HttpParams(); + } href$.pipe( find((href: string) => hasValue(href)), diff --git a/src/app/register-email-form/register-email-form.component.spec.ts b/src/app/register-email-form/register-email-form.component.spec.ts index a415ef4808..585e69405a 100644 --- a/src/app/register-email-form/register-email-form.component.spec.ts +++ b/src/app/register-email-form/register-email-form.component.spec.ts @@ -14,8 +14,10 @@ import { RouterStub } from '../shared/testing/router.stub'; import { NotificationsServiceStub } from '../shared/testing/notifications-service.stub'; import { RegisterEmailFormComponent } from './register-email-form.component'; import { createSuccessfulRemoteDataObject$ } from '../shared/remote-data.utils'; +import { ConfigurationDataService } from '../core/data/configuration-data.service'; +import { ConfigurationProperty } from '../core/shared/configuration-property.model'; -describe('RegisterEmailComponent', () => { +describe('RegisterEmailFormComponent', () => { let comp: RegisterEmailFormComponent; let fixture: ComponentFixture; @@ -23,6 +25,7 @@ describe('RegisterEmailComponent', () => { let router; let epersonRegistrationService: EpersonRegistrationService; let notificationsService; + let configurationDataService: ConfigurationDataService; beforeEach(waitForAsync(() => { @@ -33,6 +36,15 @@ describe('RegisterEmailComponent', () => { registerEmail: createSuccessfulRemoteDataObject$({}) }); + configurationDataService = jasmine.createSpyObj('configurationDataService', { + findByPropertyName: createSuccessfulRemoteDataObject$(Object.assign(new ConfigurationProperty(), { + name: 'authentication-password.domain.valid', + values: [ + 'example.com, @gmail.com' + ] + })) + }); + TestBed.configureTestingModule({ imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), ReactiveFormsModule], declarations: [RegisterEmailFormComponent], @@ -41,6 +53,7 @@ describe('RegisterEmailComponent', () => { {provide: EpersonRegistrationService, useValue: epersonRegistrationService}, {provide: FormBuilder, useValue: new FormBuilder()}, {provide: NotificationsService, useValue: notificationsService}, + {provide: ConfigurationDataService, useValue: configurationDataService}, ], schemas: [CUSTOM_ELEMENTS_SCHEMA] }).compileComponents(); @@ -75,7 +88,7 @@ describe('RegisterEmailComponent', () => { comp.form.patchValue({email: 'valid@email.org'}); comp.register(); - expect(epersonRegistrationService.registerEmail).toHaveBeenCalledWith('valid@email.org'); + expect(epersonRegistrationService.registerEmail).toHaveBeenCalledWith('valid@email.org', null); expect(notificationsService.success).toHaveBeenCalled(); expect(router.navigate).toHaveBeenCalledWith(['/home']); }); @@ -85,7 +98,7 @@ describe('RegisterEmailComponent', () => { comp.form.patchValue({email: 'valid@email.org'}); comp.register(); - expect(epersonRegistrationService.registerEmail).toHaveBeenCalledWith('valid@email.org'); + expect(epersonRegistrationService.registerEmail).toHaveBeenCalledWith('valid@email.org', null); expect(notificationsService.error).toHaveBeenCalled(); expect(router.navigate).not.toHaveBeenCalled(); });