From 3d326a52d1145bbc39e52f05cdc6ea5ccf5361ff Mon Sep 17 00:00:00 2001 From: enrique Date: Tue, 27 Aug 2024 14:01:50 +0200 Subject: [PATCH] fix: tests --- integration/nevermined/SearchAsset.test.ts | 13 ++++++++++++- src/nevermined/api/SearchApi.ts | 22 +++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/integration/nevermined/SearchAsset.test.ts b/integration/nevermined/SearchAsset.test.ts index cf05c21b3..d99c5d01d 100644 --- a/integration/nevermined/SearchAsset.test.ts +++ b/integration/nevermined/SearchAsset.test.ts @@ -108,7 +108,18 @@ describe('Search Asset', () => { it('should be able to get assets by type', async () => { const { results: ddos } = await neverminedOffline.search.byType('dataset') + assert.equal(ddos.length, 5) - assert.equal(ddos.length, 4) + const { results: ddosWithTextFilter } = await neverminedOffline.search.byType( + 'dataset', + 'TestAsset', + ) + assert.equal(ddosWithTextFilter.length, 4) + + const { results: ddosServices } = await neverminedOffline.search.byType('service') + assert.equal(ddosServices.length, 2) + + const { results: agent } = await neverminedOffline.search.byType('agent') + assert.equal(agent.length, 0) }) }) diff --git a/src/nevermined/api/SearchApi.ts b/src/nevermined/api/SearchApi.ts index 3b8c57f52..8aa7fbe89 100644 --- a/src/nevermined/api/SearchApi.ts +++ b/src/nevermined/api/SearchApi.ts @@ -788,9 +788,19 @@ export class SearchApi extends Instantiable { ) } - public async byType(assetType: MetaDataMain['type'] = 'agent', offset = 100, page = 1) { + public async byType( + assetType: MetaDataMain['type'] = 'agent', + text?: string, + offset = 100, + page = 1, + appId?: string, + ) { const mustArray: unknown[] = [] mustArray.push(assetTypeFilter(assetType)) + if (text) { + mustArray.push(textFilter(text)) + } + return this.query({ query: { bool: { @@ -802,6 +812,7 @@ export class SearchApi extends Instantiable { }, page: page, offset: offset, + appId, }) } } @@ -834,3 +845,12 @@ export const assetTypeFilter = (assetType: MetaDataMain['type']) => { }, } } + +export const textFilter = (searchInputText = '') => ({ + nested: { + path: ['service'], + query: { + query_string: { query: `*${searchInputText}*`, fields: ['service.attributes.main.name'] }, + }, + }, +})