From 98ccf0020a5ed6d8a3da2f7e1ff0ac7678f95297 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 11 Jul 2024 14:21:48 +0200 Subject: [PATCH] backend-test-utils: refactor httpAuth.factory to define options on its own Signed-off-by: Patrik Oldsberg --- .changeset/wicked-impalas-explode.md | 5 ++++ packages/backend-test-utils/api-report.md | 11 +++----- .../src/next/services/mockServices.ts | 25 +++++++++++-------- 3 files changed, 24 insertions(+), 17 deletions(-) create mode 100644 .changeset/wicked-impalas-explode.md diff --git a/.changeset/wicked-impalas-explode.md b/.changeset/wicked-impalas-explode.md new file mode 100644 index 0000000000..f8a01bc36e --- /dev/null +++ b/.changeset/wicked-impalas-explode.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-test-utils': patch +--- + +Internal refactor of `mockServices.httpAuth.factory` to allow it to still be constructed with options, but without declaring options via `createServiceFactory`. diff --git a/packages/backend-test-utils/api-report.md b/packages/backend-test-utils/api-report.md index af7edba061..d77aea09a8 100644 --- a/packages/backend-test-utils/api-report.md +++ b/packages/backend-test-utils/api-report.md @@ -206,13 +206,10 @@ export namespace mockServices { }): HttpAuthService; // (undocumented) export namespace httpAuth { - const factory: ServiceFactoryCompat< - HttpAuthService, - 'plugin', - { - defaultCredentials?: BackstageCredentials | undefined; - } - >; + const factory: ((options?: { + defaultCredentials?: BackstageCredentials; + }) => ServiceFactory) & + ServiceFactory; const // (undocumented) mock: ( partialImpl?: Partial | undefined, diff --git a/packages/backend-test-utils/src/next/services/mockServices.ts b/packages/backend-test-utils/src/next/services/mockServices.ts index d56179d958..38ff819228 100644 --- a/packages/backend-test-utils/src/next/services/mockServices.ts +++ b/packages/backend-test-utils/src/next/services/mockServices.ts @@ -270,15 +270,10 @@ export namespace mockServices { ); } export namespace httpAuth { - /** - * Creates a mock service factory for the `HttpAuthService`. - * - * By default all requests without credentials are treated as requests from - * the default mock user principal. This behavior can be configured with the - * `defaultCredentials` option. - */ - export const factory = createServiceFactory( - (options?: { defaultCredentials?: BackstageCredentials }) => ({ + const factoryWithOptions = (options?: { + defaultCredentials?: BackstageCredentials; + }) => + createServiceFactory({ service: coreServices.httpAuth, deps: { plugin: coreServices.pluginMetadata }, factory: ({ plugin }) => @@ -286,7 +281,17 @@ export namespace mockServices { plugin.getId(), options?.defaultCredentials ?? mockCredentials.user(), ), - }), + })(); + /** + * Creates a mock service factory for the `HttpAuthService`. + * + * By default all requests without credentials are treated as requests from + * the default mock user principal. This behavior can be configured with the + * `defaultCredentials` option. + */ + export const factory = Object.assign( + factoryWithOptions, + factoryWithOptions(), ); export const mock = simpleMock(coreServices.httpAuth, () => ({ credentials: jest.fn(),