mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
fix: resolve issue with unit tests
This commit is contained in:
@@ -26,11 +26,13 @@ import { HALEndpointServiceStub } from '../../../shared/testing/hal-endpoint-ser
|
|||||||
import { ObjectCacheServiceStub } from '../../../shared/testing/object-cache-service.stub';
|
import { ObjectCacheServiceStub } from '../../../shared/testing/object-cache-service.stub';
|
||||||
import { createPaginatedList } from '../../../shared/testing/utils.test';
|
import { createPaginatedList } from '../../../shared/testing/utils.test';
|
||||||
import { followLink } from '../../../shared/utils/follow-link-config.model';
|
import { followLink } from '../../../shared/utils/follow-link-config.model';
|
||||||
|
import { LinkDefinition } from '../../cache/builders/build-decorators';
|
||||||
import { RemoteDataBuildService } from '../../cache/builders/remote-data-build.service';
|
import { RemoteDataBuildService } from '../../cache/builders/remote-data-build.service';
|
||||||
import { ObjectCacheEntry } from '../../cache/object-cache.reducer';
|
import { ObjectCacheEntry } from '../../cache/object-cache.reducer';
|
||||||
import { ObjectCacheService } from '../../cache/object-cache.service';
|
import { ObjectCacheService } from '../../cache/object-cache.service';
|
||||||
import { HALEndpointService } from '../../shared/hal-endpoint.service';
|
import { HALEndpointService } from '../../shared/hal-endpoint.service';
|
||||||
import { HALLink } from '../../shared/hal-link.model';
|
import { HALLink } from '../../shared/hal-link.model';
|
||||||
|
import { HALResource } from '../../shared/hal-resource.model';
|
||||||
import { FindListOptions } from '../find-list-options.model';
|
import { FindListOptions } from '../find-list-options.model';
|
||||||
import { RemoteData } from '../remote-data';
|
import { RemoteData } from '../remote-data';
|
||||||
import { RequestService } from '../request.service';
|
import { RequestService } from '../request.service';
|
||||||
@@ -417,6 +419,11 @@ describe('BaseDataService', () => {
|
|||||||
c: remoteDataMocks.ResponsePending,
|
c: remoteDataMocks.ResponsePending,
|
||||||
d: remoteDataMocks.Success,
|
d: remoteDataMocks.Success,
|
||||||
}));
|
}));
|
||||||
|
spyOn(service, 'getLinkDefinition').and.callFake((source, linkName) => {
|
||||||
|
return {
|
||||||
|
propertyName: linkName,
|
||||||
|
} as any as LinkDefinition<HALResource>;
|
||||||
|
});
|
||||||
const expected = '--b-c-d';
|
const expected = '--b-c-d';
|
||||||
const values = {
|
const values = {
|
||||||
b: remoteDataMocks.RequestPending,
|
b: remoteDataMocks.RequestPending,
|
||||||
@@ -625,16 +632,19 @@ describe('BaseDataService', () => {
|
|||||||
c: remoteDataPageMocks.ResponsePending,
|
c: remoteDataPageMocks.ResponsePending,
|
||||||
d: remoteDataPageMocks.Success,
|
d: remoteDataPageMocks.Success,
|
||||||
}));
|
}));
|
||||||
|
spyOn(service, 'getLinkDefinition').and.callFake((source, linkName) => {
|
||||||
|
return {
|
||||||
|
propertyName: linkName,
|
||||||
|
} as any as LinkDefinition<HALResource>;
|
||||||
|
});
|
||||||
const expected = '--b-c-d';
|
const expected = '--b-c-d';
|
||||||
const values = {
|
const values = {
|
||||||
b: remoteDataPageMocks.RequestPending,
|
b: remoteDataPageMocks.RequestPending,
|
||||||
c: remoteDataPageMocks.ResponsePending,
|
c: remoteDataPageMocks.ResponsePending,
|
||||||
d: remoteDataPageMocks.Success,
|
d: remoteDataPageMocks.Success,
|
||||||
};
|
};
|
||||||
|
|
||||||
expectObservable(service.findListByHref(selfLink, findListOptions, false, false, ...linksToFollow)).toBe(expected, values);
|
expectObservable(service.findListByHref(selfLink, findListOptions, false, false, ...linksToFollow)).toBe(expected, values);
|
||||||
flush();
|
flush();
|
||||||
expect(objectCache.addDependency).toHaveBeenCalledTimes(3);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -28,14 +28,19 @@ import {
|
|||||||
isNotEmptyOperator,
|
isNotEmptyOperator,
|
||||||
} from '../../../shared/empty.util';
|
} from '../../../shared/empty.util';
|
||||||
import { FollowLinkConfig } from '../../../shared/utils/follow-link-config.model';
|
import { FollowLinkConfig } from '../../../shared/utils/follow-link-config.model';
|
||||||
import { getLinkDefinition } from '../../cache/builders/build-decorators';
|
import {
|
||||||
|
getLinkDefinition,
|
||||||
|
LinkDefinition,
|
||||||
|
} from '../../cache/builders/build-decorators';
|
||||||
import { RemoteDataBuildService } from '../../cache/builders/remote-data-build.service';
|
import { RemoteDataBuildService } from '../../cache/builders/remote-data-build.service';
|
||||||
import { CacheableObject } from '../../cache/cacheable-object.model';
|
import { CacheableObject } from '../../cache/cacheable-object.model';
|
||||||
import { RequestParam } from '../../cache/models/request-param.model';
|
import { RequestParam } from '../../cache/models/request-param.model';
|
||||||
import { ObjectCacheEntry } from '../../cache/object-cache.reducer';
|
import { ObjectCacheEntry } from '../../cache/object-cache.reducer';
|
||||||
import { ObjectCacheService } from '../../cache/object-cache.service';
|
import { ObjectCacheService } from '../../cache/object-cache.service';
|
||||||
|
import { GenericConstructor } from '../../shared/generic-constructor';
|
||||||
import { HALEndpointService } from '../../shared/hal-endpoint.service';
|
import { HALEndpointService } from '../../shared/hal-endpoint.service';
|
||||||
import { HALLink } from '../../shared/hal-link.model';
|
import { HALLink } from '../../shared/hal-link.model';
|
||||||
|
import { HALResource } from '../../shared/hal-resource.model';
|
||||||
import { getFirstCompletedRemoteData } from '../../shared/operators';
|
import { getFirstCompletedRemoteData } from '../../shared/operators';
|
||||||
import { URLCombiner } from '../../url-combiner/url-combiner';
|
import { URLCombiner } from '../../url-combiner/url-combiner';
|
||||||
import { FindListOptions } from '../find-list-options.model';
|
import { FindListOptions } from '../find-list-options.model';
|
||||||
@@ -303,7 +308,7 @@ export class BaseDataService<T extends CacheableObject> implements HALDataServic
|
|||||||
if (hasValue(remoteDataObject?.payload?._links)) {
|
if (hasValue(remoteDataObject?.payload?._links)) {
|
||||||
for (const followLinkName of Object.keys(remoteDataObject.payload._links)) {
|
for (const followLinkName of Object.keys(remoteDataObject.payload._links)) {
|
||||||
// only add the followLinks if they are embedded, and we get only links from the linkMap with the correct name
|
// only add the followLinks if they are embedded, and we get only links from the linkMap with the correct name
|
||||||
const linkDefinition = getLinkDefinition((remoteDataObject.payload as any).constructor, followLinkName);
|
const linkDefinition = this.getLinkDefinition((remoteDataObject.payload as any).constructor, followLinkName);
|
||||||
if (linkDefinition?.propertyName && hasValue(remoteDataObject.payload[linkDefinition.propertyName]) && followLinkName !== 'self') {
|
if (linkDefinition?.propertyName && hasValue(remoteDataObject.payload[linkDefinition.propertyName]) && followLinkName !== 'self') {
|
||||||
// followLink can be either an individual HALLink or a HALLink[]
|
// followLink can be either an individual HALLink or a HALLink[]
|
||||||
const followLinksList: HALLink[] = [].concat(remoteDataObject.payload._links[followLinkName]);
|
const followLinksList: HALLink[] = [].concat(remoteDataObject.payload._links[followLinkName]);
|
||||||
@@ -359,8 +364,8 @@ export class BaseDataService<T extends CacheableObject> implements HALDataServic
|
|||||||
if (hasValue(object?._links)) {
|
if (hasValue(object?._links)) {
|
||||||
for (const followLinkName of Object.keys(object._links)) {
|
for (const followLinkName of Object.keys(object._links)) {
|
||||||
// only add the followLinks if they are embedded, and we get only links from the linkMap with the correct name
|
// only add the followLinks if they are embedded, and we get only links from the linkMap with the correct name
|
||||||
const linkDefinition = getLinkDefinition((remoteDataObject.payload as any).constructor, followLinkName);
|
const linkDefinition = this.getLinkDefinition((remoteDataObject.payload as any).constructor, followLinkName);
|
||||||
if (linkDefinition?.propertyName && hasValue(remoteDataObject.payload[linkDefinition.propertyName]) && followLinkName !== 'self') {
|
if (linkDefinition?.propertyName && followLinkName !== 'self' && hasValue(object[linkDefinition.propertyName])) {
|
||||||
// followLink can be either an individual HALLink or a HALLink[]
|
// followLink can be either an individual HALLink or a HALLink[]
|
||||||
const followLinksList: HALLink[] = [].concat(object._links[followLinkName]);
|
const followLinksList: HALLink[] = [].concat(object._links[followLinkName]);
|
||||||
for (const individualFollowLink of followLinksList) {
|
for (const individualFollowLink of followLinksList) {
|
||||||
@@ -515,4 +520,9 @@ export class BaseDataService<T extends CacheableObject> implements HALDataServic
|
|||||||
|
|
||||||
return done$;
|
return done$;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLinkDefinition<D extends HALResource>(source: GenericConstructor<D>, linkName: keyof D['_links']): LinkDefinition<D> {
|
||||||
|
return getLinkDefinition(source, linkName);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user