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))
|
.post(this.url + "/api/v1/aquarius/assets/ddo/query", JSON.stringify(query))
|
||||||
.then((response: any) => {
|
.then((response: any) => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return response.json()
|
return response.json() as DDO[]
|
||||||
}
|
}
|
||||||
Logger.error("queryMetadata failed:", response.status, response.statusText)
|
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) => {
|
.catch((error) => {
|
||||||
Logger.error("Error fetching querying metadata: ", error)
|
Logger.error("Error fetching querying metadata: ", error)
|
||||||
return []
|
return [] as DDO[]
|
||||||
})
|
})
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@ -70,17 +72,19 @@ export default class Aquarius {
|
|||||||
.get(fullUrl)
|
.get(fullUrl)
|
||||||
.then((response: any) => {
|
.then((response: any) => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return response.json()
|
return response.json() as DDO[]
|
||||||
}
|
}
|
||||||
Logger.log("queryMetadataByText failed:", response.status, response.statusText)
|
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) => {
|
.catch((error) => {
|
||||||
Logger.error("Error fetching querying metadata: ", error)
|
Logger.error("Error fetching querying metadata by text: ", error)
|
||||||
return []
|
return [] as DDO[]
|
||||||
})
|
})
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@ -92,13 +96,14 @@ export default class Aquarius {
|
|||||||
.post(fullUrl, DDO.serialize(ddo))
|
.post(fullUrl, DDO.serialize(ddo))
|
||||||
.then((response: any) => {
|
.then((response: any) => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return response.json()
|
return new DDO(response.json() as DDO)
|
||||||
}
|
}
|
||||||
Logger.error("storeDDO failed:", response.status, response.statusText)
|
Logger.error("storeDDO failed:", response.status, response.statusText)
|
||||||
return null
|
return null as DDO
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
Logger.error("Error fetching querying metadata: ", error)
|
Logger.error("Error fetching querying metadata: ", error)
|
||||||
|
return null as DDO
|
||||||
})
|
})
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@ -110,13 +115,14 @@ export default class Aquarius {
|
|||||||
.get(fullUrl)
|
.get(fullUrl)
|
||||||
.then((response: any) => {
|
.then((response: any) => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return response.json()
|
return new DDO(response.json() as DDO)
|
||||||
}
|
}
|
||||||
Logger.log("retrieveDDO failed:", response.status, response.statusText)
|
Logger.log("retrieveDDO failed:", response.status, response.statusText)
|
||||||
return null
|
return null as DDO
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
Logger.error("Error fetching querying metadata: ", error)
|
Logger.error("Error fetching querying metadata: ", error)
|
||||||
|
return null as DDO
|
||||||
})
|
})
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -6,15 +6,12 @@ import DDO from "../../src/ddo/DDO"
|
|||||||
import IdGenerator from "../../src/ocean/IdGenerator"
|
import IdGenerator from "../../src/ocean/IdGenerator"
|
||||||
import config from "../config"
|
import config from "../config"
|
||||||
import AquariusConnectorMock from "../mocks/AquariusConnector.mock"
|
import AquariusConnectorMock from "../mocks/AquariusConnector.mock"
|
||||||
// import * as jsonDDO from "../testdata/ddo.json"
|
|
||||||
|
|
||||||
describe("Aquarius", () => {
|
describe("Aquarius", () => {
|
||||||
|
|
||||||
const aquarius: Aquarius = new Aquarius(config)
|
const aquarius: Aquarius = new Aquarius(config)
|
||||||
describe("#queryMetadata()", () => {
|
describe("#queryMetadata()", () => {
|
||||||
|
|
||||||
it("should query metadata", async () => {
|
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
offset: 100,
|
offset: 100,
|
||||||
page: 0,
|
page: 0,
|
||||||
@ -27,20 +24,29 @@ describe("Aquarius", () => {
|
|||||||
text: "Office",
|
text: "Office",
|
||||||
} as SearchQuery
|
} as SearchQuery
|
||||||
|
|
||||||
// @ts-ignore
|
it("should query metadata", async () => {
|
||||||
AquariusConnectorProvider.setConnector(new AquariusConnectorMock())
|
|
||||||
|
|
||||||
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)
|
||||||
assert(result.length !== null)
|
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()", () => {
|
describe("#queryMetadataByText()", () => {
|
||||||
|
|
||||||
it("should query metadata by text", async () => {
|
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
offset: 100,
|
offset: 100,
|
||||||
page: 0,
|
page: 0,
|
||||||
@ -53,14 +59,26 @@ describe("Aquarius", () => {
|
|||||||
text: "Office",
|
text: "Office",
|
||||||
} as SearchQuery
|
} as SearchQuery
|
||||||
|
|
||||||
// @ts-ignore
|
it("should query metadata by text", async () => {
|
||||||
AquariusConnectorProvider.setConnector(new AquariusConnectorMock())
|
|
||||||
|
|
||||||
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)
|
||||||
assert(result.length !== null)
|
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()", () => {
|
describe("#storeDDO()", () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user