Merge pull request #8203 from backstage/joonp/entity-filter-empty-values

Handle empty values array in EntityFilter
This commit is contained in:
Fredrik Adelöw
2021-11-24 15:49:10 +01:00
committed by GitHub
3 changed files with 38 additions and 1 deletions
@@ -435,5 +435,37 @@ describe('NextEntitiesCatalog', () => {
expect(entities).toContainEqual(entity1);
},
);
it.each(databases.eachSupportedId())(
'should return no matches for an empty values array',
// NOTE: An empty values array is not a sensible input in a realistic scenario.
async databaseId => {
const { knex } = await createDatabase(databaseId);
const entity1: Entity = {
apiVersion: 'a',
kind: 'k',
metadata: { name: 'one' },
spec: {},
};
const entity2: Entity = {
apiVersion: 'a',
kind: 'k',
metadata: { name: 'two' },
spec: {},
};
await addEntityToSearch(knex, entity1);
await addEntityToSearch(knex, entity2);
const catalog = new NextEntitiesCatalog(knex);
const testFilter = {
key: 'kind',
values: [],
};
const request = { filter: testFilter };
const { entities } = await catalog.entities(request);
expect(entities.length).toBe(0);
},
);
});
});
@@ -91,7 +91,7 @@ function addCondition(
if (filter.values) {
if (filter.values.length === 1) {
this.where({ value: filter.values[0].toLowerCase() });
} else if (filter.values.length > 1) {
} else {
this.andWhere(
'value',
'in',