mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
fix(Airtable Node): Use item at correct index in base/getSchema (#13174)
This commit is contained in:
parent
7ee6ce7ed2
commit
f2e35869c1
|
@ -1,13 +1,16 @@
|
||||||
|
import { mockDeep } from 'jest-mock-extended';
|
||||||
|
import { get } from 'lodash';
|
||||||
|
import type { IExecuteFunctions } from 'n8n-workflow';
|
||||||
|
|
||||||
import * as getSchema from '../../../../v2/actions/base/getSchema.operation';
|
import * as getSchema from '../../../../v2/actions/base/getSchema.operation';
|
||||||
import * as transport from '../../../../v2/transport';
|
import * as transport from '../../../../v2/transport';
|
||||||
import { createMockExecuteFunction } from '../helpers';
|
|
||||||
|
|
||||||
jest.mock('../../../../v2/transport', () => {
|
jest.mock('../../../../v2/transport', () => {
|
||||||
const originalModule = jest.requireActual('../../../../v2/transport');
|
const originalModule = jest.requireActual('../../../../v2/transport');
|
||||||
return {
|
return {
|
||||||
...originalModule,
|
...originalModule,
|
||||||
apiRequest: jest.fn(async function () {
|
apiRequest: jest.fn(async function () {
|
||||||
return {};
|
return { tables: [] };
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -18,19 +21,35 @@ describe('Test AirtableV2, base => getSchema', () => {
|
||||||
resource: 'base',
|
resource: 'base',
|
||||||
operation: 'getSchema',
|
operation: 'getSchema',
|
||||||
base: {
|
base: {
|
||||||
value: 'appYobase',
|
value: '={{$json.id}}',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const items = [
|
const items = [
|
||||||
{
|
{
|
||||||
json: {},
|
json: { id: 'appYobase1' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
json: { id: 'appYobase2' },
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
await getSchema.execute.call(createMockExecuteFunction(nodeParameters), items);
|
await getSchema.execute.call(
|
||||||
|
mockDeep<IExecuteFunctions>({
|
||||||
|
getInputData: jest.fn(() => items),
|
||||||
|
getNodeParameter: jest.fn((param: string, itemIndex: number) => {
|
||||||
|
if (param === 'base') {
|
||||||
|
return items[itemIndex].json.id;
|
||||||
|
}
|
||||||
|
|
||||||
expect(transport.apiRequest).toBeCalledTimes(1);
|
return get(nodeParameters, param);
|
||||||
expect(transport.apiRequest).toHaveBeenCalledWith('GET', 'meta/bases/appYobase/tables');
|
}),
|
||||||
|
}),
|
||||||
|
items,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(transport.apiRequest).toBeCalledTimes(2);
|
||||||
|
expect(transport.apiRequest).toHaveBeenCalledWith('GET', 'meta/bases/appYobase1/tables');
|
||||||
|
expect(transport.apiRequest).toHaveBeenCalledWith('GET', 'meta/bases/appYobase2/tables');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import type {
|
import type {
|
||||||
IDataObject,
|
IExecuteFunctions,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodeProperties,
|
INodeProperties,
|
||||||
IExecuteFunctions,
|
|
||||||
NodeApiError,
|
NodeApiError,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
@ -10,6 +9,7 @@ import { updateDisplayOptions, wrapData } from '../../../../../utils/utilities';
|
||||||
import { processAirtableError } from '../../helpers/utils';
|
import { processAirtableError } from '../../helpers/utils';
|
||||||
import { apiRequest } from '../../transport';
|
import { apiRequest } from '../../transport';
|
||||||
import { baseRLC } from '../common.descriptions';
|
import { baseRLC } from '../common.descriptions';
|
||||||
|
import type { TablesResponse } from '../types';
|
||||||
|
|
||||||
const properties: INodeProperties[] = [
|
const properties: INodeProperties[] = [
|
||||||
{
|
{
|
||||||
|
@ -31,22 +31,25 @@ export async function execute(
|
||||||
this: IExecuteFunctions,
|
this: IExecuteFunctions,
|
||||||
items: INodeExecutionData[],
|
items: INodeExecutionData[],
|
||||||
): Promise<INodeExecutionData[]> {
|
): Promise<INodeExecutionData[]> {
|
||||||
const returnData: INodeExecutionData[] = [];
|
let returnData: INodeExecutionData[] = [];
|
||||||
|
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
try {
|
try {
|
||||||
const baseId = this.getNodeParameter('base', 0, undefined, {
|
const baseId = this.getNodeParameter('base', i, undefined, {
|
||||||
extractValue: true,
|
extractValue: true,
|
||||||
}) as string;
|
}) as string;
|
||||||
|
|
||||||
const responseData = await apiRequest.call(this, 'GET', `meta/bases/${baseId}/tables`);
|
const responseData: TablesResponse = await apiRequest.call(
|
||||||
|
this,
|
||||||
const executionData = this.helpers.constructExecutionMetaData(
|
'GET',
|
||||||
wrapData(responseData.tables as IDataObject[]),
|
`meta/bases/${baseId}/tables`,
|
||||||
{ itemData: { item: i } },
|
|
||||||
);
|
);
|
||||||
|
|
||||||
returnData.push(...executionData);
|
const executionData = this.helpers.constructExecutionMetaData(wrapData(responseData.tables), {
|
||||||
|
itemData: { item: i },
|
||||||
|
});
|
||||||
|
|
||||||
|
returnData = returnData.concat(executionData);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error = processAirtableError(error as NodeApiError, undefined, i);
|
error = processAirtableError(error as NodeApiError, undefined, i);
|
||||||
if (this.continueOnFail()) {
|
if (this.continueOnFail()) {
|
||||||
|
|
15
packages/nodes-base/nodes/Airtable/v2/actions/types.ts
Normal file
15
packages/nodes-base/nodes/Airtable/v2/actions/types.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
export type Table = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
fields: Field[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TablesResponse = {
|
||||||
|
tables: Table[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Field = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
type: string;
|
||||||
|
};
|
Loading…
Reference in a new issue