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 // @ts-ignore
private assa: string private assa: string
public constructor(ddo: { public constructor(ddo?: {
publicKey: PublicKey[], publicKey?: PublicKey[],
authentication: Authentication[], authentication?: Authentication[],
service: Service[], service?: Service[],
}) { }) {
this.publicKey = ddo.publicKey this.publicKey = ddo ? ddo.publicKey ? ddo.publicKey : [] : []
this.authentication = ddo.authentication this.authentication = ddo ? ddo.authentication ? ddo.authentication : [] : []
this.service = ddo.service 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 PublicKey from "../../src/ddo/PublicKey"
import Service from "../../src/ddo/Service" import Service from "../../src/ddo/Service"
import StructuredMarkup from "../../src/ddo/StructuredMarkup" import StructuredMarkup from "../../src/ddo/StructuredMarkup"
import Logger from "../../src/utils/Logger"
import * as jsonDDO from "../testdata/ddo.json" import * as jsonDDO from "../testdata/ddo.json"
describe("DDO", () => { describe("DDO", () => {
@ -151,12 +150,43 @@ describe("DDO", () => {
it("should properly serialize", async () => { it("should properly serialize", async () => {
const ddoString = DDO.serialize(testDDO) const ddoString = DDO.serialize(testDDO)
Logger.log(ddoString)
assert(ddoString) assert(ddoString)
assert(ddoString.startsWith("{")) 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()", () => { describe("#deserialize()", () => {
it("should properly deserialize from serialized object", async () => { it("should properly deserialize from serialized object", async () => {