diff --git a/src/ddo/DDO.ts b/src/ddo/DDO.ts index d0febe6..1cca7f8 100644 --- a/src/ddo/DDO.ts +++ b/src/ddo/DDO.ts @@ -23,13 +23,13 @@ export default class DDO { // @ts-ignore private assa: string - public constructor(ddo: { - publicKey: PublicKey[], - authentication: Authentication[], - service: Service[], + public constructor(ddo?: { + publicKey?: PublicKey[], + authentication?: Authentication[], + service?: Service[], }) { - this.publicKey = ddo.publicKey - this.authentication = ddo.authentication - this.service = ddo.service + this.publicKey = ddo ? ddo.publicKey ? ddo.publicKey : [] : [] + this.authentication = ddo ? ddo.authentication ? ddo.authentication : [] : [] + this.service = ddo ? ddo.service ? ddo.service : [] : [] } } diff --git a/test/ddo/DDO.test.ts b/test/ddo/DDO.test.ts index b729182..f57fad0 100644 --- a/test/ddo/DDO.test.ts +++ b/test/ddo/DDO.test.ts @@ -8,7 +8,6 @@ import MetaDataBase from "../../src/ddo/MetaDataBase" import PublicKey from "../../src/ddo/PublicKey" import Service from "../../src/ddo/Service" import StructuredMarkup from "../../src/ddo/StructuredMarkup" -import Logger from "../../src/utils/Logger" import * as jsonDDO from "../testdata/ddo.json" describe("DDO", () => { @@ -151,12 +150,43 @@ describe("DDO", () => { it("should properly serialize", async () => { const ddoString = DDO.serialize(testDDO) - Logger.log(ddoString) assert(ddoString) assert(ddoString.startsWith("{")) }) }) + describe("#constructor()", () => { + + it("should create an empty ddo", async () => { + + const ddo = new DDO() + assert(ddo) + + assert(ddo.service.length === 0) + assert(ddo.authentication.length === 0) + assert(ddo.publicKey.length === 0) + }) + + it("should create an predefined ddo", async () => { + + const service: Service = { + serviceEndpoint: "http://", + description: "nice service" + } as Service + + const ddo = new DDO({ + service: [service] + }) + assert(ddo) + + assert(ddo.service.length === 1) + assert(ddo.service[0].description === service.description) + + assert(ddo.authentication.length === 0) + assert(ddo.publicKey.length === 0) + }) + }) + describe("#deserialize()", () => { it("should properly deserialize from serialized object", async () => {