feat(scaffolder): implement scaffolderServiceRef for credentials aware communication (#33044)
* add scaffolderServiceRef to scaffolder-node Signed-off-by: benjdlambert <ben@blam.sh> * make ScaffolderApi methods required, add tests Signed-off-by: benjdlambert <ben@blam.sh> * use request objects for single-string params in ScaffolderService Signed-off-by: benjdlambert <ben@blam.sh> * add scaffolderServiceMock test utility Signed-off-by: benjdlambert <ben@blam.sh> * adjust review comments Signed-off-by: benjdlambert <ben@blam.sh> * add scaffolderApiMock test utility to scaffolder-react Signed-off-by: benjdlambert <ben@blam.sh> * use items/totalItems response shape for listTasks Signed-off-by: benjdlambert <ben@blam.sh> * pass credentials through for autocomplete Signed-off-by: benjdlambert <ben@blam.sh> --------- Signed-off-by: benjdlambert <ben@blam.sh>
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./alpha": "./src/alpha.ts",
|
||||
"./testUtils": "./src/testUtils.ts",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"main": "src/index.ts",
|
||||
@@ -40,6 +41,9 @@
|
||||
"alpha": [
|
||||
"src/alpha.ts"
|
||||
],
|
||||
"testUtils": [
|
||||
"src/testUtils.ts"
|
||||
],
|
||||
"package.json": [
|
||||
"package.json"
|
||||
]
|
||||
@@ -115,12 +119,16 @@
|
||||
"swr": "^2.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@backstage/frontend-test-utils": "workspace:^",
|
||||
"@types/react": "^17.0.0 || ^18.0.0",
|
||||
"react": "^17.0.0 || ^18.0.0",
|
||||
"react-dom": "^17.0.0 || ^18.0.0",
|
||||
"react-router-dom": "^6.30.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@backstage/frontend-test-utils": {
|
||||
"optional": true
|
||||
},
|
||||
"@types/react": {
|
||||
"optional": true
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
## API Report File for "@backstage/plugin-scaffolder-react"
|
||||
|
||||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
||||
|
||||
```ts
|
||||
import { ApiMock } from '@backstage/frontend-test-utils';
|
||||
import { ScaffolderApi } from '@backstage/plugin-scaffolder-common';
|
||||
|
||||
// @public
|
||||
export namespace scaffolderApiMock {
|
||||
const mock: (
|
||||
partialImpl?: Partial<ScaffolderApi> | undefined,
|
||||
) => ApiMock<ScaffolderApi>;
|
||||
}
|
||||
```
|
||||
@@ -37,6 +37,9 @@ const scaffolderApiMock: jest.Mocked<ScaffolderApi> = {
|
||||
listActions: jest.fn(),
|
||||
listTasks: jest.fn(),
|
||||
autocomplete: jest.fn(),
|
||||
retry: jest.fn(),
|
||||
listTemplatingExtensions: jest.fn(),
|
||||
dryRun: jest.fn(),
|
||||
};
|
||||
|
||||
const catalogApi = catalogApiMock.mock();
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2025 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Frontend test helpers for the Scaffolder plugin.
|
||||
*
|
||||
* @packageDocumentation
|
||||
*/
|
||||
|
||||
export { scaffolderApiMock } from './testUtils/scaffolderApiMock';
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2025 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { scaffolderApiMock } from './scaffolderApiMock';
|
||||
|
||||
describe('scaffolderApiMock', () => {
|
||||
it('creates a mock with all methods as jest.fn()', () => {
|
||||
const mock = scaffolderApiMock.mock();
|
||||
|
||||
expect(mock.getTask).toHaveBeenCalledTimes(0);
|
||||
expect(mock.scaffold).toHaveBeenCalledTimes(0);
|
||||
expect(mock.listActions).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it('supports overriding individual methods', async () => {
|
||||
const mock = scaffolderApiMock.mock({
|
||||
getTask: jest.fn().mockResolvedValue({ id: 'task-1' }),
|
||||
});
|
||||
|
||||
await expect(mock.getTask('task-1')).resolves.toEqual(
|
||||
expect.objectContaining({ id: 'task-1' }),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2025 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createApiMock } from '@backstage/frontend-test-utils';
|
||||
import { scaffolderApiRef } from '../api/ref';
|
||||
|
||||
/**
|
||||
* A collection of mock functionality for the scaffolder API.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export namespace scaffolderApiMock {
|
||||
/**
|
||||
* Creates a scaffolder API whose methods are mock functions, possibly with
|
||||
* some of them overloaded by the caller.
|
||||
*/
|
||||
export const mock = createApiMock(scaffolderApiRef, () => ({
|
||||
getTemplateParameterSchema: jest.fn(),
|
||||
scaffold: jest.fn(),
|
||||
getTask: jest.fn(),
|
||||
cancelTask: jest.fn(),
|
||||
retry: jest.fn(),
|
||||
listTasks: jest.fn(),
|
||||
getIntegrationsList: jest.fn(),
|
||||
listActions: jest.fn(),
|
||||
listTemplatingExtensions: jest.fn(),
|
||||
streamLogs: jest.fn(),
|
||||
dryRun: jest.fn(),
|
||||
autocomplete: jest.fn(),
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user