diff --git a/.changeset/tall-actors-clap.md b/.changeset/tall-actors-clap.md new file mode 100644 index 0000000000..594918a362 --- /dev/null +++ b/.changeset/tall-actors-clap.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder': patch +--- + +Fix issue with `secrets` not being forwarded properly to the backend when creating a task diff --git a/plugins/scaffolder/src/alpha/hooks/useFormDecorators.test.tsx b/plugins/scaffolder/src/alpha/hooks/useFormDecorators.test.tsx index 92475c3eea..8f486bbba1 100644 --- a/plugins/scaffolder/src/alpha/hooks/useFormDecorators.test.tsx +++ b/plugins/scaffolder/src/alpha/hooks/useFormDecorators.test.tsx @@ -81,4 +81,75 @@ describe('useFormDecorators', () => { expect(mockApiImplementation.test).toHaveBeenCalledWith('hello'); }); }); + + it('should return existing secrets and formstate', async () => { + const renderedHook = renderHook(() => useFormDecorators({ manifest }), { + wrapper: ({ children }) => ( + {} }], + ]} + > + {children} + + ), + }); + await waitFor(async () => { + const result = renderedHook.result.current!; + + const { secrets, formState } = await result.run({ + formState: { test: 'formState' }, + secrets: { test: 'hello' }, + }); + + expect(secrets).toEqual({ test: 'hello' }); + expect(formState).toEqual({ test: 'formState' }); + }); + }); + + it('should allow merging of existing secrets and formstate', async () => { + const secretAndFormDataModifier = createScaffolderFormDecorator({ + id: 'test', + async decorator({ setFormState, setSecrets }) { + setFormState(state => ({ ...state, new: 'formState' })); + setSecrets(state => ({ ...state, new: 'hello' })); + }, + }); + const renderedHook = renderHook(() => useFormDecorators({ manifest }), { + wrapper: ({ children }) => ( + {} }], + ]} + > + {children} + + ), + }); + await waitFor(async () => { + const result = renderedHook.result.current!; + + const { secrets, formState } = await result.run({ + formState: { test: 'formState' }, + secrets: { test: 'hello' }, + }); + + expect(secrets).toEqual({ test: 'hello', new: 'hello' }); + expect(formState).toEqual({ test: 'formState', new: 'formState' }); + }); + }); }); diff --git a/plugins/scaffolder/src/alpha/hooks/useFormDecorators.ts b/plugins/scaffolder/src/alpha/hooks/useFormDecorators.ts index 8469a89bec..d74c4a9823 100644 --- a/plugins/scaffolder/src/alpha/hooks/useFormDecorators.ts +++ b/plugins/scaffolder/src/alpha/hooks/useFormDecorators.ts @@ -75,7 +75,7 @@ export const useFormDecorators = ({ secrets: Record; }) => { let formState: Record = { ...opts.formState }; - let secrets: Record = {}; + let secrets: Record = { ...opts.secrets }; if (manifest?.EXPERIMENTAL_formDecorators) { // for each of the form decorators, go and call the decorator with the context