fix: clean up filter merging logic and add combined filter+query test

- Replace incorrect Object.keys-on-array guard with direct filter
  conversion, matching the pattern used in getEntityFacetsByPredicate
- Add backend router test covering combined filter query param + body
  query predicate being forwarded independently to entitiesBatch

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2026-02-26 21:59:36 +01:00
parent ec411a01ae
commit 3880820c62
2 changed files with 33 additions and 5 deletions
+2 -5
View File
@@ -249,11 +249,8 @@ export class CatalogClient implements CatalogApi {
}
filterPredicate = query;
if (filter !== undefined) {
const filterValue = this.getFilterValue(filter);
if (filterValue && Object.keys(filterValue).length > 0) {
const converted = convertFilterToPredicate(filter);
filterPredicate = { $all: [filterPredicate, converted] };
}
const converted = convertFilterToPredicate(filter);
filterPredicate = { $all: [filterPredicate, converted] };
}
}
@@ -759,6 +759,37 @@ describe('createRouter readonly disabled', () => {
expect(response.body).toEqual({ items: [entity] });
});
it('forwards both filter query param and body query predicate independently', async () => {
const entity: Entity = {
apiVersion: 'a',
kind: 'component',
metadata: {
name: 'a',
},
};
const entityRef = stringifyEntityRef(entity);
entitiesCatalog.entitiesBatch.mockResolvedValue({
items: { type: 'object', entities: [entity] },
});
const response = await request(app)
.post('/entities/by-refs?filter=kind=Component')
.set('Content-Type', 'application/json')
.send(
JSON.stringify({
entityRefs: [entityRef],
query: { 'metadata.namespace': 'default' },
}),
);
expect(entitiesCatalog.entitiesBatch).toHaveBeenCalledWith({
entityRefs: [entityRef],
fields: undefined,
credentials: mockCredentials.user(),
filter: { key: 'kind', values: ['Component'] },
query: { 'metadata.namespace': 'default' },
});
expect(response.status).toEqual(200);
});
it('rejects invalid query predicate', async () => {
const response = await request(app)
.post('/entities/by-refs')