From e3139d2150da55bda1878de779a0eff9ef1249af Mon Sep 17 00:00:00 2001 From: Alex Dik Date: Wed, 4 May 2016 17:42:08 +0200 Subject: [PATCH] Add default value for HalLink.$source on instantiation --- .../api/api-v3/hal-resources/hal-resource.service.test.ts | 4 ++++ .../api/api-v3/hal-resources/hal-resource.service.ts | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/app/components/api/api-v3/hal-resources/hal-resource.service.test.ts b/frontend/app/components/api/api-v3/hal-resources/hal-resource.service.test.ts index bde26330c4..c2eba2a346 100644 --- a/frontend/app/components/api/api-v3/hal-resources/hal-resource.service.test.ts +++ b/frontend/app/components/api/api-v3/hal-resources/hal-resource.service.test.ts @@ -46,6 +46,10 @@ describe('HalResource service', () => { expect(HalResource).to.exist; }); + it('should be instantiable using a default object', () => { + expect(new HalResource().href).to.equal(null); + }); + it('should set its source to _plain if _plain is a property of the source', () => { let source = { _plain: { diff --git a/frontend/app/components/api/api-v3/hal-resources/hal-resource.service.ts b/frontend/app/components/api/api-v3/hal-resources/hal-resource.service.ts index da3d05120d..7abc0a779f 100644 --- a/frontend/app/components/api/api-v3/hal-resources/hal-resource.service.ts +++ b/frontend/app/components/api/api-v3/hal-resources/hal-resource.service.ts @@ -50,7 +50,7 @@ export default class HalResource { } protected static getEmptyResource():any { - return {_links: {self: null}}; + return {_links: {self: {}}}; } public get name():string { @@ -86,7 +86,7 @@ export default class HalResource { }); } - constructor(public $source:any, public $loaded:boolean = true) { + constructor(public $source:any = HalResource.getEmptyResource(), public $loaded:boolean = true) { this.$source = $source._plain || $source; this.proxyProperties();