mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
94072: test cases
This commit is contained in:
@@ -663,5 +663,104 @@ describe('RemoteDataBuildService', () => {
|
||||
expect(service.buildFromHref(cold('a', { a: 'rest/api/endpoint' }))).toBeObservable(cold(''));
|
||||
});
|
||||
});
|
||||
|
||||
describe('when one of getRequestFromRequestHref or getRequestFromRequestUUID emits nothing', () => {
|
||||
let requestEntry: RequestEntry;
|
||||
|
||||
beforeEach(() => {
|
||||
requestEntry = Object.assign(new RequestEntry(), {
|
||||
state: RequestEntryState.Success,
|
||||
request: {},
|
||||
});
|
||||
(requestService.getByHref as jasmine.Spy).and.returnValue(cold('a', { a: undefined }));
|
||||
(requestService.getByUUID as jasmine.Spy).and.returnValue(cold('a', { a: requestEntry }));
|
||||
spyOn((service as any), 'buildPayload').and.returnValue(cold('a', { a: {} }));
|
||||
});
|
||||
|
||||
it('should create remote-data with the existing request-entry', () => {
|
||||
expect(service.buildFromHref(cold('a', { a: 'rest/api/endpoint' }))).toBeObservable(cold('a', {
|
||||
a: new RemoteData(undefined, undefined, undefined, RequestEntryState.Success, undefined, {}, undefined),
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('when one of getRequestFromRequestHref or getRequestFromRequestUUID is stale', () => {
|
||||
let requestEntry1: RequestEntry;
|
||||
let requestEntry2: RequestEntry;
|
||||
|
||||
beforeEach(() => {
|
||||
requestEntry1 = Object.assign(new RequestEntry(), {
|
||||
state: RequestEntryState.Success,
|
||||
request: {},
|
||||
});
|
||||
requestEntry2 = Object.assign(new RequestEntry(), {
|
||||
state: RequestEntryState.SuccessStale,
|
||||
request: {},
|
||||
});
|
||||
(requestService.getByHref as jasmine.Spy).and.returnValue(cold('a', { a: requestEntry1 }));
|
||||
(requestService.getByUUID as jasmine.Spy).and.returnValue(cold('a', { a: requestEntry2 }));
|
||||
spyOn((service as any), 'buildPayload').and.returnValue(cold('a', { a: {} }));
|
||||
});
|
||||
|
||||
it('should create remote-data with the non-stale request-entry', () => {
|
||||
expect(service.buildFromHref(cold('a', { a: 'rest/api/endpoint' }))).toBeObservable(cold('a', {
|
||||
a: new RemoteData(undefined, undefined, undefined, RequestEntryState.Success, undefined, {}, undefined),
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('when both getRequestFromRequestHref and getRequestFromRequestUUID are stale', () => {
|
||||
let requestEntry1: RequestEntry;
|
||||
let requestEntry2: RequestEntry;
|
||||
|
||||
beforeEach(() => {
|
||||
requestEntry1 = Object.assign(new RequestEntry(), {
|
||||
state: RequestEntryState.SuccessStale,
|
||||
request: {},
|
||||
lastUpdated: 20,
|
||||
});
|
||||
requestEntry2 = Object.assign(new RequestEntry(), {
|
||||
state: RequestEntryState.SuccessStale,
|
||||
request: {},
|
||||
lastUpdated: 10,
|
||||
});
|
||||
(requestService.getByHref as jasmine.Spy).and.returnValue(cold('a', { a: requestEntry1 }));
|
||||
(requestService.getByUUID as jasmine.Spy).and.returnValue(cold('a', { a: requestEntry2 }));
|
||||
spyOn((service as any), 'buildPayload').and.returnValue(cold('a', { a: {} }));
|
||||
});
|
||||
|
||||
it('should create remote-data with the most up-to-date request-entry', () => {
|
||||
expect(service.buildFromHref(cold('a', { a: 'rest/api/endpoint' }))).toBeObservable(cold('a', {
|
||||
a: new RemoteData(undefined, undefined, 20, RequestEntryState.SuccessStale, undefined, {}, undefined),
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('when both getRequestFromRequestHref and getRequestFromRequestUUID are not stale', () => {
|
||||
let requestEntry1: RequestEntry;
|
||||
let requestEntry2: RequestEntry;
|
||||
|
||||
beforeEach(() => {
|
||||
requestEntry1 = Object.assign(new RequestEntry(), {
|
||||
state: RequestEntryState.Success,
|
||||
request: {},
|
||||
lastUpdated: 25,
|
||||
});
|
||||
requestEntry2 = Object.assign(new RequestEntry(), {
|
||||
state: RequestEntryState.Success,
|
||||
request: {},
|
||||
lastUpdated: 5,
|
||||
});
|
||||
(requestService.getByHref as jasmine.Spy).and.returnValue(cold('a', { a: requestEntry1 }));
|
||||
(requestService.getByUUID as jasmine.Spy).and.returnValue(cold('a', { a: requestEntry2 }));
|
||||
spyOn((service as any), 'buildPayload').and.returnValue(cold('a', { a: {} }));
|
||||
});
|
||||
|
||||
it('should create remote-data with the most up-to-date request-entry', () => {
|
||||
expect(service.buildFromHref(cold('a', { a: 'rest/api/endpoint' }))).toBeObservable(cold('a', {
|
||||
a: new RemoteData(undefined, undefined, 25, RequestEntryState.Success, undefined, {}, undefined),
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user