From 192eecc3ae52d34f6323a3e9ddbe264dc7e514bd Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 26 Oct 2018 10:40:46 +0200 Subject: [PATCH 1/7] added searchAssets --- src/ConfigProvider.ts | 2 +- src/aquarius/Aquarius.ts | 33 ++++++++++++++++++++- src/aquarius/AquariusProvider.ts | 9 ++++-- src/models/Config.ts | 2 +- src/ocean/Ocean.ts | 8 +++-- test/aquarius/Aquarius.test.ts | 33 +++++++++++++++++++++ test/config.ts | 2 ++ test/keeper/ContractBase.test.ts | 12 ++++---- test/keeper/ContractHandler.test.ts | 10 +++---- test/keeper/Keeper.test.ts | 12 ++++---- test/mocks/Aquarius.mock.ts | 2 +- test/ocean/Account.test.ts | 16 +++++----- test/ocean/Asset.test.ts | 26 ++++++++--------- test/ocean/Ocean.test.ts | 45 ++++++++++++++++++++++------- test/ocean/Order.test.ts | 27 +++++++++-------- 15 files changed, 170 insertions(+), 69 deletions(-) create mode 100644 test/aquarius/Aquarius.test.ts diff --git a/src/ConfigProvider.ts b/src/ConfigProvider.ts index f66ef58..ed09436 100644 --- a/src/ConfigProvider.ts +++ b/src/ConfigProvider.ts @@ -6,7 +6,7 @@ export default class ConfigProvider { return ConfigProvider.config } - public static configure(config: Config) { + public static setConfig(config: Config) { ConfigProvider.config = config } diff --git a/src/aquarius/Aquarius.ts b/src/aquarius/Aquarius.ts index 8503c80..26f7375 100644 --- a/src/aquarius/Aquarius.ts +++ b/src/aquarius/Aquarius.ts @@ -1,8 +1,17 @@ import fetch from "node-fetch" +import ConfigProvider from "../ConfigProvider" import Logger from "../utils/Logger" export default class Aquarius { - public static async getAccessUrl(accessToken: any, payload: any): Promise { + + private url: string + + constructor() { + + this.url = ConfigProvider.getConfig().aquariusUri + } + + public async getAccessUrl(accessToken: any, payload: any): Promise { const accessUrl = await fetch(`${accessToken.service_endpoint}/${accessToken.resource_id}`, { method: "POST", @@ -27,4 +36,26 @@ export default class Aquarius { return accessUrl } + + public async queryMetadata(query): Promise { + + const result = await fetch(this.url + "/api/v1/aquarius/assets/metadata/query", { + method: "POST", + body: JSON.stringify(query), + headers: { + "Content-type": "application/json", + }, + }) + .then((response: any) => { + if (response.ok) { + return response.json() + } + Logger.log("Failed: ", response.status, response.statusText) + }) + .catch((error) => { + Logger.error("Error fetching querying metdata: ", error) + }) + + return result + } } diff --git a/src/aquarius/AquariusProvider.ts b/src/aquarius/AquariusProvider.ts index ab5db68..c6f1ec6 100644 --- a/src/aquarius/AquariusProvider.ts +++ b/src/aquarius/AquariusProvider.ts @@ -1,14 +1,19 @@ +import Aquarius from "./Aquarius" + export default class AquariusProvider { - public static setAquarius(aquarius) { + public static setAquarius(aquarius: Aquarius) { AquariusProvider.aquarius = aquarius } public static getAquarius() { + if (!AquariusProvider.aquarius) { + AquariusProvider.aquarius = new Aquarius() + } return AquariusProvider.aquarius } - private static aquarius + private static aquarius: Aquarius = null } diff --git a/src/models/Config.ts b/src/models/Config.ts index 4207965..786838f 100644 --- a/src/models/Config.ts +++ b/src/models/Config.ts @@ -1,5 +1,5 @@ export default class Config { - public providerUri: string + public aquariusUri: string public nodeUri: string public web3Provider: any } diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index c390253..26e0e8a 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -1,4 +1,3 @@ -import Aquarius from "../aquarius/Aquarius" import AquariusProvider from "../aquarius/AquariusProvider" import ConfigProvider from "../ConfigProvider" import Keeper from "../keeper/Keeper" @@ -13,8 +12,7 @@ export default class Ocean { public static async getInstance(config) { if (!Ocean.instance) { - ConfigProvider.configure(config) - AquariusProvider.setAquarius(Aquarius) + ConfigProvider.setConfig(config) Ocean.instance = new Ocean(await Keeper.getInstance()) } @@ -90,4 +88,8 @@ export default class Ocean { return orders } + + public async searchAssets(query): Promise { + return AquariusProvider.getAquarius().queryMetadata(query) + } } diff --git a/test/aquarius/Aquarius.test.ts b/test/aquarius/Aquarius.test.ts new file mode 100644 index 0000000..5e78ab1 --- /dev/null +++ b/test/aquarius/Aquarius.test.ts @@ -0,0 +1,33 @@ +import * as assert from "assert" +import Aquarius from "../../src/aquarius/Aquarius" +import ConfigProvider from "../../src/ConfigProvider" +import config from "../config" + +describe("Aquarius", () => { + + before(() => { + + ConfigProvider.setConfig(config) + }) + + describe("#queryMetadata()queryMetadata", async () => { + + const aquarius: Aquarius = new Aquarius() + + const query = { + offset: 100, + page: 0, + query: { + value: 1, + }, + sort: { + value: 1, + }, + text: "Office", + } + + const result: any[] = await aquarius.queryMetadata(query) + assert(result) + }) + +}) diff --git a/test/config.ts b/test/config.ts index 6c85b26..4a915db 100644 --- a/test/config.ts +++ b/test/config.ts @@ -1,5 +1,7 @@ import Config from "../src/models/Config" export default { + aquariusUri: "http://localhost:5000", nodeUri: "http://localhost:8545", + web3Provider: null, } as Config diff --git a/test/keeper/ContractBase.test.ts b/test/keeper/ContractBase.test.ts index a77424a..b620dda 100644 --- a/test/keeper/ContractBase.test.ts +++ b/test/keeper/ContractBase.test.ts @@ -5,14 +5,14 @@ import ContractBaseMock from "../mocks/ContractBase.Mock" const wrappedContract = new ContractBaseMock("OceanToken") -before(async () => { - ConfigProvider.configure(config) - await ContractHandler.deployContracts() - wrappedContract.initMock() -}) - describe("ContractWrapperBase", () => { + before(async () => { + ConfigProvider.setConfig(config) + await ContractHandler.deployContracts() + wrappedContract.initMock() + }) + describe("#call()", () => { it("should fail to call on an unknown contract function", (done) => { diff --git a/test/keeper/ContractHandler.test.ts b/test/keeper/ContractHandler.test.ts index 0f6510a..20b8164 100644 --- a/test/keeper/ContractHandler.test.ts +++ b/test/keeper/ContractHandler.test.ts @@ -3,13 +3,13 @@ import ConfigProvider from "../../src/ConfigProvider" import ContractHandler from "../../src/keeper/ContractHandler" import config from "../config" -before(async () => { - ConfigProvider.configure(config) - await ContractHandler.deployContracts() -}) - describe("ContractHandler", () => { + before(async () => { + ConfigProvider.setConfig(config) + await ContractHandler.deployContracts() + }) + describe("#get()", () => { it("should load and get OceanToken correctly", async () => { diff --git a/test/keeper/Keeper.test.ts b/test/keeper/Keeper.test.ts index b70001b..967b9cc 100644 --- a/test/keeper/Keeper.test.ts +++ b/test/keeper/Keeper.test.ts @@ -6,14 +6,14 @@ import config from "../config" let keeper: Keeper -before(async () => { - ConfigProvider.configure(config) - await ContractHandler.deployContracts() - keeper = await Keeper.getInstance() -}) - describe("Keeper", () => { + before(async () => { + ConfigProvider.setConfig(config) + await ContractHandler.deployContracts() + keeper = await Keeper.getInstance() + }) + describe("public interface", () => { it("should have market", () => { diff --git a/test/mocks/Aquarius.mock.ts b/test/mocks/Aquarius.mock.ts index 46d479e..9b962be 100644 --- a/test/mocks/Aquarius.mock.ts +++ b/test/mocks/Aquarius.mock.ts @@ -2,7 +2,7 @@ import Aquarius from "../../src/aquarius/Aquarius" export default class AquariusMock extends Aquarius { - public static async getAccessUrl(accessToken: any, payload: any): Promise { + public async getAccessUrl(accessToken: any, payload: any): Promise { return "http://test/test" } } diff --git a/test/ocean/Account.test.ts b/test/ocean/Account.test.ts index 6914f05..93aedd5 100644 --- a/test/ocean/Account.test.ts +++ b/test/ocean/Account.test.ts @@ -9,16 +9,16 @@ import config from "../config" let ocean: Ocean let accounts: Account[] -before(async () => { - ConfigProvider.configure(config) - await ContractHandler.deployContracts() - ocean = await Ocean.getInstance(config) - - accounts = await ocean.getAccounts() -}) - describe("Account", () => { + before(async () => { + ConfigProvider.setConfig(config) + await ContractHandler.deployContracts() + ocean = await Ocean.getInstance(config) + + accounts = await ocean.getAccounts() + }) + describe("#getOceanBalance()", () => { it("should get initial ocean balance", async () => { diff --git a/test/ocean/Asset.test.ts b/test/ocean/Asset.test.ts index 4a2c17f..aaaaa81 100644 --- a/test/ocean/Asset.test.ts +++ b/test/ocean/Asset.test.ts @@ -19,21 +19,21 @@ let testAsset: Asset let accounts: Account[] let testPublisher: Account -before(async () => { - ConfigProvider.configure(config) - AquariusProvider.setAquarius(AquariusMock) - - await ContractHandler.deployContracts() - ocean = await Ocean.getInstance(config) - accounts = await ocean.getAccounts() - testPublisher = accounts[0] - testAsset = new Asset(testName, testDescription, testPrice, testPublisher) - - await ocean.register(testAsset) -}) - describe("Asset", () => { + before(async () => { + ConfigProvider.setConfig(config) + AquariusProvider.setAquarius(new AquariusMock(config.aquariusUri)) + + await ContractHandler.deployContracts() + ocean = await Ocean.getInstance(config) + accounts = await ocean.getAccounts() + testPublisher = accounts[0] + testAsset = new Asset(testName, testDescription, testPrice, testPublisher) + + await ocean.register(testAsset) + }) + describe("#purchase()", () => { it("should purchase an asset", async () => { diff --git a/test/ocean/Ocean.test.ts b/test/ocean/Ocean.test.ts index fc855ee..297e035 100644 --- a/test/ocean/Ocean.test.ts +++ b/test/ocean/Ocean.test.ts @@ -1,4 +1,5 @@ import {assert} from "chai" +import AquariusProvider from "../../src/aquarius/AquariusProvider" import ConfigProvider from "../../src/ConfigProvider" import ContractHandler from "../../src/keeper/ContractHandler" import Account from "../../src/ocean/Account" @@ -6,6 +7,7 @@ import Asset from "../../src/ocean/Asset" import Ocean from "../../src/ocean/Ocean" import Order from "../../src/ocean/Order" import config from "../config" +import AquariusMock from "../mocks/Aquarius.mock" let ocean: Ocean let accounts: Account[] @@ -17,18 +19,19 @@ const description = "This asset is pure owange" const price = 100 const timeout = 100000000 -before(async () => { - ConfigProvider.configure(config) - await ContractHandler.deployContracts() - ocean = await Ocean.getInstance(config) - accounts = await ocean.getAccounts() - - testPublisher = accounts[0] - testAsset = new Asset(name, description, price, testPublisher) -}) - describe("Ocean", () => { + before(async () => { + ConfigProvider.setConfig(config) + AquariusProvider.setAquarius(new AquariusMock()) + await ContractHandler.deployContracts() + ocean = await Ocean.getInstance(config) + accounts = await ocean.getAccounts() + + testPublisher = accounts[0] + testAsset = new Asset(name, description, price, testPublisher) + }) + describe("#getInstance()", () => { it("should list accounts", async () => { @@ -84,4 +87,26 @@ describe("Ocean", () => { }) + describe("#searchAssets()", () => { + + it("should search for assets", async () => { + + const query = { + offset: 100, + page: 0, + query: { + value: 1, + }, + sort: { + value: 1, + }, + text: "Office", + } + + const assets: any[] = await ocean.searchAssets(query) + + assert(assets) + }) + + }) }) diff --git a/test/ocean/Order.test.ts b/test/ocean/Order.test.ts index 8624502..1f2ff09 100644 --- a/test/ocean/Order.test.ts +++ b/test/ocean/Order.test.ts @@ -1,4 +1,5 @@ import {assert} from "chai" +import AquariusProvider from "../../src/aquarius/AquariusProvider" import ConfigProvider from "../../src/ConfigProvider" import ContractHandler from "../../src/keeper/ContractHandler" import AccessStatus from "../../src/models/AccessStatus" @@ -7,6 +8,7 @@ import Asset from "../../src/ocean/Asset" import Ocean from "../../src/ocean/Ocean" import Order from "../../src/ocean/Order" import config from "../config" +import AquariusMock from "../mocks/Aquarius.mock" const testName = "Order Test Asset" const testDescription = "This asset is pure owange" @@ -20,20 +22,21 @@ let accounts: Account[] let testPublisher: Account let testConsumer: Account -before(async () => { - ConfigProvider.configure(config) - await ContractHandler.deployContracts() - ocean = await Ocean.getInstance(config) - accounts = await ocean.getAccounts() - testPublisher = accounts[0] - testConsumer = accounts[1] - // register an asset to play around with - testAsset = new Asset(testName, testDescription, testPrice, testPublisher) - await ocean.register(testAsset) -}) - describe("Order", () => { + before(async () => { + ConfigProvider.setConfig(config) + AquariusProvider.setAquarius(new AquariusMock()) + await ContractHandler.deployContracts() + ocean = await Ocean.getInstance(config) + accounts = await ocean.getAccounts() + testPublisher = accounts[0] + testConsumer = accounts[1] + // register an asset to play around with + testAsset = new Asset(testName, testDescription, testPrice, testPublisher) + await ocean.register(testAsset) + }) + describe("#pay()", async () => { it("should pay for an order", async () => { From 9b016afd4b70dd355ba1be138816175a87ecb022 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 26 Oct 2018 10:54:02 +0200 Subject: [PATCH 2/7] fix asset test --- test/ocean/Asset.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ocean/Asset.test.ts b/test/ocean/Asset.test.ts index aaaaa81..cf85365 100644 --- a/test/ocean/Asset.test.ts +++ b/test/ocean/Asset.test.ts @@ -23,7 +23,7 @@ describe("Asset", () => { before(async () => { ConfigProvider.setConfig(config) - AquariusProvider.setAquarius(new AquariusMock(config.aquariusUri)) + AquariusProvider.setAquarius(new AquariusMock()) await ContractHandler.deployContracts() ocean = await Ocean.getInstance(config) @@ -33,7 +33,7 @@ describe("Asset", () => { await ocean.register(testAsset) }) - + describe("#purchase()", () => { it("should purchase an asset", async () => { From f7b88cf9f80e6c671c60b6d167806ebc5c26e6ac Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 26 Oct 2018 10:55:38 +0200 Subject: [PATCH 3/7] v0.1.0-beta.17 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 38133bd..4566113 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@oceanprotocol/squid", - "version": "0.1.0-beta.16", + "version": "0.1.0-beta.17", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 905ba40..4f0c0ef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@oceanprotocol/squid", - "version": "0.1.0-beta.16", + "version": "0.1.0-beta.17", "description": "JavaScript client library for Ocean Protocol", "main": "dist/squid.js", "scripts": { From 43119ed6062df950174731b36a8b6e9b8616f378 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 26 Oct 2018 11:57:26 +0200 Subject: [PATCH 4/7] added fetch mock --- src/ConfigProvider.ts | 2 +- src/aquarius/Aquarius.ts | 28 ++++++++--------------- src/aquarius/AquariusConnector.ts | 14 ++++++++++++ src/aquarius/AquariusConnectorProvider.ts | 23 +++++++++++++++++++ src/aquarius/AquariusProvider.ts | 3 ++- test/aquarius/Aquarius.test.ts | 16 ++++++------- test/mocks/AquariusConnector.mock.ts | 17 ++++++++++++++ test/ocean/Asset.test.ts | 2 +- test/ocean/Ocean.test.ts | 4 ++-- test/ocean/Order.test.ts | 2 +- 10 files changed, 79 insertions(+), 32 deletions(-) create mode 100644 src/aquarius/AquariusConnector.ts create mode 100644 src/aquarius/AquariusConnectorProvider.ts create mode 100644 test/mocks/AquariusConnector.mock.ts diff --git a/src/ConfigProvider.ts b/src/ConfigProvider.ts index ed09436..d133fc8 100644 --- a/src/ConfigProvider.ts +++ b/src/ConfigProvider.ts @@ -2,7 +2,7 @@ import Config from "./models/Config" export default class ConfigProvider { - public static getConfig() { + public static getConfig(): Config { return ConfigProvider.config } diff --git a/src/aquarius/Aquarius.ts b/src/aquarius/Aquarius.ts index 26f7375..bc213a4 100644 --- a/src/aquarius/Aquarius.ts +++ b/src/aquarius/Aquarius.ts @@ -1,25 +1,21 @@ -import fetch from "node-fetch" -import ConfigProvider from "../ConfigProvider" +import Config from "../models/Config" import Logger from "../utils/Logger" +import AquariusConnectorProvider from "./AquariusConnectorProvider" export default class Aquarius { private url: string - constructor() { + constructor(config: Config) { - this.url = ConfigProvider.getConfig().aquariusUri + this.url = config.aquariusUri } public async getAccessUrl(accessToken: any, payload: any): Promise { - const accessUrl = await fetch(`${accessToken.service_endpoint}/${accessToken.resource_id}`, { - method: "POST", - body: payload, - headers: { - "Content-type": "application/json", - }, - }) + const accessUrl = await AquariusConnectorProvider.getConnector().post( + `${accessToken.service_endpoint}/${accessToken.resource_id}`, + payload) .then((response: any) => { if (response.ok) { return response.text() @@ -39,13 +35,9 @@ export default class Aquarius { public async queryMetadata(query): Promise { - const result = await fetch(this.url + "/api/v1/aquarius/assets/metadata/query", { - method: "POST", - body: JSON.stringify(query), - headers: { - "Content-type": "application/json", - }, - }) + const result = await AquariusConnectorProvider.getConnector().post( + this.url + "/api/v1/aquarius/assets/metadata/query", + JSON.stringify(query)) .then((response: any) => { if (response.ok) { return response.json() diff --git a/src/aquarius/AquariusConnector.ts b/src/aquarius/AquariusConnector.ts new file mode 100644 index 0000000..247799d --- /dev/null +++ b/src/aquarius/AquariusConnector.ts @@ -0,0 +1,14 @@ +import fetch from "node-fetch" + +export default class AquariusConnector { + + public post(url, payload) { + return fetch(url, { + method: "POST", + body: payload, + headers: { + "Content-type": "application/json", + }, + }) + } +} diff --git a/src/aquarius/AquariusConnectorProvider.ts b/src/aquarius/AquariusConnectorProvider.ts new file mode 100644 index 0000000..edc9d1f --- /dev/null +++ b/src/aquarius/AquariusConnectorProvider.ts @@ -0,0 +1,23 @@ +import Logger from "../utils/Logger" +import AquariusConnector from "./AquariusConnector" + +export default class AquariusConnectorProvider { + + public static setConnector(connector: AquariusConnector) { + + Logger.log("setting", typeof connector.constructor.name) + + AquariusConnectorProvider.connector = connector + } + + public static getConnector() { + + if (!AquariusConnectorProvider.connector) { + AquariusConnectorProvider.connector = new AquariusConnector() + } + Logger.log("getting", typeof AquariusConnectorProvider.connector.constructor.name) + return AquariusConnectorProvider.connector + } + + private static connector: AquariusConnector = null +} diff --git a/src/aquarius/AquariusProvider.ts b/src/aquarius/AquariusProvider.ts index c6f1ec6..e881643 100644 --- a/src/aquarius/AquariusProvider.ts +++ b/src/aquarius/AquariusProvider.ts @@ -1,3 +1,4 @@ +import ConfigProvider from "../ConfigProvider" import Aquarius from "./Aquarius" export default class AquariusProvider { @@ -10,7 +11,7 @@ export default class AquariusProvider { public static getAquarius() { if (!AquariusProvider.aquarius) { - AquariusProvider.aquarius = new Aquarius() + AquariusProvider.aquarius = new Aquarius(ConfigProvider.getConfig()) } return AquariusProvider.aquarius } diff --git a/test/aquarius/Aquarius.test.ts b/test/aquarius/Aquarius.test.ts index 5e78ab1..9a4529e 100644 --- a/test/aquarius/Aquarius.test.ts +++ b/test/aquarius/Aquarius.test.ts @@ -1,18 +1,18 @@ import * as assert from "assert" import Aquarius from "../../src/aquarius/Aquarius" -import ConfigProvider from "../../src/ConfigProvider" +import AquariusConnectorProvider from "../../src/aquarius/AquariusConnectorProvider" import config from "../config" +import AquariusConnectorMock from "../mocks/AquariusConnector.mock" + +before(() => { + AquariusConnectorProvider.setConnector(new AquariusConnectorMock()) +}) describe("Aquarius", () => { - before(() => { + describe("#queryMetadata()", async () => { - ConfigProvider.setConfig(config) - }) - - describe("#queryMetadata()queryMetadata", async () => { - - const aquarius: Aquarius = new Aquarius() + const aquarius: Aquarius = new Aquarius(config) const query = { offset: 100, diff --git a/test/mocks/AquariusConnector.mock.ts b/test/mocks/AquariusConnector.mock.ts new file mode 100644 index 0000000..5e0db38 --- /dev/null +++ b/test/mocks/AquariusConnector.mock.ts @@ -0,0 +1,17 @@ +import AquariusConnector from "../../src/aquarius/AquariusConnector" + +export default class AquariusConnectorMock extends AquariusConnector { + + public async post(url: string, payload: any) { + + return { + ok: true, + json: () => { + return [] + }, + text: () => { + return "" + }, + } + } +} diff --git a/test/ocean/Asset.test.ts b/test/ocean/Asset.test.ts index cf85365..1554a03 100644 --- a/test/ocean/Asset.test.ts +++ b/test/ocean/Asset.test.ts @@ -23,7 +23,7 @@ describe("Asset", () => { before(async () => { ConfigProvider.setConfig(config) - AquariusProvider.setAquarius(new AquariusMock()) + AquariusProvider.setAquarius(new AquariusMock(config)) await ContractHandler.deployContracts() ocean = await Ocean.getInstance(config) diff --git a/test/ocean/Ocean.test.ts b/test/ocean/Ocean.test.ts index 297e035..905a0ef 100644 --- a/test/ocean/Ocean.test.ts +++ b/test/ocean/Ocean.test.ts @@ -23,7 +23,7 @@ describe("Ocean", () => { before(async () => { ConfigProvider.setConfig(config) - AquariusProvider.setAquarius(new AquariusMock()) + AquariusProvider.setAquarius(new AquariusMock(config)) await ContractHandler.deployContracts() ocean = await Ocean.getInstance(config) accounts = await ocean.getAccounts() @@ -31,7 +31,7 @@ describe("Ocean", () => { testPublisher = accounts[0] testAsset = new Asset(name, description, price, testPublisher) }) - + describe("#getInstance()", () => { it("should list accounts", async () => { diff --git a/test/ocean/Order.test.ts b/test/ocean/Order.test.ts index 1f2ff09..262f6f3 100644 --- a/test/ocean/Order.test.ts +++ b/test/ocean/Order.test.ts @@ -26,7 +26,7 @@ describe("Order", () => { before(async () => { ConfigProvider.setConfig(config) - AquariusProvider.setAquarius(new AquariusMock()) + AquariusProvider.setAquarius(new AquariusMock(config)) await ContractHandler.deployContracts() ocean = await Ocean.getInstance(config) accounts = await ocean.getAccounts() From 8c4ba815890df1fa4e5a6becfbc9079d099da57f Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 26 Oct 2018 13:40:09 +0200 Subject: [PATCH 5/7] optimize test --- test/aquarius/Aquarius.test.ts | 35 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/test/aquarius/Aquarius.test.ts b/test/aquarius/Aquarius.test.ts index 9a4529e..d1caf6e 100644 --- a/test/aquarius/Aquarius.test.ts +++ b/test/aquarius/Aquarius.test.ts @@ -10,24 +10,27 @@ before(() => { describe("Aquarius", () => { - describe("#queryMetadata()", async () => { + describe("#queryMetadata()", () => { - const aquarius: Aquarius = new Aquarius(config) + it("should query metadata", async () => { - const query = { - offset: 100, - page: 0, - query: { - value: 1, - }, - sort: { - value: 1, - }, - text: "Office", - } + const aquarius: Aquarius = new Aquarius(config) + + const query = { + offset: 100, + page: 0, + query: { + value: 1, + }, + sort: { + value: 1, + }, + text: "Office", + } + + const result: any[] = await aquarius.queryMetadata(query) + assert(result) + }) - const result: any[] = await aquarius.queryMetadata(query) - assert(result) }) - }) From af376eb7ee208bf11bdcca57740c712a5af7267c Mon Sep 17 00:00:00 2001 From: Jernej Pregelj Date: Mon, 29 Oct 2018 16:38:23 +0100 Subject: [PATCH 6/7] changes in search paths & type --- src/aquarius/Aquarius.ts | 22 ++++++++++++++++++++-- src/aquarius/AquariusConnector.ts | 15 +++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/aquarius/Aquarius.ts b/src/aquarius/Aquarius.ts index bc213a4..2e14c4b 100644 --- a/src/aquarius/Aquarius.ts +++ b/src/aquarius/Aquarius.ts @@ -36,7 +36,7 @@ export default class Aquarius { public async queryMetadata(query): Promise { const result = await AquariusConnectorProvider.getConnector().post( - this.url + "/api/v1/aquarius/assets/metadata/query", + this.url + "/api/v1/aquarius/assets/ddo/query", JSON.stringify(query)) .then((response: any) => { if (response.ok) { @@ -45,7 +45,25 @@ export default class Aquarius { Logger.log("Failed: ", response.status, response.statusText) }) .catch((error) => { - Logger.error("Error fetching querying metdata: ", error) + Logger.error("Error fetching querying metadata: ", error) + }) + + return result + } + + public async queryMetadataByText(query): Promise { + + const result = await AquariusConnectorProvider.getConnector().get( + this.url + "/api/v1/aquarius/assets/ddo/query", + JSON.stringify(query)) + .then((response: any) => { + if (response.ok) { + return response.json() + } + Logger.log("Failed: ", response.status, response.statusText) + }) + .catch((error) => { + Logger.error("Error fetching querying metadata: ", error) }) return result diff --git a/src/aquarius/AquariusConnector.ts b/src/aquarius/AquariusConnector.ts index 247799d..e5dd021 100644 --- a/src/aquarius/AquariusConnector.ts +++ b/src/aquarius/AquariusConnector.ts @@ -1,4 +1,5 @@ import fetch from "node-fetch" +import URL from "url" export default class AquariusConnector { @@ -11,4 +12,18 @@ export default class AquariusConnector { }, }) } + + public get(url, payload) { + const fullUrl = new URL(url) + for (const key of Object.keys(payload)) { + fullUrl.searchParams.append(key, payload[key]) + } + return fetch(fullUrl, { + method: "GET", + body: null, + headers: { + "Content-type": "application/json", + }, + }) + } } From 4e52e10a4bfc71b0516ff00dbb15702311ba92bd Mon Sep 17 00:00:00 2001 From: Jernej Pregelj Date: Mon, 29 Oct 2018 16:55:32 +0100 Subject: [PATCH 7/7] url fix --- src/aquarius/AquariusConnector.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aquarius/AquariusConnector.ts b/src/aquarius/AquariusConnector.ts index e5dd021..243bd23 100644 --- a/src/aquarius/AquariusConnector.ts +++ b/src/aquarius/AquariusConnector.ts @@ -1,5 +1,5 @@ import fetch from "node-fetch" -import URL from "url" +import { URL } from "url" export default class AquariusConnector {