mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
68729: Resolve missing links to undefined
This commit is contained in:

committed by
Art Lowel

parent
be4d4ec88d
commit
6606520c2f
47
src/app/core/cache/builders/link.service.spec.ts
vendored
47
src/app/core/cache/builders/link.service.spec.ts
vendored
@@ -218,5 +218,52 @@ describe('LinkService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when a link is missing', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
testModel = Object.assign(new TestModel(), {
|
||||||
|
value: 'a test value',
|
||||||
|
_links: {
|
||||||
|
self: {
|
||||||
|
href: 'http://self.link'
|
||||||
|
},
|
||||||
|
predecessor: {
|
||||||
|
href: 'http://predecessor.link'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
spyOnFunction(decorators, 'getDataServiceFor').and.returnValue(TestDataService);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('resolving the available link', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOnFunction(decorators, 'getLinkDefinition').and.returnValue({
|
||||||
|
resourceType: TEST_MODEL,
|
||||||
|
linkName: 'predecessor',
|
||||||
|
propertyName: 'predecessor'
|
||||||
|
});
|
||||||
|
result = service.resolveLinks(testModel, followLink('predecessor'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the model with the resolved link', () => {
|
||||||
|
expect(result.predecessor).toBe('findByHref');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('resolving the missing link', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOnFunction(decorators, 'getLinkDefinition').and.returnValue({
|
||||||
|
resourceType: TEST_MODEL,
|
||||||
|
linkName: 'successor',
|
||||||
|
propertyName: 'successor'
|
||||||
|
});
|
||||||
|
result = service.resolveLinks(testModel, followLink('successor'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the model with no resolved link', () => {
|
||||||
|
expect(result.successor).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
/* tslint:enable:max-classes-per-file */
|
/* tslint:enable:max-classes-per-file */
|
||||||
|
19
src/app/core/cache/builders/link.service.ts
vendored
19
src/app/core/cache/builders/link.service.ts
vendored
@@ -55,16 +55,19 @@ export class LinkService {
|
|||||||
parent: this.parentInjector
|
parent: this.parentInjector
|
||||||
}).get(provider);
|
}).get(provider);
|
||||||
|
|
||||||
const href = model._links[matchingLinkDef.linkName].href;
|
const link = model._links[matchingLinkDef.linkName];
|
||||||
|
if (hasValue(link)) {
|
||||||
|
const href = link.href;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (matchingLinkDef.isList) {
|
if (matchingLinkDef.isList) {
|
||||||
model[linkToFollow.name] = service.findAllByHref(href, linkToFollow.findListOptions, ...linkToFollow.linksToFollow);
|
model[linkToFollow.name] = service.findAllByHref(href, linkToFollow.findListOptions, ...linkToFollow.linksToFollow);
|
||||||
} else {
|
} else {
|
||||||
model[linkToFollow.name] = service.findByHref(href, ...linkToFollow.linksToFollow);
|
model[linkToFollow.name] = service.findByHref(href, ...linkToFollow.linksToFollow);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(`Something went wrong when using @dataService(${matchingLinkDef.resourceType.value}) ${hasValue(service) ? '' : '(undefined) '}to resolve link ${linkToFollow.name} from ${href}`);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
throw new Error(`Something went wrong when using @dataService(${matchingLinkDef.resourceType.value}) ${hasValue(service) ? '' : '(undefined) '}to resolve link ${linkToFollow.name} from ${href}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return model;
|
return model;
|
||||||
|
Reference in New Issue
Block a user