mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
78849: Fix unit test
This commit is contained in:
@@ -1,16 +1,16 @@
|
|||||||
import { RequestService } from './request.service';
|
import { RequestService } from './request.service';
|
||||||
import { EpersonRegistrationService } from './eperson-registration.service';
|
import { EpersonRegistrationService } from './eperson-registration.service';
|
||||||
import { RestResponse } from '../cache/response.models';
|
import { RestResponse } from '../cache/response.models';
|
||||||
import { RequestEntry, RequestEntryState } from './request.reducer';
|
import { RequestEntry } from './request.reducer';
|
||||||
import { cold } from 'jasmine-marbles';
|
import { cold } from 'jasmine-marbles';
|
||||||
import { PostRequest } from './request.models';
|
import { PostRequest } from './request.models';
|
||||||
import { Registration } from '../shared/registration.model';
|
import { Registration } from '../shared/registration.model';
|
||||||
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub';
|
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub';
|
||||||
import { createPendingRemoteDataObject, createSuccessfulRemoteDataObject } from '../../shared/remote-data.utils';
|
import { createSuccessfulRemoteDataObject } from '../../shared/remote-data.utils';
|
||||||
import { of as observableOf } from 'rxjs/internal/observable/of';
|
import { of as observableOf } from 'rxjs/internal/observable/of';
|
||||||
import { TestScheduler } from 'rxjs/testing';
|
import { TestScheduler } from 'rxjs/testing';
|
||||||
|
|
||||||
fdescribe('EpersonRegistrationService', () => {
|
describe('EpersonRegistrationService', () => {
|
||||||
let testScheduler;
|
let testScheduler;
|
||||||
|
|
||||||
let service: EpersonRegistrationService;
|
let service: EpersonRegistrationService;
|
||||||
@@ -96,51 +96,26 @@ fdescribe('EpersonRegistrationService', () => {
|
|||||||
user: registrationWithUser.user
|
user: registrationWithUser.user
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the original registration if it was already cached', () => {
|
it('should use cached responses and /registrations/search/findByToken?', () => {
|
||||||
testScheduler.run(({ cold, expectObservable }) => {
|
testScheduler.run(({ cold, expectObservable }) => {
|
||||||
rdbService.buildSingle.and.returnValue(cold('a-b-c', {
|
rdbService.buildSingle.and.returnValue(cold('a', { a: rd }));
|
||||||
a: createSuccessfulRemoteDataObject(registrationWithUser),
|
|
||||||
b: createPendingRemoteDataObject(),
|
|
||||||
c: createSuccessfulRemoteDataObject(new Registration())
|
|
||||||
}));
|
|
||||||
|
|
||||||
expectObservable(
|
service.searchByToken('test-token');
|
||||||
service.searchByToken('test-token')
|
|
||||||
).toBe('(a|)', {
|
expect(requestService.send).toHaveBeenCalledWith(
|
||||||
a: Object.assign(new Registration(), {
|
jasmine.objectContaining({
|
||||||
email: registrationWithUser.email,
|
uuid: 'request-id', method: 'GET',
|
||||||
token: 'test-token',
|
href: 'rest-url/registrations/search/findByToken?token=test-token',
|
||||||
user: registrationWithUser.user
|
}), true
|
||||||
})
|
);
|
||||||
|
expectObservable(rdbService.buildSingle.calls.argsFor(0)[0]).toBe('(a|)', {
|
||||||
|
a: 'rest-url/registrations/search/findByToken?token=test-token'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should re-request the registration if it was already cached but stale', () => {
|
|
||||||
const rdCachedStale = createSuccessfulRemoteDataObject(new Registration());
|
|
||||||
rdCachedStale.state = RequestEntryState.SuccessStale;
|
|
||||||
|
|
||||||
testScheduler.run(({ cold, expectObservable }) => {
|
|
||||||
rdbService.buildSingle.and.returnValue(cold('a-b-c', {
|
|
||||||
a: rdCachedStale,
|
|
||||||
b: createPendingRemoteDataObject(),
|
|
||||||
c: createSuccessfulRemoteDataObject(registrationWithUser),
|
|
||||||
}));
|
|
||||||
|
|
||||||
expectObservable(
|
|
||||||
service.searchByToken('test-token')
|
|
||||||
).toBe('----(c|)', {
|
|
||||||
c: Object.assign(new Registration(), {
|
|
||||||
email: registrationWithUser.email,
|
|
||||||
token: 'test-token',
|
|
||||||
user: registrationWithUser.user
|
|
||||||
})
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user