mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
fixed re-decode of json response from aquarius
This commit is contained in:
parent
3c7ce8b124
commit
7e6c431d85
@ -43,17 +43,19 @@ export default class Aquarius {
|
||||
.post(this.url + "/api/v1/aquarius/assets/ddo/query", JSON.stringify(query))
|
||||
.then((response: any) => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
return response.json() as DDO[]
|
||||
}
|
||||
Logger.error("queryMetadata failed:", response.status, response.statusText)
|
||||
return []
|
||||
return [] as DDO[]
|
||||
})
|
||||
.then((ddos) => {
|
||||
return ddos.map((ddo): DDO => {
|
||||
return new DDO(ddo as DDO)
|
||||
})
|
||||
.then((res: string) => {
|
||||
return JSON.parse(res) as DDO[]
|
||||
})
|
||||
.catch((error) => {
|
||||
Logger.error("Error fetching querying metadata: ", error)
|
||||
return []
|
||||
return [] as DDO[]
|
||||
})
|
||||
|
||||
return result
|
||||
@ -70,17 +72,19 @@ export default class Aquarius {
|
||||
.get(fullUrl)
|
||||
.then((response: any) => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
return response.json() as DDO[]
|
||||
}
|
||||
Logger.log("queryMetadataByText failed:", response.status, response.statusText)
|
||||
return []
|
||||
return [] as DDO[]
|
||||
})
|
||||
.then((ddos) => {
|
||||
return ddos.map((ddo): DDO => {
|
||||
return new DDO(ddo as DDO)
|
||||
})
|
||||
.then((res: string) => {
|
||||
return JSON.parse(res) as DDO[]
|
||||
})
|
||||
.catch((error) => {
|
||||
Logger.error("Error fetching querying metadata: ", error)
|
||||
return []
|
||||
Logger.error("Error fetching querying metadata by text: ", error)
|
||||
return [] as DDO[]
|
||||
})
|
||||
|
||||
return result
|
||||
@ -92,13 +96,14 @@ export default class Aquarius {
|
||||
.post(fullUrl, DDO.serialize(ddo))
|
||||
.then((response: any) => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
return new DDO(response.json() as DDO)
|
||||
}
|
||||
Logger.error("storeDDO failed:", response.status, response.statusText)
|
||||
return null
|
||||
return null as DDO
|
||||
})
|
||||
.catch((error) => {
|
||||
Logger.error("Error fetching querying metadata: ", error)
|
||||
return null as DDO
|
||||
})
|
||||
|
||||
return result
|
||||
@ -110,13 +115,14 @@ export default class Aquarius {
|
||||
.get(fullUrl)
|
||||
.then((response: any) => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
return new DDO(response.json() as DDO)
|
||||
}
|
||||
Logger.log("retrieveDDO failed:", response.status, response.statusText)
|
||||
return null
|
||||
return null as DDO
|
||||
})
|
||||
.catch((error) => {
|
||||
Logger.error("Error fetching querying metadata: ", error)
|
||||
return null as DDO
|
||||
})
|
||||
|
||||
return result
|
||||
|
@ -6,15 +6,12 @@ import DDO from "../../src/ddo/DDO"
|
||||
import IdGenerator from "../../src/ocean/IdGenerator"
|
||||
import config from "../config"
|
||||
import AquariusConnectorMock from "../mocks/AquariusConnector.mock"
|
||||
// import * as jsonDDO from "../testdata/ddo.json"
|
||||
|
||||
describe("Aquarius", () => {
|
||||
|
||||
const aquarius: Aquarius = new Aquarius(config)
|
||||
describe("#queryMetadata()", () => {
|
||||
|
||||
it("should query metadata", async () => {
|
||||
|
||||
const query = {
|
||||
offset: 100,
|
||||
page: 0,
|
||||
@ -27,20 +24,29 @@ describe("Aquarius", () => {
|
||||
text: "Office",
|
||||
} as SearchQuery
|
||||
|
||||
// @ts-ignore
|
||||
AquariusConnectorProvider.setConnector(new AquariusConnectorMock())
|
||||
it("should query metadata", async () => {
|
||||
|
||||
const result: any[] = await aquarius.queryMetadata(query)
|
||||
// @ts-ignore
|
||||
AquariusConnectorProvider.setConnector(new AquariusConnectorMock([new DDO()]))
|
||||
|
||||
const result: DDO[] = await aquarius.queryMetadata(query)
|
||||
assert(result)
|
||||
assert(result.length !== null)
|
||||
})
|
||||
|
||||
it("should query metadata and return real ddo", async () => {
|
||||
|
||||
// @ts-ignore
|
||||
AquariusConnectorProvider.setConnector(new AquariusConnectorMock([new DDO()]))
|
||||
|
||||
const result: DDO[] = await aquarius.queryMetadata(query)
|
||||
assert(result)
|
||||
assert(result[0].findServiceById)
|
||||
})
|
||||
})
|
||||
|
||||
describe("#queryMetadataByText()", () => {
|
||||
|
||||
it("should query metadata by text", async () => {
|
||||
|
||||
const query = {
|
||||
offset: 100,
|
||||
page: 0,
|
||||
@ -53,14 +59,26 @@ describe("Aquarius", () => {
|
||||
text: "Office",
|
||||
} as SearchQuery
|
||||
|
||||
// @ts-ignore
|
||||
AquariusConnectorProvider.setConnector(new AquariusConnectorMock())
|
||||
it("should query metadata by text", async () => {
|
||||
|
||||
const result: any[] = await aquarius.queryMetadataByText(query)
|
||||
// @ts-ignore
|
||||
AquariusConnectorProvider.setConnector(new AquariusConnectorMock([new DDO()]))
|
||||
|
||||
const result: DDO[] = await aquarius.queryMetadataByText(query)
|
||||
assert(result)
|
||||
assert(result.length !== null)
|
||||
})
|
||||
|
||||
it("should query metadata and return real ddo", async () => {
|
||||
|
||||
// @ts-ignore
|
||||
AquariusConnectorProvider.setConnector(new AquariusConnectorMock([new DDO()]))
|
||||
|
||||
const result: DDO[] = await aquarius.queryMetadataByText(query)
|
||||
assert(result)
|
||||
assert(result[0].findServiceById)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe("#storeDDO()", () => {
|
||||
|
Loading…
Reference in New Issue
Block a user