mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 10:34:15 +00:00
fixed tests after changes to request caching
This commit is contained in:
@@ -47,7 +47,7 @@ describe('ServerSyncBufferEffects', () => {
|
|||||||
{ provide: RequestService, useValue: getMockRequestService() },
|
{ provide: RequestService, useValue: getMockRequestService() },
|
||||||
{
|
{
|
||||||
provide: ObjectCacheService, useValue: {
|
provide: ObjectCacheService, useValue: {
|
||||||
getBySelfLink: (link) => {
|
getObjectBySelfLink: (link) => {
|
||||||
const object = new DSpaceObject();
|
const object = new DSpaceObject();
|
||||||
object.self = link;
|
object.self = link;
|
||||||
return observableOf(object);
|
return observableOf(object);
|
||||||
|
@@ -67,7 +67,7 @@ describe('DataService', () => {
|
|||||||
addPatch: () => {
|
addPatch: () => {
|
||||||
/* empty */
|
/* empty */
|
||||||
},
|
},
|
||||||
getBySelfLink: () => {
|
getObjectBySelfLink: () => {
|
||||||
/* empty */
|
/* empty */
|
||||||
}
|
}
|
||||||
} as any;
|
} as any;
|
||||||
@@ -189,7 +189,7 @@ describe('DataService', () => {
|
|||||||
dso2.metadata = [{ key: 'dc.title', value: name2 }];
|
dso2.metadata = [{ key: 'dc.title', value: name2 }];
|
||||||
|
|
||||||
spyOn(service, 'findById').and.returnValues(observableOf(dso));
|
spyOn(service, 'findById').and.returnValues(observableOf(dso));
|
||||||
spyOn(objectCache, 'getBySelfLink').and.returnValues(observableOf(dso));
|
spyOn(objectCache, 'getObjectBySelfLink').and.returnValues(observableOf(dso));
|
||||||
spyOn(objectCache, 'addPatch');
|
spyOn(objectCache, 'addPatch');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -24,7 +24,7 @@ import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
|
|||||||
import { MockStore } from '../../shared/testing/mock-store';
|
import { MockStore } from '../../shared/testing/mock-store';
|
||||||
import { IndexState } from '../index/index.reducer';
|
import { IndexState } from '../index/index.reducer';
|
||||||
|
|
||||||
fdescribe('RequestService', () => {
|
describe('RequestService', () => {
|
||||||
let scheduler: TestScheduler;
|
let scheduler: TestScheduler;
|
||||||
let service: RequestService;
|
let service: RequestService;
|
||||||
let serviceAsAny: any;
|
let serviceAsAny: any;
|
||||||
@@ -42,6 +42,7 @@ fdescribe('RequestService', () => {
|
|||||||
const testHeadRequest = new HeadRequest(testUUID, testHref);
|
const testHeadRequest = new HeadRequest(testUUID, testHref);
|
||||||
const testPatchRequest = new PatchRequest(testUUID, testHref);
|
const testPatchRequest = new PatchRequest(testUUID, testHref);
|
||||||
let selectSpy;
|
let selectSpy;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
scheduler = getTestScheduler();
|
scheduler = getTestScheduler();
|
||||||
|
|
||||||
@@ -417,76 +418,65 @@ fdescribe('RequestService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('isValid', () => {
|
describe('isValid', () => {
|
||||||
describe('when the given UUID has no value', () => {
|
describe('when the given entry has no value', () => {
|
||||||
let valid;
|
let valid;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const uuid = undefined;
|
const entry = undefined;
|
||||||
valid = serviceAsAny.isValid(uuid);
|
valid = serviceAsAny.isValid(entry);
|
||||||
});
|
});
|
||||||
it('return an observable emitting false', () => {
|
it('return an observable emitting false', () => {
|
||||||
valid.subscribe((isValid) => expect(isValid).toBe(false));
|
expect(valid).toBe(false);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when the given UUID has a value, but no cached entry is found', () => {
|
describe('when the given entry has a value, but the request is not completed', () => {
|
||||||
let valid;
|
let valid;
|
||||||
|
const requestEntry = { completed: false } ;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(service, 'getByUUID').and.returnValue(observableOf(undefined));
|
spyOn(service, 'getByUUID').and.returnValue(observableOf(requestEntry));
|
||||||
const uuid = 'a45bb291-1adb-40d9-b2fc-7ad9080607be';
|
valid = serviceAsAny.isValid(requestEntry);
|
||||||
valid = serviceAsAny.isValid(uuid);
|
|
||||||
});
|
});
|
||||||
it('return an observable emitting false', () => {
|
it('return an observable emitting false', () => {
|
||||||
valid.subscribe((isValid) => expect(isValid).toBe(false));
|
expect(valid).toBe(false);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when the given UUID has a value, a cached entry is found, but it has no response', () => {
|
describe('when the given entry has a value, but the response is not successful', () => {
|
||||||
let valid;
|
let valid;
|
||||||
|
const requestEntry = { completed: true, response: { isSuccessful: false } };
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(service, 'getByUUID').and.returnValue(observableOf({ response: undefined }));
|
spyOn(service, 'getByUUID').and.returnValue(observableOf(requestEntry));
|
||||||
const uuid = '53c9b814-ad8b-4567-9bc1-d9bb6cfba6c8';
|
valid = serviceAsAny.isValid(requestEntry);
|
||||||
valid = serviceAsAny.isValid(uuid);
|
|
||||||
});
|
});
|
||||||
it('return an observable emitting false', () => {
|
it('return an observable emitting false', () => {
|
||||||
valid.subscribe((isValid) => expect(isValid).toBe(false));
|
expect(valid).toBe(false);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when the given UUID has a value, a cached entry is found, but its response was not successful', () => {
|
describe('when the given UUID has a value, its response was successful, but the response is outdated', () => {
|
||||||
let valid;
|
|
||||||
beforeEach(() => {
|
|
||||||
spyOn(service, 'getByUUID').and.returnValue(observableOf({ response: { isSuccessful: false } }));
|
|
||||||
const uuid = '694c9b32-7b2e-4788-835b-ef3fc2252e6c';
|
|
||||||
valid = serviceAsAny.isValid(uuid);
|
|
||||||
});
|
|
||||||
it('return an observable emitting false', () => {
|
|
||||||
valid.subscribe((isValid) => expect(isValid).toBe(false));
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
fdescribe('when the given UUID has a value, a cached entry is found, its response was successful, but the response is outdated', () => {
|
|
||||||
let valid;
|
let valid;
|
||||||
const now = 100000;
|
const now = 100000;
|
||||||
const timeAdded = 99899;
|
const timeAdded = 99899;
|
||||||
const msToLive = 100;
|
const msToLive = 100;
|
||||||
|
const requestEntry = {
|
||||||
beforeEach(() => {
|
completed: true,
|
||||||
spyOn(Date.prototype, 'getTime').and.returnValue(now);
|
|
||||||
spyOn(service, 'getByUUID').and.returnValue(observableOf({
|
|
||||||
response: {
|
response: {
|
||||||
isSuccessful: true,
|
isSuccessful: true,
|
||||||
timeAdded: timeAdded
|
timeAdded: timeAdded
|
||||||
},
|
},
|
||||||
request: {
|
request: {
|
||||||
responseMsToLive: msToLive
|
responseMsToLive: msToLive,
|
||||||
}
|
}
|
||||||
}));
|
};
|
||||||
const uuid = 'f9b85788-881c-4994-86b6-bae8dad024d2';
|
|
||||||
valid = serviceAsAny.isValid(uuid);
|
beforeEach(() => {
|
||||||
|
spyOn(Date.prototype, 'getTime').and.returnValue(now);
|
||||||
|
spyOn(service, 'getByUUID').and.returnValue(observableOf(requestEntry));
|
||||||
|
valid = serviceAsAny.isValid(requestEntry);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('return an observable emitting false', () => {
|
it('return an observable emitting false', () => {
|
||||||
valid.subscribe((isValid) => expect(isValid).toBe(false));
|
expect(valid).toBe(false);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -496,9 +486,8 @@ fdescribe('RequestService', () => {
|
|||||||
const timeAdded = 99999;
|
const timeAdded = 99999;
|
||||||
const msToLive = 100;
|
const msToLive = 100;
|
||||||
|
|
||||||
beforeEach(() => {
|
const requestEntry = {
|
||||||
spyOn(Date.prototype, 'getTime').and.returnValue(now);
|
completed: true,
|
||||||
spyOn(service, 'getByUUID').and.returnValue(observableOf({
|
|
||||||
response: {
|
response: {
|
||||||
isSuccessful: true,
|
isSuccessful: true,
|
||||||
timeAdded: timeAdded
|
timeAdded: timeAdded
|
||||||
@@ -506,13 +495,15 @@ fdescribe('RequestService', () => {
|
|||||||
request: {
|
request: {
|
||||||
responseMsToLive: msToLive
|
responseMsToLive: msToLive
|
||||||
}
|
}
|
||||||
}));
|
};
|
||||||
const uuid = 'f9b85788-881c-4994-86b6-bae8dad024d2';
|
beforeEach(() => {
|
||||||
valid = serviceAsAny.isValid(uuid);
|
spyOn(Date.prototype, 'getTime').and.returnValue(now);
|
||||||
|
spyOn(service, 'getByUUID').and.returnValue(observableOf(requestEntry));
|
||||||
|
valid = serviceAsAny.isValid(requestEntry);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('return an observable emitting true', () => {
|
it('return an observable emitting true', () => {
|
||||||
valid.subscribe((isValid) => expect(isValid).toBe(true));
|
expect(valid).toBe(true);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user