Skip to content

Commit

Permalink
🔀 Merge master, fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov committed May 2, 2023
2 parents 63e88d7 + 839a56a commit 327a489
Show file tree
Hide file tree
Showing 71 changed files with 525 additions and 336 deletions.
41 changes: 38 additions & 3 deletions packages/@n8n_io/eslint-config/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ const config = (module.exports = {
'node_modules/**',
'dist/**',
// TODO: remove these
'test/**',
'.eslintrc.js',
'jest.config.js',
'*.js',
],

plugins: [
Expand Down Expand Up @@ -452,6 +450,43 @@ const config = (module.exports = {
'@typescript-eslint/no-unused-vars': 'off',
},
},
{
files: ['test/**/*.ts'],
// TODO: Remove these
rules: {
'@typescript-eslint/await-thenable': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/no-duplicate-imports': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-loop-func': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-shadow': 'off',
'@typescript-eslint/no-throw-literal': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
'@typescript-eslint/prefer-optional-chain': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/unbound-method': 'off',
'id-denylist': 'off',
'import/no-cycle': 'off',
'import/no-default-export': 'off',
'import/no-extraneous-dependencies': 'off',
'n8n-local-rules/no-uncaught-json-parse': 'off',
'prefer-const': 'off',
'prefer-spread': 'off',
},
},
],
});

Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/InternalHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,19 @@ export class InternalHooks implements IInternalHooksClass {
properties.user_id = userId;
}

if (runData?.data.resultData.error?.message?.includes('canceled')) {
runData.status = 'canceled';
}

properties.success = !!runData?.finished;

let executionStatus: ExecutionStatus;
if (runData?.status === 'crashed') {
executionStatus = 'crashed';
} else if (runData?.status === 'waiting' || runData?.data?.waitTill) {
executionStatus = 'waiting';
} else if (runData?.status === 'canceled') {
executionStatus = 'canceled';
} else {
executionStatus = properties.success ? 'success' : 'failed';
}
Expand Down
10 changes: 8 additions & 2 deletions packages/cli/src/WorkflowExecuteAdditionalData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,12 @@ function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks {
}

const workflowHasCrashed = fullRunData.status === 'crashed';
const workflowDidSucceed = !fullRunData.data.resultData.error && !workflowHasCrashed;
const workflowWasCanceled = fullRunData.status === 'canceled';
const workflowDidSucceed =
!fullRunData.data.resultData.error && !workflowHasCrashed && !workflowWasCanceled;
let workflowStatusFinal: ExecutionStatus = workflowDidSucceed ? 'success' : 'failed';
if (workflowHasCrashed) workflowStatusFinal = 'crashed';
if (workflowWasCanceled) workflowStatusFinal = 'canceled';

if (
(workflowDidSucceed && saveDataSuccessExecution === 'none') ||
Expand Down Expand Up @@ -755,9 +758,12 @@ function hookFunctionsSaveWorker(): IWorkflowExecuteHooks {
}

const workflowHasCrashed = fullRunData.status === 'crashed';
const workflowDidSucceed = !fullRunData.data.resultData.error && !workflowHasCrashed;
const workflowWasCanceled = fullRunData.status === 'canceled';
const workflowDidSucceed =
!fullRunData.data.resultData.error && !workflowHasCrashed && !workflowWasCanceled;
let workflowStatusFinal: ExecutionStatus = workflowDidSucceed ? 'success' : 'failed';
if (workflowHasCrashed) workflowStatusFinal = 'crashed';
if (workflowWasCanceled) workflowStatusFinal = 'canceled';

if (!workflowDidSucceed) {
executeErrorWorkflow(
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/WorkflowRunnerProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ process.on('message', async (message: IProcessMessage) => {
? new WorkflowOperationError('Workflow execution timed out!')
: new WorkflowOperationError('Workflow-Execution has been canceled!');

runData.status = message.type === 'timeout' ? 'failed' : 'canceled';

// If there is any data send it to parent process, if execution timedout add the error
await workflowRunner.workflowExecute.processSuccessExecution(
workflowRunner.startedAt,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/integration/commands/import.cmd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test('import:workflow should import active workflow and deactivate it', async ()
['--separate', '--input=./test/integration/commands/importWorkflows/separate'],
config,
);
const mockExit = jest.spyOn(process, 'exit').mockImplementation((number) => {
const mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {
throw new Error('process.exit');
});

Expand All @@ -52,7 +52,7 @@ test('import:workflow should import active workflow from combined file and deact
['--input=./test/integration/commands/importWorkflows/combined/combined.json'],
config,
);
const mockExit = jest.spyOn(process, 'exit').mockImplementation((number) => {
const mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {
throw new Error('process.exit');
});

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/integration/credentials.ee.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ describe('PUT /credentials/:id/share', () => {

test('should respond 403 for non-existing credentials', async () => {
const response = await authOwnerAgent
.put(`/credentials/1234567/share`)
.put('/credentials/1234567/share')
.send({ shareWithIds: [member.id] });

expect(response.statusCode).toBe(403);
Expand Down
11 changes: 5 additions & 6 deletions packages/cli/test/integration/credentials.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import type { Role } from '@db/entities/Role';
import type { User } from '@db/entities/User';
import { randomCredentialPayload, randomName, randomString } from './shared/random';
import * as testDb from './shared/testDb';
import type { SaveCredentialFunction } from './shared/types';
import type { AuthAgent, SaveCredentialFunction } from './shared/types';
import * as utils from './shared/utils';
import type { AuthAgent } from './shared/types';

// mock that credentialsSharing is not enabled
const mockIsCredentialsSharingEnabled = jest.spyOn(UserManagementHelpers, 'isSharingEnabled');
Expand Down Expand Up @@ -124,7 +123,7 @@ describe('POST /credentials', () => {

expect(credential.name).toBe(payload.name);
expect(credential.type).toBe(payload.type);
expect(credential.nodesAccess[0].nodeType).toBe(payload.nodesAccess![0].nodeType);
expect(credential.nodesAccess[0].nodeType).toBe(payload.nodesAccess[0].nodeType);
expect(credential.data).not.toBe(payload.data);

const sharedCredential = await Db.collections.SharedCredentials.findOneOrFail({
Expand Down Expand Up @@ -278,7 +277,7 @@ describe('PATCH /credentials/:id', () => {

expect(credential.name).toBe(patchPayload.name);
expect(credential.type).toBe(patchPayload.type);
expect(credential.nodesAccess[0].nodeType).toBe(patchPayload.nodesAccess![0].nodeType);
expect(credential.nodesAccess[0].nodeType).toBe(patchPayload.nodesAccess[0].nodeType);
expect(credential.data).not.toBe(patchPayload.data);

const sharedCredential = await Db.collections.SharedCredentials.findOneOrFail({
Expand Down Expand Up @@ -315,7 +314,7 @@ describe('PATCH /credentials/:id', () => {

expect(credential.name).toBe(patchPayload.name);
expect(credential.type).toBe(patchPayload.type);
expect(credential.nodesAccess[0].nodeType).toBe(patchPayload.nodesAccess![0].nodeType);
expect(credential.nodesAccess[0].nodeType).toBe(patchPayload.nodesAccess[0].nodeType);
expect(credential.data).not.toBe(patchPayload.data);

const sharedCredential = await Db.collections.SharedCredentials.findOneOrFail({
Expand Down Expand Up @@ -352,7 +351,7 @@ describe('PATCH /credentials/:id', () => {

expect(credential.name).toBe(patchPayload.name);
expect(credential.type).toBe(patchPayload.type);
expect(credential.nodesAccess[0].nodeType).toBe(patchPayload.nodesAccess![0].nodeType);
expect(credential.nodesAccess[0].nodeType).toBe(patchPayload.nodesAccess[0].nodeType);
expect(credential.data).not.toBe(patchPayload.data);

const sharedCredential = await Db.collections.SharedCredentials.findOneOrFail({
Expand Down
24 changes: 13 additions & 11 deletions packages/cli/test/integration/eventbus.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import express from 'express';
import type express from 'express';
import config from '@/config';
import axios from 'axios';
import syslog from 'syslog-client';
Expand All @@ -7,23 +7,25 @@ import { Container } from 'typedi';
import type { SuperAgentTest } from 'supertest';
import * as utils from './shared/utils';
import * as testDb from './shared/testDb';
import { Role } from '@db/entities/Role';
import { User } from '@db/entities/User';
import type { Role } from '@db/entities/Role';
import type { User } from '@db/entities/User';
import type {
MessageEventBusDestinationSentryOptions,
MessageEventBusDestinationSyslogOptions,
MessageEventBusDestinationWebhookOptions,
} from 'n8n-workflow';
import {
defaultMessageEventBusDestinationSentryOptions,
defaultMessageEventBusDestinationSyslogOptions,
defaultMessageEventBusDestinationWebhookOptions,
MessageEventBusDestinationSentryOptions,
MessageEventBusDestinationSyslogOptions,
MessageEventBusDestinationWebhookOptions,
} from 'n8n-workflow';
import { eventBus } from '@/eventbus';
import { EventMessageGeneric } from '@/eventbus/EventMessageClasses/EventMessageGeneric';
import { MessageEventBusDestinationSyslog } from '@/eventbus/MessageEventBusDestination/MessageEventBusDestinationSyslog.ee';
import { MessageEventBusDestinationWebhook } from '@/eventbus/MessageEventBusDestination/MessageEventBusDestinationWebhook.ee';
import { MessageEventBusDestinationSentry } from '@/eventbus/MessageEventBusDestination/MessageEventBusDestinationSentry.ee';
import type { MessageEventBusDestinationSyslog } from '@/eventbus/MessageEventBusDestination/MessageEventBusDestinationSyslog.ee';
import type { MessageEventBusDestinationWebhook } from '@/eventbus/MessageEventBusDestination/MessageEventBusDestinationWebhook.ee';
import type { MessageEventBusDestinationSentry } from '@/eventbus/MessageEventBusDestination/MessageEventBusDestinationSentry.ee';
import { EventMessageAudit } from '@/eventbus/EventMessageClasses/EventMessageAudit';
import { EventNamesTypes } from '@/eventbus/EventMessageClasses';
import type { EventNamesTypes } from '@/eventbus/EventMessageClasses';
import { License } from '@/License';

jest.unmock('@/eventbus/MessageEventBus/MessageEventBus');
Expand Down Expand Up @@ -51,7 +53,7 @@ const testWebhookDestination: MessageEventBusDestinationWebhookOptions = {
...defaultMessageEventBusDestinationWebhookOptions,
id: '88be6560-bfb4-455c-8aa1-06971e9e5522',
url: 'http://localhost:3456',
method: `POST`,
method: 'POST',
label: 'Test Webhook',
enabled: false,
subscribedEvents: ['n8n.test.message', 'n8n.audit.user.updated'],
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/integration/ldap/ldap.api.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import express from 'express';
import type express from 'express';
import type { Entry as LdapUser } from 'ldapts';
import { Not } from 'typeorm';
import { Container } from 'typedi';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/integration/license.api.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { SuperAgentTest } from 'supertest';
import config from '@/config';
import type { User } from '@db/entities/User';
import { ILicensePostResponse, ILicenseReadResponse } from '@/Interfaces';
import type { ILicensePostResponse, ILicenseReadResponse } from '@/Interfaces';
import { License } from '@/License';
import * as testDb from './shared/testDb';
import * as utils from './shared/utils';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/integration/passwordReset.api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let globalOwnerRole: Role;
let globalMemberRole: Role;
let owner: User;
let authlessAgent: SuperAgentTest;
let externalHooks = utils.mockInstance(ExternalHooks);
const externalHooks = utils.mockInstance(ExternalHooks);

beforeAll(async () => {
const app = await utils.initTestServer({ endpointGroups: ['passwordReset'] });
Expand Down
18 changes: 9 additions & 9 deletions packages/cli/test/integration/publicApi/executions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ describe('GET /executions', () => {

await testDb.createErrorExecution(workflow);

const response = await authOwnerAgent.get(`/executions`).query({
const response = await authOwnerAgent.get('/executions').query({
status: 'success',
});

Expand Down Expand Up @@ -254,7 +254,7 @@ describe('GET /executions', () => {

await testDb.createErrorExecution(workflow);

const firstExecutionResponse = await authOwnerAgent.get(`/executions`).query({
const firstExecutionResponse = await authOwnerAgent.get('/executions').query({
status: 'success',
limit: 1,
});
Expand All @@ -263,7 +263,7 @@ describe('GET /executions', () => {
expect(firstExecutionResponse.body.data.length).toBe(1);
expect(firstExecutionResponse.body.nextCursor).toBeDefined();

const secondExecutionResponse = await authOwnerAgent.get(`/executions`).query({
const secondExecutionResponse = await authOwnerAgent.get('/executions').query({
status: 'success',
limit: 1,
cursor: firstExecutionResponse.body.nextCursor,
Expand Down Expand Up @@ -308,7 +308,7 @@ describe('GET /executions', () => {

const errorExecution = await testDb.createErrorExecution(workflow);

const response = await authOwnerAgent.get(`/executions`).query({
const response = await authOwnerAgent.get('/executions').query({
status: 'error',
});

Expand Down Expand Up @@ -348,7 +348,7 @@ describe('GET /executions', () => {

const waitingExecution = await testDb.createWaitingExecution(workflow);

const response = await authOwnerAgent.get(`/executions`).query({
const response = await authOwnerAgent.get('/executions').query({
status: 'waiting',
});

Expand Down Expand Up @@ -389,7 +389,7 @@ describe('GET /executions', () => {
);
await testDb.createManyExecutions(2, workflow2, testDb.createSuccessfulExecution);

const response = await authOwnerAgent.get(`/executions`).query({
const response = await authOwnerAgent.get('/executions').query({
workflowId: workflow.id,
});

Expand Down Expand Up @@ -439,7 +439,7 @@ describe('GET /executions', () => {
await testDb.createManyExecutions(2, firstWorkflowForUser2, testDb.createSuccessfulExecution);
await testDb.createManyExecutions(2, secondWorkflowForUser2, testDb.createSuccessfulExecution);

const response = await authOwnerAgent.get(`/executions`);
const response = await authOwnerAgent.get('/executions');

expect(response.statusCode).toBe(200);
expect(response.body.data.length).toBe(8);
Expand All @@ -463,7 +463,7 @@ describe('GET /executions', () => {
await testDb.createManyExecutions(2, firstWorkflowForUser2, testDb.createSuccessfulExecution);
await testDb.createManyExecutions(2, secondWorkflowForUser2, testDb.createSuccessfulExecution);

const response = await authUser1Agent.get(`/executions`);
const response = await authUser1Agent.get('/executions');

expect(response.statusCode).toBe(200);
expect(response.body.data.length).toBe(4);
Expand All @@ -489,7 +489,7 @@ describe('GET /executions', () => {

await testDb.shareWorkflowWithUsers(firstWorkflowForUser2, [user1]);

const response = await authUser1Agent.get(`/executions`);
const response = await authUser1Agent.get('/executions');

expect(response.statusCode).toBe(200);
expect(response.body.data.length).toBe(6);
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/test/integration/publicApi/workflows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ describe('GET /workflows/:id', () => {
test('should fail due to invalid API Key', testWithAPIKey('get', '/workflows/2', 'abcXYZ'));

test('should fail due to non-existing workflow', async () => {
const response = await authOwnerAgent.get(`/workflows/2`);
const response = await authOwnerAgent.get('/workflows/2');
expect(response.statusCode).toBe(404);
});

Expand Down Expand Up @@ -375,7 +375,7 @@ describe('DELETE /workflows/:id', () => {
test('should fail due to invalid API Key', testWithAPIKey('delete', '/workflows/2', 'abcXYZ'));

test('should fail due to non-existing workflow', async () => {
const response = await authOwnerAgent.delete(`/workflows/2`);
const response = await authOwnerAgent.delete('/workflows/2');
expect(response.statusCode).toBe(404);
});

Expand Down Expand Up @@ -447,7 +447,7 @@ describe('POST /workflows/:id/activate', () => {
);

test('should fail due to non-existing workflow', async () => {
const response = await authOwnerAgent.post(`/workflows/2/activate`);
const response = await authOwnerAgent.post('/workflows/2/activate');
expect(response.statusCode).toBe(404);
});

Expand Down Expand Up @@ -549,7 +549,7 @@ describe('POST /workflows/:id/deactivate', () => {
);

test('should fail due to non-existing workflow', async () => {
const response = await authOwnerAgent.post(`/workflows/2/deactivate`);
const response = await authOwnerAgent.post('/workflows/2/deactivate');
expect(response.statusCode).toBe(404);
});

Expand Down Expand Up @@ -709,7 +709,7 @@ describe('PUT /workflows/:id', () => {
test('should fail due to invalid API Key', testWithAPIKey('put', '/workflows/1', 'abcXYZ'));

test('should fail due to non-existing workflow', async () => {
const response = await authOwnerAgent.put(`/workflows/1`).send({
const response = await authOwnerAgent.put('/workflows/1').send({
name: 'testing',
nodes: [
{
Expand Down Expand Up @@ -737,7 +737,7 @@ describe('PUT /workflows/:id', () => {
});

test('should fail due to invalid body', async () => {
const response = await authOwnerAgent.put(`/workflows/1`).send({
const response = await authOwnerAgent.put('/workflows/1').send({
nodes: [
{
id: 'uuid-1234',
Expand Down
Loading

0 comments on commit 327a489

Please sign in to comment.