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((res: string) => {
|
.then((ddos) => {
|
||||||
return JSON.parse(res) as DDO[]
|
return ddos.map((ddo): DDO => {
|
||||||
|
return new DDO(ddo 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((res: string) => {
|
.then((ddos) => {
|
||||||
return JSON.parse(res) as DDO[]
|
return ddos.map((ddo): DDO => {
|
||||||
|
return new DDO(ddo 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,61 +6,79 @@ 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()", () => {
|
||||||
|
|
||||||
|
const query = {
|
||||||
|
offset: 100,
|
||||||
|
page: 0,
|
||||||
|
query: {
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
sort: {
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
text: "Office",
|
||||||
|
} as SearchQuery
|
||||||
|
|
||||||
it("should query metadata", async () => {
|
it("should query metadata", async () => {
|
||||||
|
|
||||||
const query = {
|
|
||||||
offset: 100,
|
|
||||||
page: 0,
|
|
||||||
query: {
|
|
||||||
value: 1,
|
|
||||||
},
|
|
||||||
sort: {
|
|
||||||
value: 1,
|
|
||||||
},
|
|
||||||
text: "Office",
|
|
||||||
} as SearchQuery
|
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
AquariusConnectorProvider.setConnector(new AquariusConnectorMock())
|
AquariusConnectorProvider.setConnector(new AquariusConnectorMock([new DDO()]))
|
||||||
|
|
||||||
const result: any[] = await aquarius.queryMetadata(query)
|
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()", () => {
|
||||||
|
|
||||||
|
const query = {
|
||||||
|
offset: 100,
|
||||||
|
page: 0,
|
||||||
|
query: {
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
sort: {
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
text: "Office",
|
||||||
|
} as SearchQuery
|
||||||
|
|
||||||
it("should query metadata by text", async () => {
|
it("should query metadata by text", async () => {
|
||||||
|
|
||||||
const query = {
|
|
||||||
offset: 100,
|
|
||||||
page: 0,
|
|
||||||
query: {
|
|
||||||
value: 1,
|
|
||||||
},
|
|
||||||
sort: {
|
|
||||||
value: 1,
|
|
||||||
},
|
|
||||||
text: "Office",
|
|
||||||
} as SearchQuery
|
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
AquariusConnectorProvider.setConnector(new AquariusConnectorMock())
|
AquariusConnectorProvider.setConnector(new AquariusConnectorMock([new DDO()]))
|
||||||
|
|
||||||
const result: any[] = await aquarius.queryMetadataByText(query)
|
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