2019-05-08 16:55:58 +02:00
|
|
|
import { assert, spy, use } from "chai"
|
|
|
|
import * as spies from "chai-spies"
|
|
|
|
|
|
|
|
import { Ocean } from "../../src/ocean/Ocean"
|
2019-03-21 02:56:58 +01:00
|
|
|
import { Aquarius } from "../../src/aquarius/Aquarius"
|
2019-04-01 14:36:44 +02:00
|
|
|
import { SearchQuery } from "../../src/aquarius/Aquarius"
|
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-10-26 10:40:46 +02:00
|
|
|
import config from "../config"
|
2019-05-08 16:55:58 +02:00
|
|
|
|
|
|
|
use(spies)
|
|
|
|
|
2019-05-08 23:38:12 +02:00
|
|
|
const reponsify = async (data) => ({ok: true, json: () => Promise.resolve(data)})
|
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-05-08 16:55:58 +02:00
|
|
|
let ocean: Ocean
|
|
|
|
let aquarius: Aquarius
|
2019-04-05 12:20:42 +02:00
|
|
|
// tslint:disable-next-line
|
|
|
|
const getResults = (results: DDO[], page = 0, total_pages = 1, total_results = 1) =>
|
|
|
|
({results, page, total_pages, total_results})
|
2019-02-04 11:46:24 +01:00
|
|
|
|
2019-05-08 16:55:58 +02:00
|
|
|
beforeEach(async () => {
|
|
|
|
ocean = await Ocean.getInstance(config)
|
|
|
|
aquarius = ocean.aquarius
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
spy.restore()
|
|
|
|
})
|
|
|
|
|
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,
|
2019-04-16 19:01:11 +02:00
|
|
|
page: 1,
|
2018-11-16 11:35:28 +01:00
|
|
|
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 () => {
|
2019-05-08 23:38:12 +02:00
|
|
|
spy.on(ocean.utils.fetch, "post", () => reponsify(getResults([new DDO()])))
|
2019-04-05 12:20:42 +02:00
|
|
|
|
|
|
|
const result = await aquarius.queryMetadata(query)
|
|
|
|
assert.typeOf(result.results, "array")
|
|
|
|
assert.lengthOf(result.results, 1)
|
|
|
|
assert.equal(result.page, 0)
|
|
|
|
assert.equal(result.totalPages, 1)
|
|
|
|
assert.equal(result.totalResults, 1)
|
2018-11-01 12:47:48 +01:00
|
|
|
})
|
|
|
|
|
2018-11-16 11:35:28 +01:00
|
|
|
it("should query metadata and return real ddo", async () => {
|
|
|
|
|
2019-05-08 23:38:12 +02:00
|
|
|
spy.on(ocean.utils.fetch, "post", () => reponsify(getResults([new DDO()])))
|
2018-11-16 11:35:28 +01:00
|
|
|
|
2019-04-05 12:20:42 +02:00
|
|
|
const result = await aquarius.queryMetadata(query)
|
|
|
|
assert.typeOf(result.results, "array")
|
|
|
|
assert.lengthOf(result.results, 1)
|
|
|
|
assert.isDefined(result.results[0].findServiceById)
|
2018-11-16 11:35:28 +01:00
|
|
|
})
|
2018-11-01 12:47:48 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
describe("#queryMetadataByText()", () => {
|
|
|
|
|
2018-11-16 11:35:28 +01:00
|
|
|
const query = {
|
|
|
|
offset: 100,
|
2019-04-16 19:01:11 +02:00
|
|
|
page: 1,
|
2018-11-16 11:35:28 +01:00
|
|
|
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
|
|
|
|
2019-05-08 23:38:12 +02:00
|
|
|
spy.on(ocean.utils.fetch, "get", () => reponsify(getResults([new DDO()])))
|
2019-04-05 12:20:42 +02:00
|
|
|
|
|
|
|
const result = await aquarius.queryMetadataByText(query)
|
|
|
|
assert.typeOf(result.results, "array")
|
|
|
|
assert.lengthOf(result.results, 1)
|
|
|
|
assert.equal(result.page, 0)
|
|
|
|
assert.equal(result.totalPages, 1)
|
|
|
|
assert.equal(result.totalResults, 1)
|
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 () => {
|
|
|
|
|
2019-05-08 23:38:12 +02:00
|
|
|
spy.on(ocean.utils.fetch, "get", () => reponsify(getResults([new DDO()])))
|
2018-11-16 11:35:28 +01:00
|
|
|
|
2019-04-05 12:20:42 +02:00
|
|
|
const result = await aquarius.queryMetadataByText(query)
|
|
|
|
assert.typeOf(result.results, "array")
|
|
|
|
assert.lengthOf(result.results, 1)
|
|
|
|
assert.isDefined(result.results[0].findServiceById)
|
2018-11-16 11:35:28 +01:00
|
|
|
})
|
|
|
|
|
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
|
|
|
})
|
|
|
|
|
2019-05-08 23:38:12 +02:00
|
|
|
spy.on(ocean.utils.fetch, "post", () => reponsify(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
|
|
|
})
|
|
|
|
|
2019-05-08 23:38:12 +02:00
|
|
|
spy.on(ocean.utils.fetch, "post", () => reponsify(ddo))
|
|
|
|
spy.on(ocean.utils.fetch, "get", () => reponsify(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
|
|
|
})
|