fix(editor): Only ignore managed credentials in the HTTP node (#12417)

This commit is contained in:
Ricardo Espinoza
2025-01-02 10:43:34 -05:00
committed by GitHub
parent dab7bc43c6
commit 6b46657412
2 changed files with 74 additions and 8 deletions

View File

@@ -7,6 +7,7 @@ import { createComponentRenderer } from '@/__tests__/render';
import { useCredentialsStore } from '@/stores/credentials.store'; import { useCredentialsStore } from '@/stores/credentials.store';
import { mockedStore } from '@/__tests__/utils'; import { mockedStore } from '@/__tests__/utils';
import type { INodeUi } from '@/Interface'; import type { INodeUi } from '@/Interface';
import { useNDVStore } from '@/stores/ndv.store';
const httpNode: INodeUi = { const httpNode: INodeUi = {
parameters: { parameters: {
@@ -31,6 +32,25 @@ const httpNode: INodeUi = {
issues: { parameters: { url: ['Parameter "URL" is required.'] } }, issues: { parameters: { url: ['Parameter "URL" is required.'] } },
}; };
const openAiNode: INodeUi = {
parameters: {
resource: 'text',
operation: 'message',
modelId: { __rl: true, mode: 'list', value: '' },
messages: { values: [{ content: '', role: 'user' }] },
simplify: true,
jsonOutput: false,
options: {},
},
type: '@n8n/n8n-nodes-langchain.openAi',
typeVersion: 1.8,
position: [440, 0],
id: '17241295-a277-4cdf-8c46-6c3f85b335e9',
name: 'OpenAI',
credentials: { openAiApi: { id: 'byDFnd7vN5GzMVD2', name: 'n8n free OpenAI API credits' } },
issues: { parameters: { modelId: ['Parameter "Model" is required.'] } },
};
describe('NodeCredentials', () => { describe('NodeCredentials', () => {
const defaultRenderOptions: RenderOptions = { const defaultRenderOptions: RenderOptions = {
pinia: createTestingPinia(), pinia: createTestingPinia(),
@@ -45,6 +65,9 @@ describe('NodeCredentials', () => {
const renderComponent = createComponentRenderer(NodeCredentials, defaultRenderOptions); const renderComponent = createComponentRenderer(NodeCredentials, defaultRenderOptions);
const credentialsStore = mockedStore(useCredentialsStore);
const ndvStore = mockedStore(useNDVStore);
beforeAll(() => { beforeAll(() => {
credentialsStore.state.credentialTypes = { credentialsStore.state.credentialTypes = {
openAiApi: { openAiApi: {
@@ -80,9 +103,8 @@ describe('NodeCredentials', () => {
}; };
}); });
const credentialsStore = mockedStore(useCredentialsStore);
it('should display available credentials in the dropdown', async () => { it('should display available credentials in the dropdown', async () => {
ndvStore.activeNode = httpNode;
credentialsStore.state.credentials = { credentialsStore.state.credentials = {
c8vqdPpPClh4TgIO: { c8vqdPpPClh4TgIO: {
id: 'c8vqdPpPClh4TgIO', id: 'c8vqdPpPClh4TgIO',
@@ -103,7 +125,8 @@ describe('NodeCredentials', () => {
expect(screen.queryByText('OpenAi account')).toBeInTheDocument(); expect(screen.queryByText('OpenAi account')).toBeInTheDocument();
}); });
it('should ignore managed credentials in the dropdown', async () => { it('should ignore managed credentials in the dropdown if active node is the HTTP node', async () => {
ndvStore.activeNode = httpNode;
credentialsStore.state.credentials = { credentialsStore.state.credentials = {
c8vqdPpPClh4TgIO: { c8vqdPpPClh4TgIO: {
id: 'c8vqdPpPClh4TgIO', id: 'c8vqdPpPClh4TgIO',
@@ -132,4 +155,42 @@ describe('NodeCredentials', () => {
expect(screen.queryByText('OpenAi account')).toBeInTheDocument(); expect(screen.queryByText('OpenAi account')).toBeInTheDocument();
expect(screen.queryByText('OpenAi account 2')).not.toBeInTheDocument(); expect(screen.queryByText('OpenAi account 2')).not.toBeInTheDocument();
}); });
it('should not ignored managed credentials in the dropdown if active node is not the HTTP node', async () => {
ndvStore.activeNode = openAiNode;
credentialsStore.state.credentials = {
c8vqdPpPClh4TgIO: {
id: 'c8vqdPpPClh4TgIO',
name: 'OpenAi account',
type: 'openAiApi',
isManaged: false,
createdAt: '',
updatedAt: '',
},
SkXM3oUkQvvYS31c: {
id: 'c8vqdPpPClh4TgIO',
name: 'OpenAi account 2',
type: 'openAiApi',
isManaged: true,
createdAt: '',
updatedAt: '',
},
};
renderComponent(
{
props: {
node: openAiNode,
},
},
{ merge: true },
);
const credentialsSelect = screen.getByTestId('node-credentials-select');
await fireEvent.click(credentialsSelect);
expect(screen.queryByText('OpenAi account')).toBeInTheDocument();
expect(screen.queryByText('OpenAi account 2')).toBeInTheDocument();
});
}); });

View File

@@ -1,9 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import type { ICredentialsResponse, INodeUi, INodeUpdatePropertiesInformation } from '@/Interface'; import type { ICredentialsResponse, INodeUi, INodeUpdatePropertiesInformation } from '@/Interface';
import type { import {
INodeCredentialDescription, HTTP_REQUEST_NODE_TYPE,
INodeCredentialsDetails, type INodeCredentialDescription,
NodeParameterValueType, type INodeCredentialsDetails,
type NodeParameterValueType,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'; import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
@@ -261,7 +262,11 @@ function getCredentialOptions(types: string[]): CredentialDropdownOption[] {
); );
}); });
return options.filter((option) => !option.isManaged); if (ndvStore.activeNode?.type === HTTP_REQUEST_NODE_TYPE) {
options = options.filter((option) => !option.isManaged);
}
return options;
} }
function getSelectedId(type: string) { function getSelectedId(type: string) {