chore(catalog-model): use isNonEmptyString for icon validation

Signed-off-by: Benjamin Janssens <benji.janssens@gmail.com>
This commit is contained in:
Benjamin Janssens
2025-05-16 13:55:35 +02:00
parent aeb70a02e2
commit fb48a5a9d3
2 changed files with 4 additions and 6 deletions
@@ -197,7 +197,7 @@ describe('FieldFormatEntityPolicy', () => {
},
);
it.each([[123], [{}], [[]], ['abc xyz']])(
it.each([[123], [{}], [[]]])(
'rejects bad link icon value %s',
async (icon: unknown) => {
data.metadata.links = [{ url: 'http://foo', icon }];
@@ -208,10 +208,8 @@ describe('FieldFormatEntityPolicy', () => {
it('rejects a single bad link icon value', async () => {
data.metadata.links = [
{ url: 'http://foo', icon: 'good' },
{ url: 'http://foo', icon: 'not good' },
{ url: 'http://foo', icon: 123 },
];
await expect(policy.enforce(data)).rejects.toThrow(
/links.1.icon.*"not good"/i,
);
await expect(policy.enforce(data)).rejects.toThrow(/links.1.icon.*"123"/i);
});
});
@@ -161,7 +161,7 @@ export class FieldFormatEntityPolicy implements EntityPolicy {
optional(
`links.${i}.icon`,
links[i]?.icon,
KubernetesValidatorFunctions.isValidObjectName,
CommonValidatorFunctions.isNonEmptyString,
);
}