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:
Ben Lambert
2026-02-27 17:24:49 +01:00
committed by GitHub
parent 1b3dea2092
commit f598909f0f
26 changed files with 1188 additions and 112 deletions
@@ -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();
+23
View File
@@ -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(),
}));
}