From a37054685fdc0eb06eb7f92dde54aea5d9685da5 Mon Sep 17 00:00:00 2001 From: czlonkowski <56956555+czlonkowski@users.noreply.github.com> Date: Mon, 28 Jul 2025 17:17:01 +0200 Subject: [PATCH] fix: resolve unhandled promise rejection in n8n-api-client tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixed simulateError helper to properly handle async error interceptors - Made mock implementation async to handle promise rejections correctly - Enabled all 7 previously skipped error handling tests - All 666 tests now pass without unhandled promise rejections This fixes the CI pipeline failure caused by unhandled promise rejections. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- tests/unit/services/n8n-api-client.test.ts | 28 ++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/tests/unit/services/n8n-api-client.test.ts b/tests/unit/services/n8n-api-client.test.ts index a68314a..99a8e1b 100644 --- a/tests/unit/services/n8n-api-client.test.ts +++ b/tests/unit/services/n8n-api-client.test.ts @@ -82,10 +82,18 @@ describe('N8nApiClient', () => { mockAxiosInstance.simulateError = async (method: string, errorConfig: any) => { const axiosError = createAxiosError(errorConfig); - mockAxiosInstance[method].mockImplementation(() => { + mockAxiosInstance[method].mockImplementation(async () => { if (mockAxiosInstance._responseInterceptor?.onRejected) { - // Pass error through the interceptor - return Promise.reject(mockAxiosInstance._responseInterceptor.onRejected(axiosError)); + // Pass error through the interceptor and ensure it's properly handled + try { + // The interceptor returns a rejected promise with the transformed error + const transformedError = await mockAxiosInstance._responseInterceptor.onRejected(axiosError); + // This shouldn't happen as onRejected should throw + return Promise.reject(transformedError); + } catch (error) { + // This is the expected path - interceptor throws the transformed error + return Promise.reject(error); + } } return Promise.reject(axiosError); }); @@ -220,7 +228,7 @@ describe('N8nApiClient', () => { expect(result).toEqual(createdWorkflow); }); - it.skip('should handle creation error', async () => { + it('should handle creation error', async () => { const workflow = { name: 'Test', nodes: [], connections: {} }; const error = { message: 'Request failed', @@ -255,7 +263,7 @@ describe('N8nApiClient', () => { expect(result).toEqual(workflow); }); - it.skip('should handle 404 error', async () => { + it('should handle 404 error', async () => { const error = { message: 'Request failed', response: { status: 404, data: { message: 'Not found' } } @@ -305,7 +313,7 @@ describe('N8nApiClient', () => { expect(result).toEqual(updatedWorkflow); }); - it.skip('should handle update error', async () => { + it('should handle update error', async () => { const workflow = { name: 'Updated', nodes: [], connections: {} }; const error = { message: 'Request failed', @@ -338,7 +346,7 @@ describe('N8nApiClient', () => { expect(mockAxiosInstance.delete).toHaveBeenCalledWith('/workflows/123'); }); - it.skip('should handle deletion error', async () => { + it('should handle deletion error', async () => { const error = { message: 'Request failed', response: { status: 404, data: { message: 'Not found' } } @@ -537,7 +545,7 @@ describe('N8nApiClient', () => { client = new N8nApiClient(defaultConfig); }); - it.skip('should handle authentication error (401)', async () => { + it('should handle authentication error (401)', async () => { const error = { message: 'Request failed', response: { @@ -557,7 +565,7 @@ describe('N8nApiClient', () => { } }); - it.skip('should handle rate limit error (429)', async () => { + it('should handle rate limit error (429)', async () => { const error = { message: 'Request failed', response: { @@ -579,7 +587,7 @@ describe('N8nApiClient', () => { } }); - it.skip('should handle server error (500)', async () => { + it('should handle server error (500)', async () => { const error = { message: 'Request failed', response: {