1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

made ddo business object more versatile

This commit is contained in:
Sebastian Gerske 2018-11-01 11:22:00 +01:00
parent 56fc8e6f23
commit 787ed9dcf3
2 changed files with 39 additions and 9 deletions

View File

@ -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 : [] : []
}
}

View File

@ -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 () => {