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,84 @@
|
||||
import type { IExecuteSingleFunctions, IHttpRequestOptions } from 'n8n-workflow';
|
||||
|
||||
import { addUpdateMaskPresend } from '../GenericFunctions';
|
||||
|
||||
describe('GenericFunctions - addUpdateMask', () => {
|
||||
const mockGetNodeParameter = jest.fn();
|
||||
|
||||
const mockContext = {
|
||||
getNodeParameter: mockGetNodeParameter,
|
||||
} as unknown as IExecuteSingleFunctions;
|
||||
|
||||
beforeEach(() => {
|
||||
mockGetNodeParameter.mockClear();
|
||||
});
|
||||
|
||||
it('should add updateMask with mapped properties to the query string', async () => {
|
||||
mockGetNodeParameter.mockReturnValue({
|
||||
postType: 'postTypeValue',
|
||||
url: 'https://example.com',
|
||||
startDateTime: '2023-09-15T10:00:00.000Z',
|
||||
couponCode: 'DISCOUNT123',
|
||||
});
|
||||
|
||||
const opts: Partial<IHttpRequestOptions> = {
|
||||
qs: {},
|
||||
};
|
||||
|
||||
const result = await addUpdateMaskPresend.call(mockContext, opts as IHttpRequestOptions);
|
||||
|
||||
expect(result.qs).toEqual({
|
||||
updateMask:
|
||||
'topicType,callToAction.url,event.schedule.startDate,event.schedule.startTime,offer.couponCode',
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle empty additionalOptions and not add updateMask', async () => {
|
||||
mockGetNodeParameter.mockReturnValue({});
|
||||
|
||||
const opts: Partial<IHttpRequestOptions> = {
|
||||
qs: {},
|
||||
};
|
||||
|
||||
const result = await addUpdateMaskPresend.call(mockContext, opts as IHttpRequestOptions);
|
||||
|
||||
expect(result.qs).toEqual({});
|
||||
});
|
||||
|
||||
it('should include unmapped properties in the updateMask', async () => {
|
||||
mockGetNodeParameter.mockReturnValue({
|
||||
postType: 'postTypeValue',
|
||||
unmappedProperty: 'someValue',
|
||||
});
|
||||
|
||||
const opts: Partial<IHttpRequestOptions> = {
|
||||
qs: {},
|
||||
};
|
||||
|
||||
const result = await addUpdateMaskPresend.call(mockContext, opts as IHttpRequestOptions);
|
||||
|
||||
expect(result.qs).toEqual({
|
||||
updateMask: 'topicType,unmappedProperty',
|
||||
});
|
||||
});
|
||||
|
||||
it('should merge updateMask with existing query string', async () => {
|
||||
mockGetNodeParameter.mockReturnValue({
|
||||
postType: 'postTypeValue',
|
||||
redeemOnlineUrl: 'https://google.example.com',
|
||||
});
|
||||
|
||||
const opts: Partial<IHttpRequestOptions> = {
|
||||
qs: {
|
||||
existingQuery: 'existingValue',
|
||||
},
|
||||
};
|
||||
|
||||
const result = await addUpdateMaskPresend.call(mockContext, opts as IHttpRequestOptions);
|
||||
|
||||
expect(result.qs).toEqual({
|
||||
existingQuery: 'existingValue',
|
||||
updateMask: 'topicType,offer.redeemOnlineUrl',
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,84 @@
|
||||
import { NodeApiError, type ILoadOptionsFunctions, type IPollFunctions } from 'n8n-workflow';
|
||||
|
||||
import { googleApiRequest } from '../GenericFunctions';
|
||||
|
||||
describe('googleApiRequest', () => {
|
||||
const mockHttpRequestWithAuthentication = jest.fn();
|
||||
const mockContext = {
|
||||
helpers: {
|
||||
httpRequestWithAuthentication: mockHttpRequestWithAuthentication,
|
||||
},
|
||||
getNode: jest.fn(),
|
||||
} as unknown as ILoadOptionsFunctions | IPollFunctions;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should make a GET request and return data', async () => {
|
||||
const mockResponse = { success: true };
|
||||
mockHttpRequestWithAuthentication.mockResolvedValue(mockResponse);
|
||||
|
||||
const result = await googleApiRequest.call(mockContext, 'GET', '/test-resource');
|
||||
|
||||
expect(mockHttpRequestWithAuthentication).toHaveBeenCalledWith(
|
||||
'googleBusinessProfileOAuth2Api',
|
||||
expect.objectContaining({
|
||||
method: 'GET',
|
||||
url: 'https://mybusiness.googleapis.com/v4/test-resource',
|
||||
qs: {},
|
||||
json: true,
|
||||
}),
|
||||
);
|
||||
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
it('should make a POST request with body and return data', async () => {
|
||||
const mockResponse = { success: true };
|
||||
mockHttpRequestWithAuthentication.mockResolvedValue(mockResponse);
|
||||
|
||||
const requestBody = { key: 'value' };
|
||||
const result = await googleApiRequest.call(mockContext, 'POST', '/test-resource', requestBody);
|
||||
|
||||
expect(mockHttpRequestWithAuthentication).toHaveBeenCalledWith(
|
||||
'googleBusinessProfileOAuth2Api',
|
||||
expect.objectContaining({
|
||||
method: 'POST',
|
||||
body: requestBody,
|
||||
url: 'https://mybusiness.googleapis.com/v4/test-resource',
|
||||
qs: {},
|
||||
json: true,
|
||||
}),
|
||||
);
|
||||
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
it('should remove the body for GET requests', async () => {
|
||||
const mockResponse = { success: true };
|
||||
mockHttpRequestWithAuthentication.mockResolvedValue(mockResponse);
|
||||
|
||||
const result = await googleApiRequest.call(mockContext, 'GET', '/test-resource', {});
|
||||
|
||||
expect(mockHttpRequestWithAuthentication).toHaveBeenCalledWith(
|
||||
'googleBusinessProfileOAuth2Api',
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
expect.not.objectContaining({ body: expect.anything() }),
|
||||
);
|
||||
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
it('should throw NodeApiError on API failure', async () => {
|
||||
const mockError = new Error('API request failed');
|
||||
mockHttpRequestWithAuthentication.mockRejectedValue(mockError);
|
||||
|
||||
await expect(googleApiRequest.call(mockContext, 'GET', '/test-resource')).rejects.toThrow(
|
||||
NodeApiError,
|
||||
);
|
||||
|
||||
expect(mockContext.getNode).toHaveBeenCalled();
|
||||
expect(mockHttpRequestWithAuthentication).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,131 @@
|
||||
import type { IExecuteSingleFunctions, IHttpRequestOptions } from 'n8n-workflow';
|
||||
|
||||
import { handleDatesPresend } from '../GenericFunctions';
|
||||
|
||||
describe('GenericFunctions - handleDatesPresend', () => {
|
||||
const mockGetNode = jest.fn();
|
||||
const mockGetNodeParameter = jest.fn();
|
||||
|
||||
const mockContext = {
|
||||
getNode: mockGetNode,
|
||||
getNodeParameter: mockGetNodeParameter,
|
||||
} as unknown as IExecuteSingleFunctions;
|
||||
|
||||
beforeEach(() => {
|
||||
mockGetNode.mockClear();
|
||||
mockGetNodeParameter.mockClear();
|
||||
});
|
||||
|
||||
it('should return options unchanged if no date-time parameters are provided', async () => {
|
||||
mockGetNode.mockReturnValue({
|
||||
parameters: {},
|
||||
});
|
||||
mockGetNodeParameter.mockReturnValue({});
|
||||
|
||||
const opts: Partial<IHttpRequestOptions> = {
|
||||
body: {},
|
||||
};
|
||||
|
||||
const result = await handleDatesPresend.call(mockContext, opts as IHttpRequestOptions);
|
||||
|
||||
expect(result).toEqual(opts);
|
||||
});
|
||||
|
||||
it('should merge startDateTime parameter into event schedule', async () => {
|
||||
mockGetNode.mockReturnValue({
|
||||
parameters: {
|
||||
startDateTime: '2023-09-15T10:00:00.000Z',
|
||||
},
|
||||
});
|
||||
mockGetNodeParameter.mockReturnValue({});
|
||||
|
||||
const opts: Partial<IHttpRequestOptions> = {
|
||||
body: {},
|
||||
};
|
||||
|
||||
const result = await handleDatesPresend.call(mockContext, opts as IHttpRequestOptions);
|
||||
|
||||
expect(result.body).toEqual({
|
||||
event: {
|
||||
schedule: {
|
||||
startDate: { year: 2023, month: 9, day: 15 },
|
||||
startTime: { hours: 10, minutes: 0, seconds: 0, nanos: 0 },
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should merge startDate and endDateTime parameters into event schedule', async () => {
|
||||
mockGetNode.mockReturnValue({
|
||||
parameters: {
|
||||
startDate: '2023-09-15',
|
||||
endDateTime: '2023-09-16T12:30:00.000Z',
|
||||
},
|
||||
});
|
||||
mockGetNodeParameter.mockReturnValue({});
|
||||
|
||||
const opts: Partial<IHttpRequestOptions> = {
|
||||
body: {},
|
||||
};
|
||||
|
||||
const result = await handleDatesPresend.call(mockContext, opts as IHttpRequestOptions);
|
||||
|
||||
expect(result.body).toEqual({
|
||||
event: {
|
||||
schedule: {
|
||||
startDate: { year: 2023, month: 9, day: 15 },
|
||||
endDate: { year: 2023, month: 9, day: 16 },
|
||||
endTime: { hours: 12, minutes: 30, seconds: 0, nanos: 0 },
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should merge additional options into event schedule', async () => {
|
||||
mockGetNode.mockReturnValue({
|
||||
parameters: {
|
||||
startDate: '2023-09-15',
|
||||
},
|
||||
});
|
||||
mockGetNodeParameter.mockReturnValue({
|
||||
additionalOption: 'someValue',
|
||||
});
|
||||
|
||||
const opts: Partial<IHttpRequestOptions> = {
|
||||
body: {},
|
||||
};
|
||||
|
||||
const result = await handleDatesPresend.call(mockContext, opts as IHttpRequestOptions);
|
||||
|
||||
expect(result.body).toEqual({
|
||||
event: {
|
||||
schedule: {
|
||||
startDate: { year: 2023, month: 9, day: 15 },
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should modify the body with event schedule containing only date', async () => {
|
||||
mockGetNode.mockReturnValue({
|
||||
parameters: {
|
||||
startDate: '2023-09-15',
|
||||
},
|
||||
});
|
||||
mockGetNodeParameter.mockReturnValue({});
|
||||
|
||||
const opts: Partial<IHttpRequestOptions> = {
|
||||
body: { event: {} },
|
||||
};
|
||||
|
||||
const result = await handleDatesPresend.call(mockContext, opts as IHttpRequestOptions);
|
||||
|
||||
expect(result.body).toEqual({
|
||||
event: {
|
||||
schedule: {
|
||||
startDate: { year: 2023, month: 9, day: 15 },
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,123 @@
|
||||
import type { DeclarativeRestApiSettings, IExecutePaginationFunctions } from 'n8n-workflow';
|
||||
|
||||
import { handlePagination } from '../GenericFunctions';
|
||||
|
||||
describe('GenericFunctions - handlePagination', () => {
|
||||
const mockMakeRoutingRequest = jest.fn();
|
||||
const mockGetNodeParameter = jest.fn();
|
||||
|
||||
const mockContext = {
|
||||
makeRoutingRequest: mockMakeRoutingRequest,
|
||||
getNodeParameter: mockGetNodeParameter,
|
||||
} as unknown as IExecutePaginationFunctions;
|
||||
|
||||
beforeEach(() => {
|
||||
mockMakeRoutingRequest.mockClear();
|
||||
mockGetNodeParameter.mockClear();
|
||||
});
|
||||
|
||||
it('should stop fetching when the limit is reached and returnAll is false', async () => {
|
||||
mockMakeRoutingRequest
|
||||
.mockResolvedValueOnce([
|
||||
{
|
||||
json: {
|
||||
localPosts: [{ id: 1 }, { id: 2 }],
|
||||
nextPageToken: 'nextToken1',
|
||||
},
|
||||
},
|
||||
])
|
||||
.mockResolvedValueOnce([
|
||||
{
|
||||
json: {
|
||||
localPosts: [{ id: 3 }, { id: 4 }],
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
mockGetNodeParameter.mockReturnValueOnce(false);
|
||||
mockGetNodeParameter.mockReturnValueOnce(3);
|
||||
|
||||
const requestOptions = {
|
||||
options: {
|
||||
qs: {},
|
||||
},
|
||||
} as unknown as DeclarativeRestApiSettings.ResultOptions;
|
||||
|
||||
const result = await handlePagination.call(mockContext, requestOptions);
|
||||
|
||||
expect(mockMakeRoutingRequest).toHaveBeenCalledTimes(2);
|
||||
expect(result).toEqual([{ json: { id: 1 } }, { json: { id: 2 } }, { json: { id: 3 } }]);
|
||||
});
|
||||
|
||||
it('should handle empty results', async () => {
|
||||
mockMakeRoutingRequest.mockResolvedValueOnce([
|
||||
{
|
||||
json: {
|
||||
localPosts: [],
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
mockGetNodeParameter.mockReturnValueOnce(false);
|
||||
mockGetNodeParameter.mockReturnValueOnce(5);
|
||||
|
||||
const requestOptions = {
|
||||
options: {
|
||||
qs: {},
|
||||
},
|
||||
} as unknown as DeclarativeRestApiSettings.ResultOptions;
|
||||
|
||||
const result = await handlePagination.call(mockContext, requestOptions);
|
||||
|
||||
expect(mockMakeRoutingRequest).toHaveBeenCalledTimes(1);
|
||||
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
it('should fetch all items when returnAll is true', async () => {
|
||||
mockMakeRoutingRequest
|
||||
.mockResolvedValueOnce([
|
||||
{
|
||||
json: {
|
||||
localPosts: [{ id: 1 }, { id: 2 }],
|
||||
nextPageToken: 'nextToken1',
|
||||
},
|
||||
},
|
||||
])
|
||||
.mockResolvedValueOnce([
|
||||
{
|
||||
json: {
|
||||
localPosts: [{ id: 3 }, { id: 4 }],
|
||||
nextPageToken: 'nextToken2',
|
||||
},
|
||||
},
|
||||
])
|
||||
.mockResolvedValueOnce([
|
||||
{
|
||||
json: {
|
||||
localPosts: [{ id: 5 }],
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
mockGetNodeParameter.mockReturnValueOnce(true);
|
||||
|
||||
const requestOptions = {
|
||||
options: {
|
||||
qs: {},
|
||||
},
|
||||
} as unknown as DeclarativeRestApiSettings.ResultOptions;
|
||||
|
||||
const result = await handlePagination.call(mockContext, requestOptions);
|
||||
|
||||
expect(mockMakeRoutingRequest).toHaveBeenCalledTimes(3);
|
||||
|
||||
expect(result).toEqual([
|
||||
{ json: { id: 1 } },
|
||||
{ json: { id: 2 } },
|
||||
{ json: { id: 3 } },
|
||||
{ json: { id: 4 } },
|
||||
{ json: { id: 5 } },
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
import type { ILoadOptionsFunctions } from 'n8n-workflow';
|
||||
|
||||
import { searchAccounts } from '../GenericFunctions';
|
||||
|
||||
describe('GenericFunctions - searchAccounts', () => {
|
||||
const mockGoogleApiRequest = jest.fn();
|
||||
|
||||
const mockContext = {
|
||||
helpers: {
|
||||
httpRequestWithAuthentication: mockGoogleApiRequest,
|
||||
},
|
||||
} as unknown as ILoadOptionsFunctions;
|
||||
|
||||
beforeEach(() => {
|
||||
mockGoogleApiRequest.mockClear();
|
||||
});
|
||||
|
||||
it('should return accounts with filtering', async () => {
|
||||
mockGoogleApiRequest.mockResolvedValue({
|
||||
accounts: [
|
||||
{ name: 'accounts/123', accountName: 'Test Account 1' },
|
||||
{ name: 'accounts/234', accountName: 'Test Account 2' },
|
||||
],
|
||||
});
|
||||
|
||||
const filter = '123';
|
||||
const result = await searchAccounts.call(mockContext, filter);
|
||||
|
||||
expect(result).toEqual({
|
||||
results: [{ name: 'Test Account 1', value: 'accounts/123' }],
|
||||
paginationToken: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle empty results', async () => {
|
||||
mockGoogleApiRequest.mockResolvedValue({ accounts: [] });
|
||||
|
||||
const result = await searchAccounts.call(mockContext);
|
||||
|
||||
expect(result).toEqual({ results: [], paginationToken: undefined });
|
||||
});
|
||||
|
||||
it('should handle pagination', async () => {
|
||||
mockGoogleApiRequest.mockResolvedValue({
|
||||
accounts: [{ name: 'accounts/123', accountName: 'Test Account 1' }],
|
||||
nextPageToken: 'nextToken1',
|
||||
});
|
||||
mockGoogleApiRequest.mockResolvedValue({
|
||||
accounts: [{ name: 'accounts/234', accountName: 'Test Account 2' }],
|
||||
nextPageToken: 'nextToken2',
|
||||
});
|
||||
mockGoogleApiRequest.mockResolvedValue({
|
||||
accounts: [{ name: 'accounts/345', accountName: 'Test Account 3' }],
|
||||
});
|
||||
|
||||
const result = await searchAccounts.call(mockContext);
|
||||
|
||||
// The request would only return the last result
|
||||
// N8N handles the pagination and adds the previous results to the results array
|
||||
expect(result).toEqual({
|
||||
results: [{ name: 'Test Account 3', value: 'accounts/345' }],
|
||||
paginationToken: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,68 @@
|
||||
import type { ILoadOptionsFunctions } from 'n8n-workflow';
|
||||
|
||||
import { searchLocations } from '../GenericFunctions';
|
||||
|
||||
describe('GenericFunctions - searchLocations', () => {
|
||||
const mockGoogleApiRequest = jest.fn();
|
||||
const mockGetNodeParameter = jest.fn();
|
||||
|
||||
const mockContext = {
|
||||
helpers: {
|
||||
httpRequestWithAuthentication: mockGoogleApiRequest,
|
||||
},
|
||||
getNodeParameter: mockGetNodeParameter,
|
||||
} as unknown as ILoadOptionsFunctions;
|
||||
|
||||
beforeEach(() => {
|
||||
mockGoogleApiRequest.mockClear();
|
||||
mockGetNodeParameter.mockClear();
|
||||
mockGetNodeParameter.mockReturnValue('parameterValue');
|
||||
});
|
||||
|
||||
it('should return locations with filtering', async () => {
|
||||
mockGoogleApiRequest.mockResolvedValue({
|
||||
locations: [{ name: 'locations/123' }, { name: 'locations/234' }],
|
||||
});
|
||||
|
||||
const filter = '123';
|
||||
const result = await searchLocations.call(mockContext, filter);
|
||||
|
||||
expect(result).toEqual({
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
|
||||
results: [{ name: 'locations/123', value: 'locations/123' }],
|
||||
paginationToken: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle empty results', async () => {
|
||||
mockGoogleApiRequest.mockResolvedValue({ locations: [] });
|
||||
|
||||
const result = await searchLocations.call(mockContext);
|
||||
|
||||
expect(result).toEqual({ results: [], paginationToken: undefined });
|
||||
});
|
||||
|
||||
it('should handle pagination', async () => {
|
||||
mockGoogleApiRequest.mockResolvedValue({
|
||||
locations: [{ name: 'locations/123' }],
|
||||
nextPageToken: 'nextToken1',
|
||||
});
|
||||
mockGoogleApiRequest.mockResolvedValue({
|
||||
locations: [{ name: 'locations/234' }],
|
||||
nextPageToken: 'nextToken2',
|
||||
});
|
||||
mockGoogleApiRequest.mockResolvedValue({
|
||||
locations: [{ name: 'locations/345' }],
|
||||
});
|
||||
|
||||
const result = await searchLocations.call(mockContext);
|
||||
|
||||
// The request would only return the last result
|
||||
// N8N handles the pagination and adds the previous results to the results array
|
||||
expect(result).toEqual({
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
|
||||
results: [{ name: 'locations/345', value: 'locations/345' }],
|
||||
paginationToken: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
import type { ILoadOptionsFunctions } from 'n8n-workflow';
|
||||
|
||||
import { searchPosts } from '../GenericFunctions';
|
||||
|
||||
describe('GenericFunctions - searchPosts', () => {
|
||||
const mockGoogleApiRequest = jest.fn();
|
||||
const mockGetNodeParameter = jest.fn();
|
||||
|
||||
const mockContext = {
|
||||
helpers: {
|
||||
httpRequestWithAuthentication: mockGoogleApiRequest,
|
||||
},
|
||||
getNodeParameter: mockGetNodeParameter,
|
||||
} as unknown as ILoadOptionsFunctions;
|
||||
|
||||
beforeEach(() => {
|
||||
mockGoogleApiRequest.mockClear();
|
||||
mockGetNodeParameter.mockClear();
|
||||
mockGetNodeParameter.mockReturnValue('parameterValue');
|
||||
});
|
||||
|
||||
it('should return posts with filtering', async () => {
|
||||
mockGoogleApiRequest.mockResolvedValue({
|
||||
localPosts: [
|
||||
{ name: 'accounts/123/locations/123/localPosts/123', summary: 'First Post' },
|
||||
{ name: 'accounts/123/locations/123/localPosts/234', summary: 'Second Post' },
|
||||
],
|
||||
});
|
||||
|
||||
const filter = 'First';
|
||||
const result = await searchPosts.call(mockContext, filter);
|
||||
|
||||
expect(result).toEqual({
|
||||
results: [
|
||||
{
|
||||
name: 'First Post',
|
||||
value: 'accounts/123/locations/123/localPosts/123',
|
||||
},
|
||||
],
|
||||
paginationToken: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle empty results', async () => {
|
||||
mockGoogleApiRequest.mockResolvedValue({ localPosts: [] });
|
||||
|
||||
const result = await searchPosts.call(mockContext);
|
||||
|
||||
expect(result).toEqual({ results: [], paginationToken: undefined });
|
||||
});
|
||||
|
||||
it('should handle pagination', async () => {
|
||||
mockGoogleApiRequest.mockResolvedValue({
|
||||
localPosts: [{ name: 'accounts/123/locations/123/localPosts/123', summary: 'First Post' }],
|
||||
nextPageToken: 'nextToken1',
|
||||
});
|
||||
mockGoogleApiRequest.mockResolvedValue({
|
||||
localPosts: [{ name: 'accounts/123/locations/123/localPosts/234', summary: 'Second Post' }],
|
||||
nextPageToken: 'nextToken2',
|
||||
});
|
||||
mockGoogleApiRequest.mockResolvedValue({
|
||||
localPosts: [{ name: 'accounts/123/locations/123/localPosts/345', summary: 'Third Post' }],
|
||||
});
|
||||
|
||||
const result = await searchPosts.call(mockContext);
|
||||
|
||||
expect(result).toEqual({
|
||||
results: [{ name: 'Third Post', value: 'accounts/123/locations/123/localPosts/345' }],
|
||||
paginationToken: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
/* eslint-disable n8n-nodes-base/node-param-display-name-miscased */
|
||||
import type { ILoadOptionsFunctions } from 'n8n-workflow';
|
||||
|
||||
import { searchReviews } from '../GenericFunctions';
|
||||
|
||||
describe('GenericFunctions - searchReviews', () => {
|
||||
const mockGoogleApiRequest = jest.fn();
|
||||
const mockGetNodeParameter = jest.fn();
|
||||
|
||||
const mockContext = {
|
||||
helpers: {
|
||||
httpRequestWithAuthentication: mockGoogleApiRequest,
|
||||
},
|
||||
getNodeParameter: mockGetNodeParameter,
|
||||
} as unknown as ILoadOptionsFunctions;
|
||||
|
||||
beforeEach(() => {
|
||||
mockGoogleApiRequest.mockClear();
|
||||
mockGetNodeParameter.mockClear();
|
||||
mockGetNodeParameter.mockReturnValue('parameterValue');
|
||||
});
|
||||
|
||||
it('should return reviews with filtering', async () => {
|
||||
mockGoogleApiRequest.mockResolvedValue({
|
||||
reviews: [
|
||||
{ name: 'accounts/123/locations/123/reviews/123', comment: 'Great service!' },
|
||||
{ name: 'accounts/123/locations/123/reviews/234', comment: 'Good experience.' },
|
||||
],
|
||||
});
|
||||
|
||||
const filter = 'Great';
|
||||
const result = await searchReviews.call(mockContext, filter);
|
||||
|
||||
expect(result).toEqual({
|
||||
results: [
|
||||
{
|
||||
name: 'Great service!',
|
||||
value: 'accounts/123/locations/123/reviews/123',
|
||||
},
|
||||
],
|
||||
paginationToken: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle empty results', async () => {
|
||||
mockGoogleApiRequest.mockResolvedValue({ reviews: [] });
|
||||
|
||||
const result = await searchReviews.call(mockContext);
|
||||
|
||||
expect(result).toEqual({ results: [], paginationToken: undefined });
|
||||
});
|
||||
|
||||
it('should handle pagination', async () => {
|
||||
mockGoogleApiRequest.mockResolvedValue({
|
||||
reviews: [{ name: 'accounts/123/locations/123/reviews/123', comment: 'First Review' }],
|
||||
nextPageToken: 'nextToken1',
|
||||
});
|
||||
mockGoogleApiRequest.mockResolvedValue({
|
||||
reviews: [{ name: 'accounts/123/locations/123/reviews/234', comment: 'Second Review' }],
|
||||
nextPageToken: 'nextToken2',
|
||||
});
|
||||
mockGoogleApiRequest.mockResolvedValue({
|
||||
reviews: [{ name: 'accounts/123/locations/123/reviews/345', comment: 'Third Review' }],
|
||||
});
|
||||
|
||||
const result = await searchReviews.call(mockContext);
|
||||
|
||||
expect(result).toEqual({
|
||||
results: [{ name: 'Third Review', value: 'accounts/123/locations/123/reviews/345' }],
|
||||
paginationToken: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user