fix(QuickBooks Node): Initialize headers object in quickBooksApiRequest (#34291)

Co-authored-by: Prathamesh Hukkeri <prathamesh04@users.noreply.github.com>
This commit is contained in:
PRATHAMESH HUKKERI
2026-07-16 18:53:16 +05:30
committed by GitHub
parent cc0dec234b
commit 83dd194a89
2 changed files with 85 additions and 1 deletions
@@ -48,6 +48,7 @@ export async function quickBooksApiRequest(
qs,
body,
json: !isDownload,
headers: {},
};
if (!Object.keys(body).length) {
@@ -1,6 +1,89 @@
import { mockDeep } from 'vitest-mock-extended';
import type { IExecuteFunctions } from 'n8n-workflow';
import { processLines } from '../GenericFunctions';
import { processLines, quickBooksApiRequest } from '../GenericFunctions';
describe('quickBooksApiRequest', () => {
const mockExecuteFunctions = mockDeep<IExecuteFunctions>();
beforeEach(() => {
vi.resetAllMocks();
mockExecuteFunctions.getNodeParameter.mockReturnValue('invoice');
mockExecuteFunctions.getCredentials.mockResolvedValue({
environment: 'production',
});
});
it('should initialize headers for send operation', async () => {
mockExecuteFunctions.getNodeParameter
.mockReturnValueOnce('invoice')
.mockReturnValueOnce('send');
await quickBooksApiRequest.call(mockExecuteFunctions, 'POST', '/test', {}, {});
expect(mockExecuteFunctions.helpers.requestOAuth2).toHaveBeenCalledWith(
'quickBooksOAuth2Api',
expect.objectContaining({
headers: expect.objectContaining({
'Content-Type': 'application/octet-stream',
}),
}),
);
});
it('should initialize headers for void operation', async () => {
mockExecuteFunctions.getNodeParameter
.mockReturnValueOnce('invoice')
.mockReturnValueOnce('void');
await quickBooksApiRequest.call(mockExecuteFunctions, 'POST', '/test', {}, {});
expect(mockExecuteFunctions.helpers.requestOAuth2).toHaveBeenCalledWith(
'quickBooksOAuth2Api',
expect.objectContaining({
headers: expect.objectContaining({
'Content-Type': 'application/json',
}),
}),
);
});
it('should initialize headers for delete operation', async () => {
mockExecuteFunctions.getNodeParameter
.mockReturnValueOnce('payment')
.mockReturnValueOnce('delete');
await quickBooksApiRequest.call(mockExecuteFunctions, 'POST', '/test', {}, {});
expect(mockExecuteFunctions.helpers.requestOAuth2).toHaveBeenCalledWith(
'quickBooksOAuth2Api',
expect.objectContaining({
headers: expect.objectContaining({
'Content-Type': 'application/json',
}),
}),
);
});
it('should initialize headers for download operation', async () => {
mockExecuteFunctions.getNodeParameter
.mockReturnValueOnce('invoice')
.mockReturnValueOnce('get')
.mockReturnValueOnce(true);
await quickBooksApiRequest.call(mockExecuteFunctions, 'GET', '/test', {}, {});
expect(mockExecuteFunctions.helpers.requestOAuth2).toHaveBeenCalledWith(
'quickBooksOAuth2Api',
expect.objectContaining({
headers: expect.objectContaining({
Accept: 'application/pdf',
}),
}),
);
});
});
describe('processLines', () => {
const mockExecuteFunctions: Partial<IExecuteFunctions> = {
getNodeParameter: vi.fn(),