2018-10-26 10:40:46 +02:00
|
|
|
import * as assert from "assert"
|
2019-03-21 02:56:58 +01:00
|
|
|
import { Aquarius } from "../../src/aquarius/Aquarius"
|
2019-02-12 15:07:10 +01:00
|
|
|
import { SearchQuery } from "../../src/aquarius/query/SearchQuery"
|
2019-02-04 11:46:24 +01:00
|
|
|
import { DDO } from "../../src/ddo/DDO"
|
2018-12-17 15:54:58 +01:00
|
|
|
import DID from "../../src/ocean/DID"
|
2018-11-19 12:16:11 +01:00
|
|
|
import WebServiceConnectorProvider from "../../src/utils/WebServiceConnectorProvider"
|
2018-10-26 10:40:46 +02:00
|
|
|
import config from "../config"
|
2018-11-19 12:16:11 +01:00
|
|
|
import WebServiceConnectorMock from "../mocks/WebServiceConnector.mock"
|
2018-10-26 10:40:46 +02:00
|
|
|
|
2018-10-26 11:57:26 +02:00
|
|
|
describe("Aquarius", () => {
|
2018-10-26 10:40:46 +02:00
|
|
|
|
2019-03-21 03:17:36 +01:00
|
|
|
const aquarius: Aquarius = new Aquarius({config} as any)
|
2019-02-04 11:46:24 +01:00
|
|
|
|
2018-10-26 13:37:09 +02:00
|
|
|
describe("#queryMetadata()", () => {
|
2018-10-26 10:40:46 +02:00
|
|
|
|
2018-11-16 11:35:28 +01:00
|
|
|
const query = {
|
|
|
|
offset: 100,
|
|
|
|
page: 0,
|
|
|
|
query: {
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
sort: {
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
text: "Office",
|
|
|
|
} as SearchQuery
|
2018-10-26 13:40:09 +02:00
|
|
|
|
2018-11-16 11:35:28 +01:00
|
|
|
it("should query metadata", async () => {
|
2018-11-01 12:47:48 +01:00
|
|
|
|
|
|
|
// @ts-ignore
|
2018-11-19 12:16:11 +01:00
|
|
|
WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock([new DDO()]))
|
2018-10-26 10:40:46 +02:00
|
|
|
|
2018-11-16 11:35:28 +01:00
|
|
|
const result: DDO[] = await aquarius.queryMetadata(query)
|
2018-10-26 13:37:09 +02:00
|
|
|
assert(result)
|
2018-11-01 12:47:48 +01:00
|
|
|
assert(result.length !== null)
|
|
|
|
})
|
|
|
|
|
2018-11-16 11:35:28 +01:00
|
|
|
it("should query metadata and return real ddo", async () => {
|
|
|
|
|
|
|
|
// @ts-ignore
|
2018-11-19 12:16:11 +01:00
|
|
|
WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock([new DDO()]))
|
2018-11-16 11:35:28 +01:00
|
|
|
|
|
|
|
const result: DDO[] = await aquarius.queryMetadata(query)
|
2019-02-04 18:13:54 +01:00
|
|
|
|
2018-11-16 11:35:28 +01:00
|
|
|
assert(result)
|
|
|
|
assert(result[0].findServiceById)
|
|
|
|
})
|
2018-11-01 12:47:48 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
describe("#queryMetadataByText()", () => {
|
|
|
|
|
2018-11-16 11:35:28 +01:00
|
|
|
const query = {
|
|
|
|
offset: 100,
|
|
|
|
page: 0,
|
|
|
|
query: {
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
sort: {
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
text: "Office",
|
|
|
|
} as SearchQuery
|
2018-11-01 12:47:48 +01:00
|
|
|
|
2018-11-16 11:35:28 +01:00
|
|
|
it("should query metadata by text", async () => {
|
2018-11-01 12:47:48 +01:00
|
|
|
|
|
|
|
// @ts-ignore
|
2018-11-19 12:16:11 +01:00
|
|
|
WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock([new DDO()]))
|
2018-11-01 12:47:48 +01:00
|
|
|
|
2018-11-16 11:35:28 +01:00
|
|
|
const result: DDO[] = await aquarius.queryMetadataByText(query)
|
2018-11-01 12:47:48 +01:00
|
|
|
assert(result)
|
|
|
|
assert(result.length !== null)
|
2018-10-26 13:37:09 +02:00
|
|
|
})
|
2018-10-26 13:40:09 +02:00
|
|
|
|
2018-11-16 11:35:28 +01:00
|
|
|
it("should query metadata and return real ddo", async () => {
|
|
|
|
|
|
|
|
// @ts-ignore
|
2018-11-19 12:16:11 +01:00
|
|
|
WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock([new DDO()]))
|
2018-11-16 11:35:28 +01:00
|
|
|
|
|
|
|
const result: DDO[] = await aquarius.queryMetadataByText(query)
|
|
|
|
assert(result)
|
|
|
|
assert(result[0].findServiceById)
|
|
|
|
})
|
|
|
|
|
2018-10-26 10:40:46 +02:00
|
|
|
})
|
|
|
|
|
2018-11-01 12:47:48 +01:00
|
|
|
describe("#storeDDO()", () => {
|
|
|
|
|
|
|
|
it("should store a ddo", async () => {
|
|
|
|
|
2018-12-17 15:54:58 +01:00
|
|
|
const did: DID = DID.generate()
|
2018-11-01 12:47:48 +01:00
|
|
|
const ddo: DDO = new DDO({
|
2018-12-17 15:54:58 +01:00
|
|
|
id: did.getId(),
|
2018-11-01 12:47:48 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
// @ts-ignore
|
2018-11-19 12:16:11 +01:00
|
|
|
WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock(ddo))
|
2018-11-01 12:47:48 +01:00
|
|
|
|
|
|
|
const result: DDO = await aquarius.storeDDO(ddo)
|
|
|
|
assert(result)
|
|
|
|
assert(result.id === ddo.id)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("#retrieveDDO()", () => {
|
|
|
|
|
|
|
|
it("should store a ddo", async () => {
|
|
|
|
|
2018-12-17 15:54:58 +01:00
|
|
|
const did: DID = DID.generate()
|
2018-11-01 12:47:48 +01:00
|
|
|
const ddo: DDO = new DDO({
|
2018-12-17 15:54:58 +01:00
|
|
|
id: did.getId(),
|
2018-11-01 12:47:48 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
// @ts-ignore
|
2018-11-19 12:16:11 +01:00
|
|
|
WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock(ddo))
|
2018-11-01 12:47:48 +01:00
|
|
|
|
|
|
|
const storageResult: DDO = await aquarius.storeDDO(ddo)
|
|
|
|
assert(storageResult)
|
|
|
|
|
2018-12-17 15:54:58 +01:00
|
|
|
assert(storageResult.id === did.getId())
|
2018-11-01 12:47:48 +01:00
|
|
|
|
|
|
|
const restrieveResult: DDO = await aquarius.retrieveDDO(did)
|
|
|
|
assert(restrieveResult)
|
|
|
|
|
2018-12-17 15:54:58 +01:00
|
|
|
assert(restrieveResult.id === did.getId())
|
2018-11-01 12:47:48 +01:00
|
|
|
assert(restrieveResult.id === storageResult.id)
|
|
|
|
})
|
|
|
|
})
|
2018-10-26 10:40:46 +02:00
|
|
|
})
|