diff --git a/.changeset/weak-monkeys-occur.md b/.changeset/weak-monkeys-occur.md new file mode 100644 index 0000000000..8025e10af5 --- /dev/null +++ b/.changeset/weak-monkeys-occur.md @@ -0,0 +1,6 @@ +--- +'@backstage/catalog-client': minor +'@backstage/plugin-catalog-node': minor +--- + +Add catalog service mocks under the `/testUtils` subpath export. diff --git a/packages/catalog-client/api-report-testUtils.md b/packages/catalog-client/api-report-testUtils.md index a33470e35d..47e917450c 100644 --- a/packages/catalog-client/api-report-testUtils.md +++ b/packages/catalog-client/api-report-testUtils.md @@ -21,7 +21,7 @@ import { QueryEntitiesRequest } from '@backstage/catalog-client'; import { QueryEntitiesResponse } from '@backstage/catalog-client'; import { ValidateEntityResponse } from '@backstage/catalog-client'; -// @public (undocumented) +// @public export class InMemoryCatalogClient implements CatalogApi { constructor(options?: { entities?: Entity[] }); // (undocumented) diff --git a/packages/catalog-client/src/testUtils/InMemoryCatalogClient.ts b/packages/catalog-client/src/testUtils/InMemoryCatalogClient.ts index ff01c99532..cde018a55c 100644 --- a/packages/catalog-client/src/testUtils/InMemoryCatalogClient.ts +++ b/packages/catalog-client/src/testUtils/InMemoryCatalogClient.ts @@ -38,7 +38,13 @@ import { } from '@backstage/catalog-model'; import { NotFoundError, NotImplementedError } from '@backstage/errors'; -/** @public */ +/** + * Implements a VERY basic fake catalog client that stores entities in memory. + * It has severely limited functionality, and is only useful under certain + * circumstances in tests. + * + * @public + */ export class InMemoryCatalogClient implements CatalogApi { #entities: Entity[]; diff --git a/plugins/catalog-node/api-report-testUtils.md b/plugins/catalog-node/api-report-testUtils.md index f3e465c7ac..0a3b392bad 100644 --- a/plugins/catalog-node/api-report-testUtils.md +++ b/plugins/catalog-node/api-report-testUtils.md @@ -9,21 +9,19 @@ import { InMemoryCatalogClient } from '@backstage/catalog-client/testUtils'; import { ServiceFactory } from '@backstage/backend-plugin-api'; import { ServiceMock } from '@backstage/backend-test-utils'; -// @public (undocumented) +// @public export function catalogServiceMock(options?: { entities?: Entity[]; }): InMemoryCatalogClient; -// @public (undocumented) +// @public export namespace catalogServiceMock { - const // (undocumented) - factory: (options?: { - entities?: Entity[]; - }) => ServiceFactory; - const // (undocumented) - mock: ( - partialImpl?: Partial | undefined, - ) => ServiceMock; + const factory: (options?: { + entities?: Entity[]; + }) => ServiceFactory; + const mock: ( + partialImpl?: Partial | undefined, + ) => ServiceMock; } // (No @packageDocumentation comment for this package) diff --git a/plugins/catalog-node/src/testUtils/catalogServiceMock.ts b/plugins/catalog-node/src/testUtils/catalogServiceMock.ts index dc73176a84..5eeb704ff8 100644 --- a/plugins/catalog-node/src/testUtils/catalogServiceMock.ts +++ b/plugins/catalog-node/src/testUtils/catalogServiceMock.ts @@ -50,19 +50,38 @@ function simpleMock( }; } -/** @public */ +/** + * Creates a fake catalog client that handles entities in memory storage. Note + * that this client may be severely limited in functionality, and advanced + * functions may not be available at all. + * + * @public + */ export function catalogServiceMock(options?: { entities?: Entity[] }) { return new InMemoryCatalogClient(options); } -/** @public */ +/** + * A collection of mock functionality for the catalog service. + * + * @public + */ export namespace catalogServiceMock { + /** + * Creates a fake catalog client that handles entities in memory storage. Note + * that this client may be severely limited in functionality, and advanced + * functions may not be available at all. + */ export const factory = (options?: { entities?: Entity[] }) => createServiceFactory({ service: catalogServiceRef, deps: {}, factory: () => new InMemoryCatalogClient(options), }); + /** + * Creates a catalog client whose methods are mock functions, possibly with + * some of them overloaded by the caller. + */ export const mock = simpleMock(catalogServiceRef, () => ({ getEntities: jest.fn(), getEntitiesByRefs: jest.fn(),