mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Merge pull request #1137 from atmire/w2p-78849_Issue-1113_Fix-forgot-password-page
Fix forgot password page
This commit is contained in:
@@ -8,8 +8,11 @@ import { Registration } from '../shared/registration.model';
|
||||
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub';
|
||||
import { createSuccessfulRemoteDataObject } from '../../shared/remote-data.utils';
|
||||
import { of as observableOf } from 'rxjs/internal/observable/of';
|
||||
import { TestScheduler } from 'rxjs/testing';
|
||||
|
||||
describe('EpersonRegistrationService', () => {
|
||||
let testScheduler;
|
||||
|
||||
let service: EpersonRegistrationService;
|
||||
let requestService: RequestService;
|
||||
|
||||
@@ -29,6 +32,12 @@ describe('EpersonRegistrationService', () => {
|
||||
rd = createSuccessfulRemoteDataObject(registrationWithUser);
|
||||
halService = new HALEndpointServiceStub('rest-url');
|
||||
|
||||
testScheduler = new TestScheduler((actual, expected) => {
|
||||
// asserting the two objects are equal
|
||||
// e.g. using chai.
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
requestService = jasmine.createSpyObj('requestService', {
|
||||
generateRequestId: 'request-id',
|
||||
send: {},
|
||||
@@ -36,7 +45,8 @@ describe('EpersonRegistrationService', () => {
|
||||
{ a: Object.assign(new RequestEntry(), { response: new RestResponse(true, 200, 'Success') }) })
|
||||
});
|
||||
rdbService = jasmine.createSpyObj('rdbService', {
|
||||
buildFromRequestUUID: observableOf(rd)
|
||||
buildSingle: observableOf(rd),
|
||||
buildFromRequestUUID: observableOf(rd),
|
||||
});
|
||||
service = new EpersonRegistrationService(
|
||||
requestService,
|
||||
@@ -86,8 +96,28 @@ describe('EpersonRegistrationService', () => {
|
||||
user: registrationWithUser.user
|
||||
})
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
// tslint:disable:no-shadowed-variable
|
||||
it('should use cached responses and /registrations/search/findByToken?', () => {
|
||||
testScheduler.run(({ cold, expectObservable }) => {
|
||||
rdbService.buildSingle.and.returnValue(cold('a', { a: rd }));
|
||||
|
||||
service.searchByToken('test-token');
|
||||
|
||||
expect(requestService.send).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
uuid: 'request-id', method: 'GET',
|
||||
href: 'rest-url/registrations/search/findByToken?token=test-token',
|
||||
}), true
|
||||
);
|
||||
expectObservable(rdbService.buildSingle.calls.argsFor(0)[0]).toBe('(a|)', {
|
||||
a: 'rest-url/registrations/search/findByToken?token=test-token'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
/**/
|
||||
|
@@ -3,7 +3,7 @@ import { RequestService } from './request.service';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { GetRequest, PostRequest } from './request.models';
|
||||
import { Observable } from 'rxjs';
|
||||
import { filter, find, map, take } from 'rxjs/operators';
|
||||
import { filter, find, map, skipWhile } from 'rxjs/operators';
|
||||
import { hasValue, isNotEmpty } from '../../shared/empty.util';
|
||||
import { Registration } from '../shared/registration.model';
|
||||
import { getFirstCompletedRemoteData, getFirstSucceededRemoteData } from '../shared/operators';
|
||||
@@ -60,9 +60,9 @@ export class EpersonRegistrationService {
|
||||
|
||||
const requestId = this.requestService.generateRequestId();
|
||||
|
||||
const hrefObs = this.getRegistrationEndpoint();
|
||||
const href$ = this.getRegistrationEndpoint();
|
||||
|
||||
hrefObs.pipe(
|
||||
href$.pipe(
|
||||
find((href: string) => hasValue(href)),
|
||||
map((href: string) => {
|
||||
const request = new PostRequest(requestId, href, registration);
|
||||
@@ -82,27 +82,28 @@ export class EpersonRegistrationService {
|
||||
searchByToken(token: string): Observable<Registration> {
|
||||
const requestId = this.requestService.generateRequestId();
|
||||
|
||||
const hrefObs = this.getTokenSearchEndpoint(token);
|
||||
|
||||
hrefObs.pipe(
|
||||
const href$ = this.getTokenSearchEndpoint(token).pipe(
|
||||
find((href: string) => hasValue(href)),
|
||||
map((href: string) => {
|
||||
const request = new GetRequest(requestId, href);
|
||||
Object.assign(request, {
|
||||
getResponseParser(): GenericConstructor<ResponseParsingService> {
|
||||
return RegistrationResponseParsingService;
|
||||
}
|
||||
});
|
||||
this.requestService.send(request, true);
|
||||
})
|
||||
).subscribe();
|
||||
);
|
||||
|
||||
return this.rdbService.buildFromRequestUUID<Registration>(requestId).pipe(
|
||||
href$.subscribe((href: string) => {
|
||||
const request = new GetRequest(requestId, href);
|
||||
Object.assign(request, {
|
||||
getResponseParser(): GenericConstructor<ResponseParsingService> {
|
||||
return RegistrationResponseParsingService;
|
||||
}
|
||||
});
|
||||
this.requestService.send(request, true);
|
||||
});
|
||||
|
||||
return this.rdbService.buildSingle<Registration>(href$).pipe(
|
||||
skipWhile((rd: RemoteData<Registration>) => rd.isStale),
|
||||
getFirstSucceededRemoteData(),
|
||||
map((restResponse: RemoteData<Registration>) => {
|
||||
return Object.assign(new Registration(), {email: restResponse.payload.email, token: token, user: restResponse.payload.user});
|
||||
return Object.assign(new Registration(), {
|
||||
email: restResponse.payload.email, token: token, user: restResponse.payload.user
|
||||
});
|
||||
}),
|
||||
take(1),
|
||||
);
|
||||
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ import { Store } from '@ngrx/store';
|
||||
import { CoreState } from '../../core/core.reducers';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { EPerson } from '../../core/eperson/models/eperson.model';
|
||||
import { getFirstCompletedRemoteData } from '../../core/shared/operators';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-forgot-password-form',
|
||||
@@ -70,7 +71,9 @@ export class ForgotPasswordFormComponent {
|
||||
*/
|
||||
submit() {
|
||||
if (!this.isInValid) {
|
||||
this.ePersonDataService.patchPasswordWithToken(this.user, this.token, this.password).subscribe((response: RemoteData<EPerson>) => {
|
||||
this.ePersonDataService.patchPasswordWithToken(this.user, this.token, this.password).pipe(
|
||||
getFirstCompletedRemoteData()
|
||||
).subscribe((response: RemoteData<EPerson>) => {
|
||||
if (response.hasSucceeded) {
|
||||
this.notificationsService.success(
|
||||
this.translateService.instant(this.NOTIFICATIONS_PREFIX + '.success.title'),
|
||||
|
Reference in New Issue
Block a user