mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(HighLevel Node): Add support for calendar items (#10820)
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
import { highLevelApiRequest } from '../GenericFunctions';
|
||||
|
||||
describe('GenericFunctions - highLevelApiRequest', () => {
|
||||
let mockContext: any;
|
||||
let mockHttpRequestWithAuthentication: jest.Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
mockHttpRequestWithAuthentication = jest.fn();
|
||||
mockContext = {
|
||||
helpers: {
|
||||
httpRequestWithAuthentication: mockHttpRequestWithAuthentication,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
test('should make a successful request with all parameters', async () => {
|
||||
const mockResponse = { success: true };
|
||||
mockHttpRequestWithAuthentication.mockResolvedValueOnce(mockResponse);
|
||||
|
||||
const method = 'POST';
|
||||
const resource = '/example-resource';
|
||||
const body = { key: 'value' };
|
||||
const qs = { query: 'test' };
|
||||
const url = 'https://custom-url.example.com/api';
|
||||
const option = { headers: { Authorization: 'Bearer test-token' } };
|
||||
|
||||
const result = await highLevelApiRequest.call(
|
||||
mockContext,
|
||||
method,
|
||||
resource,
|
||||
body,
|
||||
qs,
|
||||
url,
|
||||
option,
|
||||
);
|
||||
|
||||
expect(mockHttpRequestWithAuthentication).toHaveBeenCalledWith('highLevelOAuth2Api', {
|
||||
headers: { Authorization: 'Bearer test-token' },
|
||||
method: 'POST',
|
||||
body: { key: 'value' },
|
||||
qs: { query: 'test' },
|
||||
url: 'https://custom-url.example.com/api',
|
||||
json: true,
|
||||
});
|
||||
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
test('should default to the base URL when no custom URL is provided', async () => {
|
||||
const mockResponse = { success: true };
|
||||
mockHttpRequestWithAuthentication.mockResolvedValueOnce(mockResponse);
|
||||
|
||||
const method = 'GET';
|
||||
const resource = '/default-resource';
|
||||
|
||||
const result = await highLevelApiRequest.call(mockContext, method, resource);
|
||||
|
||||
expect(mockHttpRequestWithAuthentication).toHaveBeenCalledWith('highLevelOAuth2Api', {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Version: '2021-07-28',
|
||||
},
|
||||
method: 'GET',
|
||||
url: 'https://services.leadconnectorhq.com/default-resource',
|
||||
json: true,
|
||||
});
|
||||
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
test('should remove the body property if it is empty', async () => {
|
||||
const mockResponse = { success: true };
|
||||
mockHttpRequestWithAuthentication.mockResolvedValueOnce(mockResponse);
|
||||
|
||||
const method = 'DELETE';
|
||||
const resource = '/example-resource';
|
||||
const body = {};
|
||||
|
||||
const result = await highLevelApiRequest.call(mockContext, method, resource, body);
|
||||
|
||||
expect(mockHttpRequestWithAuthentication).toHaveBeenCalledWith('highLevelOAuth2Api', {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Version: '2021-07-28',
|
||||
},
|
||||
method: 'DELETE',
|
||||
url: 'https://services.leadconnectorhq.com/example-resource',
|
||||
json: true,
|
||||
});
|
||||
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
test('should remove the query string property if it is empty', async () => {
|
||||
const mockResponse = { success: true };
|
||||
mockHttpRequestWithAuthentication.mockResolvedValueOnce(mockResponse);
|
||||
|
||||
const method = 'PATCH';
|
||||
const resource = '/example-resource';
|
||||
const qs = {};
|
||||
|
||||
const result = await highLevelApiRequest.call(mockContext, method, resource, {}, qs);
|
||||
|
||||
expect(mockHttpRequestWithAuthentication).toHaveBeenCalledWith('highLevelOAuth2Api', {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Version: '2021-07-28',
|
||||
},
|
||||
method: 'PATCH',
|
||||
url: 'https://services.leadconnectorhq.com/example-resource',
|
||||
json: true,
|
||||
});
|
||||
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user