diff --git a/integration/config/config.json b/integration/config/config.json index 34f5721..8b787aa 100644 --- a/integration/config/config.json +++ b/integration/config/config.json @@ -1,6 +1,6 @@ { "nodeUri": "http://localhost:8545", - "aquariusUri": "https://nginx-aquarius.dev-ocean.com", + "aquariusUri": "http://localhost:5000", "brizoUri": "http://localhost:8030", "parityUri": "http://localhost:9545", "secretStoreUri": "http://localhost:12001", diff --git a/integration/ocean/SearchAsset.test.ts b/integration/ocean/SearchAsset.test.ts new file mode 100644 index 0000000..1f21eee --- /dev/null +++ b/integration/ocean/SearchAsset.test.ts @@ -0,0 +1,117 @@ +import { assert } from 'chai' + +import { config } from "../config" + +import { Ocean, MetaData, Account, DDO } from '../../src' // @oceanprotocol/squid + +describe("Search Asset", () => { + let ocean: Ocean + + let publisher: Account + + const testHash = Math.random().toString(36).substr(2) + let metadata: Partial + let metadataGenerator = (name: string) => ({ + ...metadata, + base: { + ...metadata.base, + name: `${name}${testHash}`, + }, + }) + + let test1length + let test2length + let test3length + + before(async () => { + ocean = await Ocean.getInstance(config) + + // Accounts + publisher = (await ocean.accounts.list())[0] + publisher.setPassword(process.env.ACCOUNT_PASSWORD) + + // Data + metadata = { + base: { + name: undefined, + type: "dataset", + description: "Weather information of UK including temperature and humidity", + size: "3.1gb", + dateCreated: "2012-02-01T10:55:11+00:00", + author: "Met Office", + license: "CC-BY", + copyrightHolder: "Met Office", + encoding: "UTF-8", + compression: "zip", + contentType: "text/csv", + // tslint:disable-next-line + workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68", + files: [ + { + url: "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip", + checksum: "085340abffh21495345af97c6b0e761", + contentLength: "12324", + }, + { + url: "https://testocnfiles.blob.core.windows.net/testfiles/testzkp2.zip", + }, + ], + links: [ + {sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"}, + {sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/"}, + {fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/"}, + ], + inLanguage: "en", + tags: "weather, uk, 2011, temperature, humidity", + price: 10, + }, + } + + }) + + it("should be able to search the assets", async () => { + const ddos: DDO[] = await ocean.assets.search(`Test1${testHash}`) + + assert.isArray(ddos, "A search should return an array") + + test1length = ddos.length + test2length = (await ocean.assets.search(`Test2${testHash}`)).length + test3length = (await ocean.assets.search(`Test3${testHash}`)).length + }) + + it("should regiester some a asset", async () => { + assert.instanceOf(await ocean.assets.create(metadataGenerator("Test1") as any, publisher), DDO) + assert.instanceOf(await ocean.assets.create(metadataGenerator("Test2") as any, publisher), DDO) + assert.instanceOf(await ocean.assets.create(metadataGenerator("Test2") as any, publisher), DDO) + assert.instanceOf(await ocean.assets.create(metadataGenerator("Test3") as any, publisher), DDO) + }) + + it("should search by text and see the increment of DDOs", async () => { + assert.equal((await ocean.assets.search(`Test2${testHash}`)).length - test2length, 2, "Something was wrong searching the assets") + assert.equal((await ocean.assets.search(`Test3${testHash}`)).length - test3length, 1, "Something was wrong searching the assets") + }) + + it("should return a list of DDOs", async () => { + const ddos: DDO[] = await ocean.assets.search(`Test1${testHash}`) + + assert.equal(ddos.length - test1length, 1, "Something was wrong searching the assets") + ddos.map(ddo => assert.instanceOf(ddo, DDO, "The DDO is not an instance of a DDO")) + }) + + it("should be able to do a query to get a list of DDOs", async () => { + const ddos: DDO[] = await ocean.assets.query({ + text: `Test2${testHash}`, + page: 0, + offset: 1, + query: { + value: 1, + }, + sort: { + value: 1, + }, + }) + + assert.equal(ddos.length, 1, "Something was wrong searching the assets") + ddos.map(ddo => assert.instanceOf(ddo, DDO, "The DDO is not an instance of a DDO")) + }) +}) diff --git a/src/aquarius/Aquarius.ts b/src/aquarius/Aquarius.ts index cc3766e..1ce47dd 100644 --- a/src/aquarius/Aquarius.ts +++ b/src/aquarius/Aquarius.ts @@ -4,7 +4,7 @@ import Config from "../models/Config" import DID from "../ocean/DID" import Logger from "../utils/Logger" import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider" -import SearchQuery from "./query/SearchQuery" +import { SearchQuery } from "./query/SearchQuery" const apiPath = "/api/v1/aquarius/assets/ddo" diff --git a/src/aquarius/query/Query.ts b/src/aquarius/query/Query.ts deleted file mode 100644 index 1c5c892..0000000 --- a/src/aquarius/query/Query.ts +++ /dev/null @@ -1,3 +0,0 @@ -export default class Query { - public value: number = 1 -} diff --git a/src/aquarius/query/SearchQuery.ts b/src/aquarius/query/SearchQuery.ts index 16eea31..f5c9ae7 100644 --- a/src/aquarius/query/SearchQuery.ts +++ b/src/aquarius/query/SearchQuery.ts @@ -1,14 +1,7 @@ -import Query from "./Query" -import Sort from "./Sort" - -export default class SearchQuery { - public offset: number = 100 - public page: number = 0 - public query: Query = { - value: 1, - } as Query - public sort: Sort = { - value: 1, - } as Sort - public text: string = "Office" +export interface SearchQuery { + text: string + offset: number + page: number + query: {[property: string]: string | number | string[] | number[]} + sort: {[jsonPath: string]: number} } diff --git a/src/aquarius/query/Sort.ts b/src/aquarius/query/Sort.ts deleted file mode 100644 index 3aa3fd9..0000000 --- a/src/aquarius/query/Sort.ts +++ /dev/null @@ -1,3 +0,0 @@ -export default class Sort { - public value: number = 1 -} diff --git a/src/index.ts b/src/index.ts index d13a0eb..acef49a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1 @@ -export * from './squid' +export * from "./squid" diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 9add1d1..d507be7 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -5,7 +5,7 @@ import OceanAgreements from "./OceanAgreements" import OceanAssets from "./OceanAssets" import AquariusProvider from "../aquarius/AquariusProvider" -import SearchQuery from "../aquarius/query/SearchQuery" +import { SearchQuery } from "../aquarius/query/SearchQuery" import BrizoProvider from "../brizo/BrizoProvider" import ConfigProvider from "../ConfigProvider" import { DDO } from "../ddo/DDO" @@ -175,7 +175,9 @@ export default class Ocean { const accessEvent: ContractEvent = EventListener.subscribe( accessService.conditions[1].contractName, - accessService.conditions[1].events[1].name, {}) + accessService.conditions[1].events[1].name, + {}, + ) const filesPromise = new Promise((resolve) => { accessEvent.listenOnce(async () => { Logger.log("Awesome; got a AccessGranted Event. Let's download the asset files.") diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index 40d5ec5..47ce732 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -1,5 +1,5 @@ import AquariusProvider from "../aquarius/AquariusProvider" -import SearchQuery from "../aquarius/query/SearchQuery" +import { SearchQuery } from "../aquarius/query/SearchQuery" import BrizoProvider from "../brizo/BrizoProvider" import { Condition } from "../ddo/Condition" import { DDO } from "../ddo/DDO" @@ -230,7 +230,7 @@ export default class OceanAssets { * @return {Promise} */ public async query(query: SearchQuery): Promise { - return AquariusProvider.getAquarius().queryMetadata(query) + return AquariusProvider.getAquarius().queryMetadataByText(query) } /** diff --git a/src/squid.ts b/src/squid.ts index 2a1b7b0..46a316a 100644 --- a/src/squid.ts +++ b/src/squid.ts @@ -1,14 +1,14 @@ -import Access from "./ocean/ServiceAgreements/Templates/Access" -import Account from "./ocean/Account" import Config from "./models/Config" +import Account from "./ocean/Account" import DID from "./ocean/DID" -import FitchainCompute from "./ocean/ServiceAgreements/Templates/FitchainCompute" import IdGenerator from "./ocean/IdGenerator" -import Logger from "./utils/Logger" import Ocean from "./ocean/Ocean" -import SecretStoreProvider from "./secretstore/SecretStoreProvider" import ServiceAgreement from "./ocean/ServiceAgreements/ServiceAgreement" import ServiceAgreementTemplate from "./ocean/ServiceAgreements/ServiceAgreementTemplate" +import Access from "./ocean/ServiceAgreements/Templates/Access" +import FitchainCompute from "./ocean/ServiceAgreements/Templates/FitchainCompute" +import SecretStoreProvider from "./secretstore/SecretStoreProvider" +import Logger from "./utils/Logger" import WebServiceConnectorProvider from "./utils/WebServiceConnectorProvider" import EventListener from "./keeper/EventListener" diff --git a/test/aquarius/Aquarius.test.ts b/test/aquarius/Aquarius.test.ts index 981fb54..0506081 100644 --- a/test/aquarius/Aquarius.test.ts +++ b/test/aquarius/Aquarius.test.ts @@ -1,6 +1,6 @@ import * as assert from "assert" import Aquarius from "../../src/aquarius/Aquarius" -import SearchQuery from "../../src/aquarius/query/SearchQuery" +import { SearchQuery } from "../../src/aquarius/query/SearchQuery" import { DDO } from "../../src/ddo/DDO" import DID from "../../src/ocean/DID" import WebServiceConnectorProvider from "../../src/utils/WebServiceConnectorProvider" diff --git a/test/ocean/Ocean.test.ts b/test/ocean/Ocean.test.ts index b1209cd..f075bfc 100644 --- a/test/ocean/Ocean.test.ts +++ b/test/ocean/Ocean.test.ts @@ -2,7 +2,7 @@ import { assert, spy, use } from "chai" import * as spies from "chai-spies" import AquariusProvider from "../../src/aquarius/AquariusProvider" -import SearchQuery from "../../src/aquarius/query/SearchQuery" +import { SearchQuery } from "../../src/aquarius/query/SearchQuery" import BrizoProvider from "../../src/brizo/BrizoProvider" import ConfigProvider from "../../src/ConfigProvider" import { DDO } from "../../src/ddo/DDO"