fix(editor): Parse out nodeType (#13474)

This commit is contained in:
Dana 2025-02-25 14:43:45 +01:00 committed by GitHub
parent 59389194c2
commit 1cd13b639e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 44 additions and 1 deletions

View file

@ -18,7 +18,9 @@ export const getSchemaPreview = async (
): Promise<JSONSchema7> => {
const { nodeType, version, resource, operation } = options;
const versionString = padVersion(version);
const path = ['schemas', nodeType, versionString, resource, operation].filter(Boolean).join('/');
const path = ['schemas', nodeType.replace('@n8n/', ''), versionString, resource, operation]
.filter(Boolean)
.join('/');
return await request({
method: 'GET',
baseURL: baseUrl,

View file

@ -0,0 +1,41 @@
import { getSchemaPreview } from '../schemaPreview';
import * as apiUtils from '@/utils/apiUtils';
describe('schemaPreview', () => {
afterEach(() => {
vi.resetAllMocks();
});
vi.mock('@/utils/apiUtils', () => ({
request: vi.fn().mockResolvedValue({ test: 'test' }),
}));
it('should return schema preview', async () => {
const response = await getSchemaPreview('http://test.com', {
nodeType: 'n8n-nodes-base.asana',
version: 1,
resource: 'resource',
operation: 'operation',
});
expect(response).toEqual({ test: 'test' });
});
it('should parse out nodeType', async () => {
const spy = vi.spyOn(apiUtils, 'request');
await getSchemaPreview('http://test.com', {
nodeType: '@n8n/n8n-nodes-base.asana',
version: 1,
resource: 'resource',
operation: 'operation',
});
expect(spy).toHaveBeenCalledWith({
method: 'GET',
baseURL: 'http://test.com',
endpoint: 'schemas/n8n-nodes-base.asana/1.0.0/resource/operation.json',
withCredentials: false,
});
});
});