Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eruizgar91 committed Aug 27, 2024
1 parent a892c93 commit 3d326a5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
13 changes: 12 additions & 1 deletion integration/nevermined/SearchAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
22 changes: 21 additions & 1 deletion src/nevermined/api/SearchApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -802,6 +812,7 @@ export class SearchApi extends Instantiable {
},
page: page,
offset: offset,
appId,
})
}
}
Expand Down Expand Up @@ -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'] },
},
},
})

0 comments on commit 3d326a5

Please sign in to comment.