mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
fix(Google Sheets Trigger Node): Do not return header row in rowAdded mode (#13119)
This commit is contained in:
parent
ac8c5527ca
commit
cd8b300d5c
|
@ -120,6 +120,9 @@ export class GoogleSheetsTrigger implements INodeType {
|
||||||
default: { mode: 'list', value: '' },
|
default: { mode: 'list', value: '' },
|
||||||
// default: '', //empty string set to progresivly reveal fields
|
// default: '', //empty string set to progresivly reveal fields
|
||||||
required: true,
|
required: true,
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsDependsOn: ['documentId.value'],
|
||||||
|
},
|
||||||
modes: [
|
modes: [
|
||||||
{
|
{
|
||||||
displayName: 'From List',
|
displayName: 'From List',
|
||||||
|
@ -530,6 +533,11 @@ export class GoogleSheetsTrigger implements INodeType {
|
||||||
(options.dateTimeRenderOption as string) || 'FORMATTED_STRING',
|
(options.dateTimeRenderOption as string) || 'FORMATTED_STRING',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (Array.isArray(sheetData) && sheetData.length !== 0) {
|
||||||
|
const zeroBasedKeyRow = keyRow - 1;
|
||||||
|
sheetData.splice(zeroBasedKeyRow, 1); // Remove key row
|
||||||
|
}
|
||||||
|
|
||||||
if (this.getMode() === 'manual') {
|
if (this.getMode() === 'manual') {
|
||||||
if (Array.isArray(sheetData)) {
|
if (Array.isArray(sheetData)) {
|
||||||
const returnData = arrayOfArraysToJson(sheetData, columns);
|
const returnData = arrayOfArraysToJson(sheetData, columns);
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
import { mockDeep } from 'jest-mock-extended';
|
||||||
|
import nock from 'nock';
|
||||||
|
|
||||||
|
import { testPollingTriggerNode } from '@test/nodes/TriggerHelpers';
|
||||||
|
|
||||||
|
import { GoogleSheetsTrigger } from '../GoogleSheetsTrigger.node';
|
||||||
|
|
||||||
|
describe('GoogleSheetsTrigger', () => {
|
||||||
|
const baseUrl = 'https://sheets.googleapis.com';
|
||||||
|
|
||||||
|
describe('rowAdded event', () => {
|
||||||
|
it('should return rows without header', async () => {
|
||||||
|
const scope = nock(baseUrl);
|
||||||
|
scope
|
||||||
|
.get('/v4/spreadsheets/testDocumentId')
|
||||||
|
.query({ fields: 'sheets.properties' })
|
||||||
|
.reply(200, {
|
||||||
|
sheets: [{ properties: { sheetId: 1, title: 'testSheetName' } }],
|
||||||
|
});
|
||||||
|
scope
|
||||||
|
.get((uri) => uri.startsWith('/v4/spreadsheets/testDocumentId/values/testSheetName!A1:ZZZ'))
|
||||||
|
.times(2)
|
||||||
|
.reply(200, {
|
||||||
|
values: [
|
||||||
|
['name', 'count'],
|
||||||
|
['apple', 14],
|
||||||
|
['banana', 12],
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const { response } = await testPollingTriggerNode(GoogleSheetsTrigger, {
|
||||||
|
credential: mockDeep(),
|
||||||
|
mode: 'manual',
|
||||||
|
node: {
|
||||||
|
parameters: {
|
||||||
|
documentId: 'testDocumentId',
|
||||||
|
sheetName: 1,
|
||||||
|
event: 'rowAdded',
|
||||||
|
options: {
|
||||||
|
dataLocationOnSheet: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
scope.done();
|
||||||
|
|
||||||
|
expect(response).toEqual([
|
||||||
|
[{ json: { count: 14, name: 'apple' } }, { json: { count: 12, name: 'banana' } }],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue