Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Expand ESLint to tests in BE packages (no-changelog) #6147

Merged
merged 5 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
4 changes: 2 additions & 2 deletions packages/cli/test/integration/saml/saml.api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import * as utils from '../shared/utils';
import { sampleConfig } from './sampleMetadata';
import { InternalHooks } from '@/InternalHooks';
import { SamlService } from '@/sso/saml/saml.service.ee';
import { SamlUserAttributes } from '@/sso/saml/types/samlUserAttributes';
import { AuthenticationMethod } from 'n8n-workflow';
import type { SamlUserAttributes } from '@/sso/saml/types/samlUserAttributes';
import type { AuthenticationMethod } from 'n8n-workflow';

let someUser: User;
let owner: User;
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/integration/shared/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import config from '@/config';

export const REST_PATH_SEGMENT = config.getEnv('endpoints.rest') as Readonly<string>;
export const REST_PATH_SEGMENT = config.getEnv('endpoints.rest');

export const PUBLIC_API_REST_PATH_SEGMENT = config.getEnv('publicApi.path') as Readonly<string>;
export const PUBLIC_API_REST_PATH_SEGMENT = config.getEnv('publicApi.path');

export const AUTHLESS_ENDPOINTS: Readonly<string[]> = [
'healthz',
Expand Down
10 changes: 4 additions & 6 deletions packages/cli/test/integration/shared/testDb.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { UserSettings } from 'n8n-core';
import {
DataSource as Connection,
DataSourceOptions as ConnectionOptions,
Repository,
} from 'typeorm';
import type { DataSourceOptions as ConnectionOptions, Repository } from 'typeorm';
import { DataSource as Connection } from 'typeorm';
import { Container } from 'typedi';

import config from '@/config';
Expand All @@ -24,7 +21,7 @@ import type { TagEntity } from '@db/entities/TagEntity';
import type { User } from '@db/entities/User';
import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
import { RoleRepository } from '@db/repositories';
import { ICredentialsDb } from '@/Interfaces';
import type { ICredentialsDb } from '@/Interfaces';

import { DB_INITIALIZATION_TIMEOUT } from './constants';
import { randomApiKey, randomEmail, randomName, randomString, randomValidPassword } from './random';
Expand Down Expand Up @@ -211,6 +208,7 @@ export async function createManyUsers(
amount: number,
attributes: Partial<User> = {},
): Promise<User[]> {
// eslint-disable-next-line prefer-const
let { email, password, firstName, lastName, globalRole, ...rest } = attributes;
if (!globalRole) {
globalRole = await getGlobalMemberRole();
Expand Down
Loading