diff --git a/.changeset/sweet-ducks-wait.md b/.changeset/sweet-ducks-wait.md index 4792fafe84..8555f4785e 100644 --- a/.changeset/sweet-ducks-wait.md +++ b/.changeset/sweet-ducks-wait.md @@ -2,4 +2,29 @@ '@backstage/backend-test-utils': minor --- -Added mock implementations for `ActionsService` and `ActionsRegistryService` +Added an `actionsRegistryServiceMock` and `actionsServiceMock` to `/alpha` export for the experimental services. + +This allows you to write tests for your actions by doing something similar to the following: + +```ts +import { actionsRegistryServiceMock } from '@backstage/backend-test-utils/alpha'; + +const mockActionsRegistry = actionsRegistryServiceMock(); +const mockCatalog = catalogServiceMock({ + entities: [ + ... + ], +}); + +createGetCatalogEntityAction({ + catalog: mockCatalog, + actionsRegistry: mockActionsRegistry, +}); + +await expect( + mockActionsRegistry.invoke({ + id: 'test:get-catalog-entity', + input: { name: 'test' }, + }), +).resolves.toEqual(...) +``` diff --git a/.changeset/wet-bars-report.md b/.changeset/wet-bars-report.md index d556f6cc61..019f1f2f6c 100644 --- a/.changeset/wet-bars-report.md +++ b/.changeset/wet-bars-report.md @@ -2,4 +2,30 @@ '@backstage/backend-plugin-api': minor --- -Added `coreServices.actionsRegistry` and `coreServices.actions` to allow registration of distributed actions from plugins, and the ability to invoke these actions +Added `actionsRegistry` and `actions` experimental services to `/alpha` to allow registration of distributed actions from plugins, and the ability to invoke these actions. You can use these services by including them like the following: + +```ts +import { + actionsRegistryServiceRef, + actionsServiceRef, +} from '@backstage/backend-plugin-api/alpha'; + +createBackendPlugin({ + pluginId: 'test-plugin', + register({ registerInit }) { + registerInit({ + deps: { + actions: actionsServiceRef, + actionsRegistry: actionsRegistryServiceRef, + }, + async init({ actions, actionsRegistry }) { + actionsRegistry.register({ + ..., + }); + + await actions.invoke(...); + }, + }); + }, +}); +``` diff --git a/.changeset/wet-bars-reporting.md b/.changeset/wet-bars-reporting.md index 7dc66cb280..2bcf4f502e 100644 --- a/.changeset/wet-bars-reporting.md +++ b/.changeset/wet-bars-reporting.md @@ -2,4 +2,4 @@ '@backstage/backend-defaults': patch --- -Added some default implementations for the `ActionsService` and `ActionsRegistryService` that allow registration of actions for a particular plugin. +Added some default implementations for the experimental `ActionsService` and `ActionsRegistryService` under `/alpha` that allow registration of actions for a particular plugin.