mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
refactor & enhance tests
This commit is contained in:
parent
8bfa7ba593
commit
b76577bda5
@ -274,16 +274,7 @@ export class Aquarius {
|
|||||||
if (newMetadata.title != null) data.title = newMetadata.title
|
if (newMetadata.title != null) data.title = newMetadata.title
|
||||||
if (newMetadata.servicePrices != null)
|
if (newMetadata.servicePrices != null)
|
||||||
data.servicePrices = newMetadata.servicePrices
|
data.servicePrices = newMetadata.servicePrices
|
||||||
if (newMetadata.links != null) {
|
if (newMetadata.links != null) data.links = newMetadata.links
|
||||||
data.links = []
|
|
||||||
for (const [name, url] of Object.entries(newMetadata.links)) {
|
|
||||||
const asample = Object()
|
|
||||||
asample.name = name
|
|
||||||
asample.url = url
|
|
||||||
asample.type = 'sample'
|
|
||||||
data.links.push(asample)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data.updated = updated
|
data.updated = updated
|
||||||
data.signature = signature
|
data.signature = signature
|
||||||
const result = await this.fetch
|
const result = await this.fetch
|
||||||
@ -293,7 +284,7 @@ export class Aquarius {
|
|||||||
return response.text
|
return response.text
|
||||||
}
|
}
|
||||||
this.logger.log(
|
this.logger.log(
|
||||||
'transferownership failed:',
|
'editMetaData failed:',
|
||||||
response.status,
|
response.status,
|
||||||
response.statusText
|
response.statusText
|
||||||
)
|
)
|
||||||
@ -327,11 +318,7 @@ export class Aquarius {
|
|||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return response.text
|
return response.text
|
||||||
}
|
}
|
||||||
this.logger.log(
|
this.logger.log('retire failed:', response.status, response.statusText)
|
||||||
'transferownership failed:',
|
|
||||||
response.status,
|
|
||||||
response.statusText
|
|
||||||
)
|
|
||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -282,9 +282,15 @@ export interface ServicePrices {
|
|||||||
price: string
|
price: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface EditableMetaDataLinks {
|
||||||
|
name: string
|
||||||
|
url: string
|
||||||
|
type: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface EditableMetaData {
|
export interface EditableMetaData {
|
||||||
description?: string
|
description?: string
|
||||||
title?: string
|
title?: string
|
||||||
links?: { [name: string]: string }[]
|
links?: EditableMetaDataLinks[]
|
||||||
servicePrices?: ServicePrices[]
|
servicePrices?: ServicePrices[]
|
||||||
}
|
}
|
||||||
|
@ -114,8 +114,35 @@ describe('Asset Owners', () => {
|
|||||||
|
|
||||||
it('should be able to update metadata', async () => {
|
it('should be able to update metadata', async () => {
|
||||||
const { id } = await ocean.assets.create(metadata as any, account1)
|
const { id } = await ocean.assets.create(metadata as any, account1)
|
||||||
|
const links = [
|
||||||
|
{
|
||||||
|
name: 'Sample1',
|
||||||
|
url: 'http://www.example.com',
|
||||||
|
type: 'sample'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Sample2',
|
||||||
|
url: 'http://www.example.net',
|
||||||
|
type: 'sample'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
const newPrices = [
|
||||||
|
{
|
||||||
|
serviceIndex: 0,
|
||||||
|
price: '31000000000000000000'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
serviceIndex: 2,
|
||||||
|
price: '31000000000000000000'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
const newMetaData = { title: 'New title', description: 'New description' }
|
const newMetaData = {
|
||||||
|
title: 'New title',
|
||||||
|
description: 'New description',
|
||||||
|
links: links,
|
||||||
|
servicePrices: newPrices
|
||||||
|
}
|
||||||
await ocean.assets.editMetadata(id, newMetaData, account1)
|
await ocean.assets.editMetadata(id, newMetaData, account1)
|
||||||
|
|
||||||
const newDDO = await ocean.assets.resolve(id)
|
const newDDO = await ocean.assets.resolve(id)
|
||||||
@ -125,6 +152,24 @@ describe('Asset Owners', () => {
|
|||||||
newDDO.service[0].attributes.additionalInformation.description,
|
newDDO.service[0].attributes.additionalInformation.description,
|
||||||
'New description'
|
'New description'
|
||||||
)
|
)
|
||||||
|
assert.equal(newDDO.service[0].attributes.main.price, '31000000000000000000')
|
||||||
|
assert.equal(newDDO.service[2].attributes.main.price, '31000000000000000000')
|
||||||
|
assert.equal(
|
||||||
|
newDDO.service[0].attributes.additionalInformation.links[0].name,
|
||||||
|
'Sample1'
|
||||||
|
)
|
||||||
|
assert.equal(
|
||||||
|
newDDO.service[0].attributes.additionalInformation.links[0].url,
|
||||||
|
'http://www.example.com'
|
||||||
|
)
|
||||||
|
assert.equal(
|
||||||
|
newDDO.service[0].attributes.additionalInformation.links[1].name,
|
||||||
|
'Sample2'
|
||||||
|
)
|
||||||
|
assert.equal(
|
||||||
|
newDDO.service[0].attributes.additionalInformation.links[1].url,
|
||||||
|
'http://www.example.net'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should be able to retire metadata', async () => {
|
it('should be able to retire metadata', async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user