1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00
squid-js/test/integration/ocean/SearchAsset.test.ts

107 lines
3.1 KiB
TypeScript
Raw Normal View History

2019-06-20 00:20:09 +02:00
import { assert } from 'chai'
2019-02-12 15:07:10 +01:00
2019-06-20 00:20:09 +02:00
import { config } from '../config'
2019-02-12 15:07:10 +01:00
2019-06-20 00:20:09 +02:00
import { generateMetadata } from '../utils'
2019-03-15 15:23:28 +01:00
2020-01-30 22:08:18 +01:00
import { Ocean, Account, DDO } from '../../../src' // @oceanprotocol/squid
2019-02-12 15:07:10 +01:00
2019-06-20 00:20:09 +02:00
describe('Search Asset', () => {
2019-02-12 15:07:10 +01:00
let ocean: Ocean
let publisher: Account
const testHash = Math.random().toString(36).substr(2)
let price
2019-11-15 00:00:10 +01:00
const metadataGenerator = (name: string) =>
generateMetadata(`${name}${testHash}`, price)
2019-02-12 15:07:10 +01:00
let test1length
let test2length
let test3length
before(async () => {
ocean = await Ocean.getInstance(config)
// Accounts
2019-06-24 13:06:38 +02:00
;[publisher] = await ocean.accounts.list()
2019-02-12 15:07:10 +01:00
})
2019-06-20 00:20:09 +02:00
it('should be able to search the assets', async () => {
const { results: ddos } = await ocean.assets.search(`Test1${testHash}`)
2019-02-12 15:07:10 +01:00
2019-06-20 00:20:09 +02:00
assert.isArray(ddos, 'A search should return an array')
2019-02-12 15:07:10 +01:00
test1length = ddos.length
2019-09-09 12:18:54 +02:00
test2length = (await ocean.assets.search(`Test2${testHash}`)).results.length
test3length = (await ocean.assets.search(`Test3${testHash}`)).results.length
if (!ocean.keeper.dispenser) {
price = 0
}
2019-02-12 15:07:10 +01:00
})
2019-08-15 13:23:56 +02:00
it('should register an asset', async () => {
2019-11-15 00:00:10 +01:00
assert.instanceOf(
await ocean.assets.create(metadataGenerator('Test1') as any, publisher),
DDO
)
assert.instanceOf(
await ocean.assets.create(metadataGenerator('Test2') as any, publisher),
DDO
)
assert.instanceOf(
await ocean.assets.create(metadataGenerator('Test2') as any, publisher),
DDO
)
assert.instanceOf(
await ocean.assets.create(metadataGenerator('Test3') as any, publisher),
DDO
)
2019-02-12 15:07:10 +01:00
})
2019-06-20 00:20:09 +02:00
it('should search by text and see the increment of DDOs', async () => {
2019-04-05 12:20:42 +02:00
assert.equal(
2019-09-09 12:18:54 +02:00
(await ocean.assets.search(`Test2${testHash}`)).results.length - test2length,
2019-04-05 12:20:42 +02:00
2,
2019-06-20 00:20:09 +02:00
'Something was wrong searching the assets'
2019-04-05 12:20:42 +02:00
)
assert.equal(
2019-09-09 12:18:54 +02:00
(await ocean.assets.search(`Test3${testHash}`)).results.length - test3length,
2019-04-05 12:20:42 +02:00
1,
2019-06-20 00:20:09 +02:00
'Something was wrong searching the assets'
2019-04-05 12:20:42 +02:00
)
2019-02-12 15:07:10 +01:00
})
2019-06-20 00:20:09 +02:00
it('should return a list of DDOs', async () => {
const { results: ddos } = await ocean.assets.search(`Test1${testHash}`)
2019-02-12 15:07:10 +01:00
2019-11-15 00:00:10 +01:00
assert.equal(
ddos.length - test1length,
1,
'Something was wrong searching the assets'
)
ddos.map((ddo) =>
2019-11-15 00:00:10 +01:00
assert.instanceOf(ddo, DDO, 'The DDO is not an instance of a DDO')
)
2019-02-12 15:07:10 +01:00
})
2019-06-20 00:20:09 +02:00
it('should be able to do a query to get a list of DDOs', async () => {
const { results: ddos } = await ocean.assets.query({
2019-04-16 19:01:11 +02:00
page: 1,
2019-02-12 15:07:10 +01:00
offset: 1,
query: {
2019-06-20 00:20:09 +02:00
text: [`Test2${testHash}`]
2019-02-12 15:07:10 +01:00
},
sort: {
2019-06-20 00:20:09 +02:00
text: 1
}
2019-02-12 15:07:10 +01:00
})
2019-06-20 00:20:09 +02:00
assert.equal(ddos.length, 1, 'Something was wrong searching the assets')
ddos.map((ddo) =>
2019-11-15 00:00:10 +01:00
assert.instanceOf(ddo, DDO, 'The DDO is not an instance of a DDO')
)
2019-02-12 15:07:10 +01:00
})
})