Skip to content

Commit 3d326a5

Browse files
committed
fix: tests
1 parent a892c93 commit 3d326a5

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

integration/nevermined/SearchAsset.test.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,18 @@ describe('Search Asset', () => {
108108

109109
it('should be able to get assets by type', async () => {
110110
const { results: ddos } = await neverminedOffline.search.byType('dataset')
111+
assert.equal(ddos.length, 5)
111112

112-
assert.equal(ddos.length, 4)
113+
const { results: ddosWithTextFilter } = await neverminedOffline.search.byType(
114+
'dataset',
115+
'TestAsset',
116+
)
117+
assert.equal(ddosWithTextFilter.length, 4)
118+
119+
const { results: ddosServices } = await neverminedOffline.search.byType('service')
120+
assert.equal(ddosServices.length, 2)
121+
122+
const { results: agent } = await neverminedOffline.search.byType('agent')
123+
assert.equal(agent.length, 0)
113124
})
114125
})

src/nevermined/api/SearchApi.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -788,9 +788,19 @@ export class SearchApi extends Instantiable {
788788
)
789789
}
790790

791-
public async byType(assetType: MetaDataMain['type'] = 'agent', offset = 100, page = 1) {
791+
public async byType(
792+
assetType: MetaDataMain['type'] = 'agent',
793+
text?: string,
794+
offset = 100,
795+
page = 1,
796+
appId?: string,
797+
) {
792798
const mustArray: unknown[] = []
793799
mustArray.push(assetTypeFilter(assetType))
800+
if (text) {
801+
mustArray.push(textFilter(text))
802+
}
803+
794804
return this.query({
795805
query: {
796806
bool: {
@@ -802,6 +812,7 @@ export class SearchApi extends Instantiable {
802812
},
803813
page: page,
804814
offset: offset,
815+
appId,
805816
})
806817
}
807818
}
@@ -834,3 +845,12 @@ export const assetTypeFilter = (assetType: MetaDataMain['type']) => {
834845
},
835846
}
836847
}
848+
849+
export const textFilter = (searchInputText = '') => ({
850+
nested: {
851+
path: ['service'],
852+
query: {
853+
query_string: { query: `*${searchInputText}*`, fields: ['service.attributes.main.name'] },
854+
},
855+
},
856+
})

0 commit comments

Comments
 (0)