diff --git a/plugins/catalog-backend/src/search/util.test.ts b/plugins/catalog-backend/src/search/util.test.ts index 0444dc2209..d2d1776338 100644 --- a/plugins/catalog-backend/src/search/util.test.ts +++ b/plugins/catalog-backend/src/search/util.test.ts @@ -14,7 +14,11 @@ * limitations under the License. */ -import { ComponentEntity, UserEntity } from '@backstage/catalog-model'; +import { + ComponentEntity, + GroupEntity, + UserEntity, +} from '@backstage/catalog-model'; import { getDocumentText } from './util'; describe('getDocumentText', () => { @@ -61,8 +65,55 @@ describe('getDocumentText', () => { expect(actual).toEqual(''); }); }); + + describe('kind is Group', () => { + test('contains display name if set', () => { + const entity = createGroup(); + const actual = getDocumentText(entity); + expect(actual).toContain(entity.spec.profile?.displayName); + }); + + test('contains description if set', () => { + const entity = createGroup(); + const actual = getDocumentText(entity); + expect(actual).toContain(entity.metadata.description); + }); + + test('contains both description and display name if both are set', () => { + const entity = createGroup(); + const actual = getDocumentText(entity); + expect(actual).toContain(entity.spec.profile?.displayName); + expect(actual).toContain(entity.metadata.description); + }); + + test('is empty if description and display name are not set', () => { + const entity = createGroup(); + delete entity.metadata.description; + delete entity.spec.profile?.displayName; + const actual = getDocumentText(entity); + expect(actual).toEqual(''); + }); + }); }); +function createGroup(): GroupEntity { + return { + apiVersion: 'backstage.io/v1alpha1', + kind: 'Group', + metadata: { + name: 'group-1', + description: 'The expected description', + }, + spec: { + type: 'team', + profile: { + displayName: 'Group 1', + }, + children: [], + }, + }; +} + function createUser(): UserEntity { return { apiVersion: 'backstage.io/v1alpha1', diff --git a/plugins/catalog-backend/src/search/util.ts b/plugins/catalog-backend/src/search/util.ts index 4e6bb8aea0..47a5570899 100644 --- a/plugins/catalog-backend/src/search/util.ts +++ b/plugins/catalog-backend/src/search/util.ts @@ -20,9 +20,13 @@ function isUserEntity(entity: Entity): entity is UserEntity { return entity.kind.toLocaleUpperCase('en-US') === 'USER'; } +function isGroupEntity(entity: Entity): entity is UserEntity { + return entity.kind.toLocaleUpperCase('en-US') === 'GROUP'; +} + export function getDocumentText(entity: Entity): string { let documentText = entity.metadata.description || ''; - if (isUserEntity(entity)) { + if (isUserEntity(entity) || isGroupEntity(entity)) { if (entity.spec?.profile?.displayName && documentText) { // combine displayName and description const displayName = entity.spec.profile.displayName;