fix: resolve unhandled promise rejection in n8n-api-client tests

- 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 <noreply@anthropic.com>
This commit is contained in:
czlonkowski
2025-07-28 17:17:01 +02:00
parent 8e8771b1f4
commit a37054685f

View File

@@ -82,10 +82,18 @@ describe('N8nApiClient', () => {
mockAxiosInstance.simulateError = async (method: string, errorConfig: any) => { mockAxiosInstance.simulateError = async (method: string, errorConfig: any) => {
const axiosError = createAxiosError(errorConfig); const axiosError = createAxiosError(errorConfig);
mockAxiosInstance[method].mockImplementation(() => { mockAxiosInstance[method].mockImplementation(async () => {
if (mockAxiosInstance._responseInterceptor?.onRejected) { if (mockAxiosInstance._responseInterceptor?.onRejected) {
// Pass error through the interceptor // Pass error through the interceptor and ensure it's properly handled
return Promise.reject(mockAxiosInstance._responseInterceptor.onRejected(axiosError)); 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); return Promise.reject(axiosError);
}); });
@@ -220,7 +228,7 @@ describe('N8nApiClient', () => {
expect(result).toEqual(createdWorkflow); expect(result).toEqual(createdWorkflow);
}); });
it.skip('should handle creation error', async () => { it('should handle creation error', async () => {
const workflow = { name: 'Test', nodes: [], connections: {} }; const workflow = { name: 'Test', nodes: [], connections: {} };
const error = { const error = {
message: 'Request failed', message: 'Request failed',
@@ -255,7 +263,7 @@ describe('N8nApiClient', () => {
expect(result).toEqual(workflow); expect(result).toEqual(workflow);
}); });
it.skip('should handle 404 error', async () => { it('should handle 404 error', async () => {
const error = { const error = {
message: 'Request failed', message: 'Request failed',
response: { status: 404, data: { message: 'Not found' } } response: { status: 404, data: { message: 'Not found' } }
@@ -305,7 +313,7 @@ describe('N8nApiClient', () => {
expect(result).toEqual(updatedWorkflow); expect(result).toEqual(updatedWorkflow);
}); });
it.skip('should handle update error', async () => { it('should handle update error', async () => {
const workflow = { name: 'Updated', nodes: [], connections: {} }; const workflow = { name: 'Updated', nodes: [], connections: {} };
const error = { const error = {
message: 'Request failed', message: 'Request failed',
@@ -338,7 +346,7 @@ describe('N8nApiClient', () => {
expect(mockAxiosInstance.delete).toHaveBeenCalledWith('/workflows/123'); expect(mockAxiosInstance.delete).toHaveBeenCalledWith('/workflows/123');
}); });
it.skip('should handle deletion error', async () => { it('should handle deletion error', async () => {
const error = { const error = {
message: 'Request failed', message: 'Request failed',
response: { status: 404, data: { message: 'Not found' } } response: { status: 404, data: { message: 'Not found' } }
@@ -537,7 +545,7 @@ describe('N8nApiClient', () => {
client = new N8nApiClient(defaultConfig); client = new N8nApiClient(defaultConfig);
}); });
it.skip('should handle authentication error (401)', async () => { it('should handle authentication error (401)', async () => {
const error = { const error = {
message: 'Request failed', message: 'Request failed',
response: { 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 = { const error = {
message: 'Request failed', message: 'Request failed',
response: { response: {
@@ -579,7 +587,7 @@ describe('N8nApiClient', () => {
} }
}); });
it.skip('should handle server error (500)', async () => { it('should handle server error (500)', async () => {
const error = { const error = {
message: 'Request failed', message: 'Request failed',
response: { response: {