backend-test-utils: refactor httpAuth.factory to define options on its own
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -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`.
|
||||
@@ -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<HttpAuthService, 'plugin'>) &
|
||||
ServiceFactory<HttpAuthService, 'plugin'>;
|
||||
const // (undocumented)
|
||||
mock: (
|
||||
partialImpl?: Partial<HttpAuthService> | undefined,
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user