1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00
ocean.js/test/integration/MetadataCache.test.ts
Alex Coseru 3bea2aaf90
Bump aqua queries
* remove aqua queries

* remove transformResult

* fix metadatacache test

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* remove unused

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* more commits

* move metadatacache to integration

* fix

* fix lint

* great improve an integration tests speed

* force aqua 3.1 on barge

* small typo fix

* fix ci

* fix import instead of require

* add ocean.assets.query

* Update ci.yml

Co-authored-by: mihaisc <mihai.scarlat@smartcontrol.ro>
2021-09-24 11:55:28 +03:00

63 lines
1.9 KiB
TypeScript

import { assert, spy, use } from 'chai'
import spies from 'chai-spies'
import { Ocean } from '../../src/ocean/Ocean'
import { MetadataCache, SearchQuery } from '../../src/metadatacache/MetadataCache'
import { DDO } from '../../src/ddo/DDO'
import { ConfigHelper } from '../../src/utils/ConfigHelper'
import { LoggerInstance } from '../../src/utils'
use(spies)
describe('MetadataCache', () => {
let ocean: Ocean
let metadataCache: MetadataCache
beforeEach(async () => {
const config = new ConfigHelper().getConfig('development')
ocean = await Ocean.getInstance(config)
metadataCache = ocean.metadataCache // eslint-disable-line prefer-destructuring
})
afterEach(() => {
spy.restore()
})
describe('#queryMetadata()', () => {
const query = {
from: 0,
size: 21,
query: {
query_string: {
query: 'Office'
}
},
sort: {
created: 'asc'
}
} as SearchQuery
it('should query metadata', async () => {
const result = await metadataCache.queryMetadata(query)
assert.typeOf(result.hits.hits, 'array')
assert.isAtLeast(result.hits.hits.length, 1)
})
it('should query metadata with a new instance', async () => {
const config = new ConfigHelper().getConfig('development')
const metadatastoreNew = new MetadataCache(config.metadataCacheUri, LoggerInstance)
const result = await metadatastoreNew.queryMetadata(query)
assert.typeOf(result.hits.hits, 'array')
assert.isAtLeast(result.hits.hits.length, 1)
})
it('should query metadata and return real ddo', async () => {
const result = await metadataCache.queryMetadata(query)
assert.typeOf(result.hits.hits, 'array')
assert.isAtLeast(result.hits.hits.length, 1)
const ddo = DDO.deserialize(JSON.stringify(result.hits.hits[0]))
assert.isDefined(ddo.findServiceById)
})
})
})