n8n-nodes-innotes
Version:
N8N node for InNotes CRM API integration
145 lines (143 loc) • 6.33 kB
JavaScript
"use strict";
/**
* Author: marco
* Last updated: 2025-05-30
*/
Object.defineProperty(exports, "__esModule", { value: true });
const InNotes_node_1 = require("../nodes/InNotes/InNotes.node");
describe('InNotes Node', () => {
let node;
let mockExecuteFunctions;
beforeEach(() => {
node = new InNotes_node_1.InNotes();
mockExecuteFunctions = {
getInputData: jest.fn().mockReturnValue([{ json: {} }]),
getNodeParameter: jest.fn(),
getCredentials: jest.fn().mockResolvedValue({
username: 'test@example.com',
password: 'testpassword',
baseUrl: 'https://test.innotes.com',
}),
helpers: {
httpRequestWithAuthentication: jest.fn(),
httpRequest: jest.fn(),
requestWithAuthenticationPaginated: jest.fn(),
request: jest.fn(),
requestWithAuthentication: jest.fn(),
requestOAuth2: jest.fn(),
requestOAuth1: jest.fn(),
},
};
});
describe('Node Properties', () => {
it('should have correct description', () => {
expect(node.description.displayName).toBe('InNotes');
expect(node.description.name).toBe('inNotes');
expect(node.description.group).toEqual(['transform']);
expect(node.description.version).toBe(1);
});
it('should have correct credentials', () => {
expect(node.description.credentials).toEqual([
{
name: 'inNotesApi',
required: true,
},
]);
});
it('should have correct inputs and outputs', () => {
expect(node.description.inputs).toEqual(['main']);
expect(node.description.outputs).toEqual(['main']);
});
});
describe('Resource Operations', () => {
it('should have contact resource with correct operations', () => {
var _a, _b;
const contactResource = (_a = node.description.properties) === null || _a === void 0 ? void 0 : _a.find(prop => prop.name === 'resource' && prop.type === 'options');
expect(contactResource).toBeDefined();
const contactOption = (_b = contactResource === null || contactResource === void 0 ? void 0 : contactResource.options) === null || _b === void 0 ? void 0 : _b.find((option) => option.value === 'contact');
expect(contactOption).toBeDefined();
expect(contactOption.name).toBe('Contact');
});
it('should have note resource with correct operations', () => {
var _a, _b;
const noteResource = (_a = node.description.properties) === null || _a === void 0 ? void 0 : _a.find(prop => prop.name === 'resource' && prop.type === 'options');
expect(noteResource).toBeDefined();
const noteOption = (_b = noteResource === null || noteResource === void 0 ? void 0 : noteResource.options) === null || _b === void 0 ? void 0 : _b.find((option) => option.value === 'note');
expect(noteOption).toBeDefined();
expect(noteOption.name).toBe('Note');
});
});
describe('Execute Method', () => {
it('should handle contact get operation', async () => {
const mockHttpRequest = jest.fn().mockResolvedValue({
data: {
id: 1,
name: 'Test Contact',
email: 'test@example.com',
},
});
mockExecuteFunctions.helpers.httpRequestWithAuthentication = mockHttpRequest;
mockExecuteFunctions.getNodeParameter = jest.fn()
.mockReturnValueOnce('contact') // resource
.mockReturnValueOnce('get') // operation
.mockReturnValueOnce(1); // contactId
const result = await node.execute.call(mockExecuteFunctions);
expect(mockHttpRequest).toHaveBeenCalledWith('inNotesApi', expect.objectContaining({
method: 'GET',
url: '/api/contacts/1',
}));
expect(result).toEqual([
[
{
json: {
id: 1,
name: 'Test Contact',
email: 'test@example.com',
},
},
],
]);
});
it('should handle note create operation', async () => {
const mockHttpRequest = jest.fn().mockResolvedValue({
data: {
id: 1,
content: 'Test note content',
contactId: 1,
},
});
mockExecuteFunctions.helpers.httpRequestWithAuthentication = mockHttpRequest;
mockExecuteFunctions.getNodeParameter = jest.fn()
.mockReturnValueOnce('note') // resource
.mockReturnValueOnce('create') // operation
.mockReturnValueOnce('Test note content') // content
.mockReturnValueOnce(1); // contactId
const result = await node.execute.call(mockExecuteFunctions);
expect(mockHttpRequest).toHaveBeenCalledWith('inNotesApi', expect.objectContaining({
method: 'POST',
url: '/api/note',
body: {
content: 'Test note content',
contactId: 1,
},
}));
expect(result).toEqual([
[
{
json: {
id: 1,
content: 'Test note content',
contactId: 1,
},
},
],
]);
});
it('should throw error for unsupported resource', async () => {
mockExecuteFunctions.getNodeParameter = jest.fn()
.mockReturnValueOnce('unsupported'); // resource
await expect(node.execute.call(mockExecuteFunctions)).rejects.toThrow('The resource "unsupported" is not known!');
});
});
});
//# sourceMappingURL=InNotes.node.test.js.map