Skip to content

Commit

Permalink
fix: add unit test for rename property case
Browse files Browse the repository at this point in the history
  • Loading branch information
pcg-kk committed Aug 13, 2024
1 parent 3351615 commit 973fd33
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions src/app/core/cache/builders/link.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ class TestModel implements HALResource {
self: HALLink;
predecessor: HALLink;
successor: HALLink;
standardLinkName: HALLink;
};

predecessor?: TestModel;
successor?: TestModel;
renamedProperty?: TestModel;
}

const mockDataServiceMap: any = new Map([
Expand Down Expand Up @@ -66,6 +68,24 @@ describe('LinkService', () => {
testDataService = new TestDataService();
spyOn(testDataService, 'findListByHref').and.callThrough();
spyOn(testDataService, 'findByHref').and.callThrough();

const linksDefinitions = new Map();
linksDefinitions.set('predecessor', {
resourceType: TEST_MODEL,
linkName: 'predecessor',
propertyName: 'predecessor',
});
linksDefinitions.set('successor', {
resourceType: TEST_MODEL,
linkName: 'successor',
propertyName: 'successor',
});
linksDefinitions.set('standardLinkName', {
resourceType: TEST_MODEL,
linkName: 'standardLinkName',
propertyName: 'renamedProperty',
});

TestBed.configureTestingModule({
providers: [
LinkService,
Expand All @@ -87,18 +107,7 @@ describe('LinkService', () => {
},
{
provide: LINK_DEFINITION_MAP_FACTORY,
useValue: jasmine.createSpy('getLinkDefinitions').and.returnValue([
{
resourceType: TEST_MODEL,
linkName: 'predecessor',
propertyName: 'predecessor',
},
{
resourceType: TEST_MODEL,
linkName: 'successor',
propertyName: 'successor',
},
]),
useValue: jasmine.createSpy('getLinkDefinitions').and.returnValue(linksDefinitions),
},
],
});
Expand All @@ -117,6 +126,15 @@ describe('LinkService', () => {
});
});
});
describe(`when the propertyName is different than linkName`, () => {
beforeEach(() => {
result = service.resolveLink(testModel, followLink('standardLinkName', {}));
});
it('link should be assign to custom property', () => {
expect(result.renamedProperty).toBeDefined();
expect(result.standardLinkName).toBeUndefined();
});
});
describe(`when the linkdefinition concerns a list`, () => {
beforeEach(() => {
((service as any).getLinkDefinition as jasmine.Spy).and.returnValue({
Expand Down

0 comments on commit 973fd33

Please sign in to comment.