first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,274 @@
|
||||
import type { ILoadOptionsFunctions } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { sheetsSearch, spreadSheetsSearch } from '../../../v2/methods/listSearch';
|
||||
import { apiRequest } from '../../../v2/transport';
|
||||
|
||||
jest.mock('../../../v2/transport', () => ({
|
||||
apiRequest: {
|
||||
call: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe('Google Sheets Search Functions', () => {
|
||||
let mockLoadOptionsFunctions: Partial<ILoadOptionsFunctions>;
|
||||
|
||||
beforeEach(() => {
|
||||
mockLoadOptionsFunctions = {
|
||||
getNode: jest.fn(),
|
||||
getNodeParameter: jest.fn(),
|
||||
};
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('spreadSheetsSearch', () => {
|
||||
it('should return search results without filter', async () => {
|
||||
const mockResponse = {
|
||||
files: [
|
||||
{ id: '1', name: 'Sheet1', webViewLink: 'https://sheet1.url' },
|
||||
{ id: '2', name: 'Sheet2', webViewLink: 'https://sheet2.url' },
|
||||
],
|
||||
nextPageToken: 'next-page',
|
||||
};
|
||||
|
||||
(apiRequest.call as jest.Mock).mockResolvedValue(mockResponse);
|
||||
|
||||
const result = await spreadSheetsSearch.call(
|
||||
mockLoadOptionsFunctions as ILoadOptionsFunctions,
|
||||
);
|
||||
|
||||
expect(apiRequest.call).toHaveBeenCalledWith(
|
||||
mockLoadOptionsFunctions,
|
||||
'GET',
|
||||
'',
|
||||
{},
|
||||
{
|
||||
q: "mimeType = 'application/vnd.google-apps.spreadsheet'",
|
||||
fields: 'nextPageToken, files(id, name, webViewLink)',
|
||||
orderBy: 'modifiedByMeTime desc,name_natural',
|
||||
includeItemsFromAllDrives: true,
|
||||
supportsAllDrives: true,
|
||||
},
|
||||
'https://www.googleapis.com/drive/v3/files',
|
||||
);
|
||||
|
||||
expect(result).toEqual({
|
||||
results: [
|
||||
{ name: 'Sheet1', value: '1', url: 'https://sheet1.url' },
|
||||
{ name: 'Sheet2', value: '2', url: 'https://sheet2.url' },
|
||||
],
|
||||
paginationToken: 'next-page',
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle search with filter', async () => {
|
||||
const mockResponse = {
|
||||
files: [{ id: '1', name: 'TestSheet', webViewLink: 'https://test.url' }],
|
||||
};
|
||||
|
||||
(apiRequest.call as jest.Mock).mockResolvedValue(mockResponse);
|
||||
|
||||
const result = await spreadSheetsSearch.call(
|
||||
mockLoadOptionsFunctions as ILoadOptionsFunctions,
|
||||
'Test',
|
||||
);
|
||||
|
||||
expect(apiRequest.call).toHaveBeenCalledWith(
|
||||
mockLoadOptionsFunctions,
|
||||
'GET',
|
||||
'',
|
||||
{},
|
||||
{
|
||||
q: "name contains 'Test' and mimeType = 'application/vnd.google-apps.spreadsheet'",
|
||||
fields: 'nextPageToken, files(id, name, webViewLink)',
|
||||
orderBy: 'modifiedByMeTime desc,name_natural',
|
||||
includeItemsFromAllDrives: true,
|
||||
supportsAllDrives: true,
|
||||
},
|
||||
'https://www.googleapis.com/drive/v3/files',
|
||||
);
|
||||
|
||||
expect(result.results).toHaveLength(1);
|
||||
expect(result.results[0].name).toBe('TestSheet');
|
||||
});
|
||||
|
||||
it('should escape single quotes in filter', async () => {
|
||||
const mockResponse = { files: [] };
|
||||
(apiRequest.call as jest.Mock).mockResolvedValue(mockResponse);
|
||||
|
||||
await spreadSheetsSearch.call(
|
||||
mockLoadOptionsFunctions as ILoadOptionsFunctions,
|
||||
"Test's Sheet",
|
||||
);
|
||||
|
||||
expect(apiRequest.call).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
'GET',
|
||||
'',
|
||||
{},
|
||||
expect.objectContaining({
|
||||
q: "name contains 'Test\\'s Sheet' and mimeType = 'application/vnd.google-apps.spreadsheet'",
|
||||
}),
|
||||
expect.any(String),
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle pagination token', async () => {
|
||||
const mockResponse = { files: [] };
|
||||
(apiRequest.call as jest.Mock).mockResolvedValue(mockResponse);
|
||||
|
||||
await spreadSheetsSearch.call(
|
||||
mockLoadOptionsFunctions as ILoadOptionsFunctions,
|
||||
undefined,
|
||||
'page-token',
|
||||
);
|
||||
|
||||
expect(apiRequest.call).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
'GET',
|
||||
'',
|
||||
{},
|
||||
expect.objectContaining({
|
||||
pageToken: 'page-token',
|
||||
}),
|
||||
expect.any(String),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sheetsSearch', () => {
|
||||
it('should return empty results when no documentId is provided', async () => {
|
||||
mockLoadOptionsFunctions.getNodeParameter = jest.fn().mockReturnValue(null);
|
||||
|
||||
const result = await sheetsSearch.call(mockLoadOptionsFunctions as ILoadOptionsFunctions);
|
||||
|
||||
expect(result).toEqual({ results: [] });
|
||||
expect(apiRequest.call).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should return sheets list for valid spreadsheet', async () => {
|
||||
mockLoadOptionsFunctions.getNodeParameter = jest.fn().mockReturnValue({
|
||||
mode: 'id',
|
||||
value: 'spreadsheet-id',
|
||||
});
|
||||
|
||||
const mockResponse = {
|
||||
sheets: [
|
||||
{
|
||||
properties: {
|
||||
sheetId: 123,
|
||||
title: 'Sheet1',
|
||||
sheetType: 'GRID',
|
||||
},
|
||||
},
|
||||
{
|
||||
properties: {
|
||||
sheetId: 456,
|
||||
title: 'Sheet2',
|
||||
sheetType: 'GRID',
|
||||
},
|
||||
},
|
||||
{
|
||||
properties: {
|
||||
sheetId: 789,
|
||||
title: 'Chart1',
|
||||
sheetType: 'CHART',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
(apiRequest.call as jest.Mock).mockResolvedValue(mockResponse);
|
||||
|
||||
const result = await sheetsSearch.call(mockLoadOptionsFunctions as ILoadOptionsFunctions);
|
||||
|
||||
expect(apiRequest.call).toHaveBeenCalledWith(
|
||||
mockLoadOptionsFunctions,
|
||||
'GET',
|
||||
'/v4/spreadsheets/spreadsheet-id',
|
||||
{},
|
||||
{ fields: 'sheets.properties' },
|
||||
);
|
||||
|
||||
expect(result.results).toHaveLength(2); // Only GRID type sheets
|
||||
expect(result.results[0]).toEqual({
|
||||
name: 'Sheet1',
|
||||
value: 123,
|
||||
url: 'https://docs.google.com/spreadsheets/d/spreadsheet-id/edit#gid=123',
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle default sheet id when sheetId is not provided', async () => {
|
||||
mockLoadOptionsFunctions.getNodeParameter = jest.fn().mockReturnValue({
|
||||
mode: 'id',
|
||||
value: 'spreadsheet-id',
|
||||
});
|
||||
|
||||
const mockResponse = {
|
||||
sheets: [
|
||||
{
|
||||
properties: {
|
||||
title: 'Sheet1',
|
||||
sheetType: 'GRID',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
(apiRequest.call as jest.Mock).mockResolvedValue(mockResponse);
|
||||
|
||||
const result = await sheetsSearch.call(mockLoadOptionsFunctions as ILoadOptionsFunctions);
|
||||
|
||||
expect(result.results[0].value).toBe('gid=0');
|
||||
});
|
||||
|
||||
it('should throw error when no data is returned', async () => {
|
||||
mockLoadOptionsFunctions.getNodeParameter = jest.fn().mockReturnValue({
|
||||
mode: 'id',
|
||||
value: 'spreadsheet-id',
|
||||
});
|
||||
mockLoadOptionsFunctions.getNode = jest.fn().mockReturnValue({});
|
||||
|
||||
(apiRequest.call as jest.Mock).mockResolvedValue(undefined);
|
||||
|
||||
await expect(
|
||||
sheetsSearch.call(mockLoadOptionsFunctions as ILoadOptionsFunctions),
|
||||
).rejects.toThrow(
|
||||
new NodeOperationError(mockLoadOptionsFunctions.getNode(), 'No data got returned'),
|
||||
);
|
||||
});
|
||||
|
||||
it('should filter out non-GRID type sheets', async () => {
|
||||
mockLoadOptionsFunctions.getNodeParameter = jest.fn().mockReturnValue({
|
||||
mode: 'id',
|
||||
value: 'spreadsheet-id',
|
||||
});
|
||||
|
||||
const mockResponse = {
|
||||
sheets: [
|
||||
{
|
||||
properties: {
|
||||
sheetId: 123,
|
||||
title: 'Chart',
|
||||
sheetType: 'CHART',
|
||||
},
|
||||
},
|
||||
{
|
||||
properties: {
|
||||
sheetId: 456,
|
||||
title: 'Grid',
|
||||
sheetType: 'GRID',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
(apiRequest.call as jest.Mock).mockResolvedValue(mockResponse);
|
||||
|
||||
const result = await sheetsSearch.call(mockLoadOptionsFunctions as ILoadOptionsFunctions);
|
||||
|
||||
expect(result.results).toHaveLength(1);
|
||||
expect(result.results[0].name).toBe('Grid');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,169 @@
|
||||
import type { ILoadOptionsFunctions } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
getSheetHeaderRow,
|
||||
getSheetHeaderRowAndAddColumn,
|
||||
getSheetHeaderRowAndSkipEmpty,
|
||||
getSheetHeaderRowWithGeneratedColumnNames,
|
||||
getSheets,
|
||||
} from '../../../v2/methods/loadOptions';
|
||||
|
||||
jest.mock('../../../v2/helpers/GoogleSheets.utils');
|
||||
|
||||
const mockGoogleSheetInstance = {
|
||||
spreadsheetGetSheets: jest.fn(),
|
||||
spreadsheetGetSheet: jest.fn(),
|
||||
getData: jest.fn(),
|
||||
testFilter: jest.fn(),
|
||||
};
|
||||
|
||||
jest.mock('../../../v2/helpers/GoogleSheet', () => ({
|
||||
GoogleSheet: jest.fn().mockImplementation(() => mockGoogleSheetInstance),
|
||||
}));
|
||||
|
||||
describe('Google Sheets Functions', () => {
|
||||
let mockLoadOptionsFunctions: Partial<ILoadOptionsFunctions>;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
mockLoadOptionsFunctions = {
|
||||
getNodeParameter: jest.fn((paramName: string) => {
|
||||
if (paramName === 'documentId') {
|
||||
return { mode: 'mode', value: 'value' };
|
||||
}
|
||||
if (paramName === 'sheetName') {
|
||||
return { mode: 'Sheet1', value: 'Sheet1' };
|
||||
}
|
||||
}),
|
||||
getNode: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
describe('getSheets', () => {
|
||||
it('should return an empty array if documentId is null', async () => {
|
||||
mockLoadOptionsFunctions.getNodeParameter = jest.fn().mockReturnValue(null);
|
||||
|
||||
const result = await getSheets.call(mockLoadOptionsFunctions as ILoadOptionsFunctions);
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
it('should throw an error if no data is returned', async () => {
|
||||
mockGoogleSheetInstance.spreadsheetGetSheets.mockResolvedValue(undefined);
|
||||
|
||||
await expect(
|
||||
getSheets.call(mockLoadOptionsFunctions as ILoadOptionsFunctions),
|
||||
).rejects.toThrow(NodeOperationError);
|
||||
});
|
||||
|
||||
it('should return sheets with GRID type', async () => {
|
||||
mockGoogleSheetInstance.spreadsheetGetSheets.mockResolvedValue({
|
||||
sheets: [
|
||||
{ properties: { sheetType: 'GRID', title: 'Sheet1', sheetId: '123' } },
|
||||
{ properties: { sheetType: 'OTHER', title: 'Sheet2', sheetId: '456' } },
|
||||
],
|
||||
});
|
||||
|
||||
const result = await getSheets.call(mockLoadOptionsFunctions as ILoadOptionsFunctions);
|
||||
expect(result).toEqual([{ name: 'Sheet1', value: '123' }]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSheetHeaderRow', () => {
|
||||
it('should return an empty array if documentId is null', async () => {
|
||||
mockLoadOptionsFunctions.getNodeParameter = jest.fn().mockReturnValue(null);
|
||||
|
||||
const result = await getSheetHeaderRow.call(
|
||||
mockLoadOptionsFunctions as ILoadOptionsFunctions,
|
||||
);
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
it('should throw an error if no data is returned', async () => {
|
||||
mockGoogleSheetInstance.spreadsheetGetSheet.mockResolvedValue({
|
||||
title: 'Sheet1',
|
||||
});
|
||||
mockGoogleSheetInstance.getData.mockResolvedValue(undefined);
|
||||
|
||||
await expect(
|
||||
getSheetHeaderRow.call(mockLoadOptionsFunctions as ILoadOptionsFunctions),
|
||||
).rejects.toThrow(NodeOperationError);
|
||||
});
|
||||
|
||||
it('should return column headers', async () => {
|
||||
mockGoogleSheetInstance.spreadsheetGetSheet.mockResolvedValue({
|
||||
title: 'Sheet1',
|
||||
});
|
||||
mockGoogleSheetInstance.getData.mockResolvedValue([['Header1', 'Header2', 'Header3']]);
|
||||
mockGoogleSheetInstance.testFilter.mockReturnValue(['Header1', 'Header2', 'Header3']);
|
||||
|
||||
const result = await getSheetHeaderRow.call(
|
||||
mockLoadOptionsFunctions as ILoadOptionsFunctions,
|
||||
);
|
||||
expect(result).toEqual([
|
||||
{ name: 'Header1', value: 'Header1' },
|
||||
{ name: 'Header2', value: 'Header2' },
|
||||
{ name: 'Header3', value: 'Header3' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSheetHeaderRowAndAddColumn', () => {
|
||||
it('should add a new column and exclude the column to match on', async () => {
|
||||
mockGoogleSheetInstance.spreadsheetGetSheet.mockResolvedValue({
|
||||
title: 'Sheet1',
|
||||
});
|
||||
mockGoogleSheetInstance.getData.mockResolvedValue([['Header1']]);
|
||||
mockGoogleSheetInstance.testFilter.mockReturnValue(['Header1']);
|
||||
|
||||
const result = await getSheetHeaderRowAndAddColumn.call(
|
||||
mockLoadOptionsFunctions as ILoadOptionsFunctions,
|
||||
);
|
||||
|
||||
expect(result).toEqual([
|
||||
{ name: 'Header1', value: 'Header1' },
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
|
||||
{ name: 'New column ...', value: 'newColumn' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSheetHeaderRowWithGeneratedColumnNames', () => {
|
||||
it('should generate column names for empty values', async () => {
|
||||
mockGoogleSheetInstance.spreadsheetGetSheet.mockResolvedValue({
|
||||
title: 'Sheet1',
|
||||
});
|
||||
mockGoogleSheetInstance.getData.mockResolvedValue([['', 'Header1', '']]);
|
||||
mockGoogleSheetInstance.testFilter.mockReturnValue(['', 'Header1', '']);
|
||||
|
||||
const result = await getSheetHeaderRowWithGeneratedColumnNames.call(
|
||||
mockLoadOptionsFunctions as ILoadOptionsFunctions,
|
||||
);
|
||||
|
||||
expect(result).toEqual([
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
|
||||
{ name: 'col_1', value: 'col_1' },
|
||||
{ name: 'Header1', value: 'Header1' },
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
|
||||
{ name: 'col_3', value: 'col_3' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSheetHeaderRowAndSkipEmpty', () => {
|
||||
it('should skip columns with empty values', async () => {
|
||||
mockGoogleSheetInstance.spreadsheetGetSheet.mockResolvedValue({
|
||||
title: 'Sheet1',
|
||||
});
|
||||
mockGoogleSheetInstance.getData.mockResolvedValue([['', 'Header1', '']]);
|
||||
mockGoogleSheetInstance.testFilter.mockReturnValue(['', 'Header1', '']);
|
||||
|
||||
const result = await getSheetHeaderRowAndSkipEmpty.call(
|
||||
mockLoadOptionsFunctions as ILoadOptionsFunctions,
|
||||
);
|
||||
|
||||
expect(result).toEqual([{ name: 'Header1', value: 'Header1' }]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,113 @@
|
||||
import type { MockProxy } from 'jest-mock-extended';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { ILoadOptionsFunctions, INode } from 'n8n-workflow';
|
||||
|
||||
import { getMappingColumns } from '../../../v2/methods/resourceMapping';
|
||||
|
||||
jest.mock('../../../v2/helpers/GoogleSheets.utils');
|
||||
|
||||
const mockGoogleSheetInstance = {
|
||||
spreadsheetGetSheets: jest.fn(),
|
||||
spreadsheetGetSheet: jest.fn(),
|
||||
getData: jest.fn(),
|
||||
testFilter: jest.fn(),
|
||||
};
|
||||
|
||||
jest.mock('../../../v2/helpers/GoogleSheet', () => ({
|
||||
GoogleSheet: jest.fn().mockImplementation(() => mockGoogleSheetInstance),
|
||||
}));
|
||||
|
||||
describe('Google Sheets, getMappingColumns', () => {
|
||||
let loadOptionsFunctions: MockProxy<ILoadOptionsFunctions>;
|
||||
|
||||
beforeEach(() => {
|
||||
loadOptionsFunctions = mock<ILoadOptionsFunctions>();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should map columns and add row number for update operation', async () => {
|
||||
loadOptionsFunctions.getNode.mockReturnValue({} as INode);
|
||||
loadOptionsFunctions.getNodeParameter
|
||||
.mockReturnValueOnce({ mode: 'id', value: 'spreadsheetId' }) // documentId
|
||||
.mockReturnValueOnce({ mode: 'name', value: 'Sheet1' }) // sheetName
|
||||
.mockReturnValueOnce({ mode: 'name' }) // sheetName mode
|
||||
.mockReturnValueOnce({}) // options.locationDefine.values
|
||||
.mockReturnValueOnce('update'); // operation
|
||||
|
||||
mockGoogleSheetInstance.spreadsheetGetSheet.mockResolvedValueOnce({
|
||||
title: 'Sheet1',
|
||||
sheetId: 1,
|
||||
});
|
||||
mockGoogleSheetInstance.getData.mockResolvedValueOnce([['id', 'name', 'email']]);
|
||||
mockGoogleSheetInstance.testFilter.mockReturnValueOnce(['id', 'name', 'email']);
|
||||
|
||||
const result = await getMappingColumns.call(loadOptionsFunctions);
|
||||
|
||||
expect(result.fields).toHaveLength(4);
|
||||
expect(result.fields).toEqual([
|
||||
{
|
||||
canBeUsedToMatch: true,
|
||||
defaultMatch: true,
|
||||
display: true,
|
||||
displayName: 'id',
|
||||
id: 'id',
|
||||
required: false,
|
||||
type: 'string',
|
||||
},
|
||||
{
|
||||
canBeUsedToMatch: true,
|
||||
defaultMatch: false,
|
||||
display: true,
|
||||
displayName: 'name',
|
||||
id: 'name',
|
||||
required: false,
|
||||
type: 'string',
|
||||
},
|
||||
{
|
||||
canBeUsedToMatch: true,
|
||||
defaultMatch: false,
|
||||
display: true,
|
||||
displayName: 'email',
|
||||
id: 'email',
|
||||
required: false,
|
||||
type: 'string',
|
||||
},
|
||||
{
|
||||
canBeUsedToMatch: true,
|
||||
defaultMatch: false,
|
||||
display: true,
|
||||
displayName: 'row_number',
|
||||
id: 'row_number',
|
||||
readOnly: true,
|
||||
removed: true,
|
||||
required: false,
|
||||
type: 'number',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should map columns and add row number for appendOrUpdate operation', async () => {
|
||||
loadOptionsFunctions.getNode.mockReturnValue({} as INode);
|
||||
loadOptionsFunctions.getNodeParameter
|
||||
.mockReturnValueOnce({ mode: 'id', value: 'spreadsheetId' }) // documentId
|
||||
.mockReturnValueOnce({ mode: 'name', value: 'Sheet1' }) // sheetName
|
||||
.mockReturnValueOnce({ mode: 'name' }) // sheetName mode
|
||||
.mockReturnValueOnce({ headerRow: 10 }) // options.locationDefine.values
|
||||
.mockReturnValueOnce('appendOrUpdate'); // operation
|
||||
|
||||
mockGoogleSheetInstance.spreadsheetGetSheet.mockResolvedValueOnce({
|
||||
title: 'Sheet1',
|
||||
sheetId: 1,
|
||||
});
|
||||
mockGoogleSheetInstance.getData.mockResolvedValueOnce([['id', 'name', 'email']]);
|
||||
mockGoogleSheetInstance.testFilter.mockReturnValueOnce(['id', 'name', 'email']);
|
||||
|
||||
const result = await getMappingColumns.call(loadOptionsFunctions);
|
||||
|
||||
expect(result.fields).toHaveLength(3);
|
||||
expect(mockGoogleSheetInstance.getData).toHaveBeenCalledWith('Sheet1!10:10', 'FORMATTED_VALUE');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user