From 08902bf9413c1540a37f61d39be93906e10ef1be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Fri, 31 May 2024 09:40:03 +0200 Subject: [PATCH] refactor(core): Update supertest, and fix some typing errors (no-changelog) (#9527) --- package.json | 2 +- packages/cli/package.json | 2 +- .../externalSecrets.api.test.ts | 11 +++---- .../cli/test/integration/auth.api.test.ts | 8 +++-- packages/cli/test/integration/auth.mw.test.ts | 26 ++++++++--------- .../test/integration/binaryData.api.test.ts | 2 +- .../community-packages.api.test.ts | 2 +- ...dynamic-node-parameters.controller.test.ts | 12 ++++---- .../credentials/credentials.api.ee.test.ts | 13 ++++----- .../credentials/credentials.api.test.ts | 20 +++++++------ .../test/integration/debug.controller.test.ts | 11 +++---- .../environments/SourceControl.test.ts | 4 +-- .../cli/test/integration/eventbus.ee.test.ts | 2 +- .../cli/test/integration/eventbus.test.ts | 3 +- .../test/integration/ldap/ldap.api.test.ts | 9 +++--- .../cli/test/integration/license.api.test.ts | 5 ++-- packages/cli/test/integration/me.api.test.ts | 4 +-- .../integration/publicApi/credentials.test.ts | 9 +++--- .../integration/publicApi/executions.test.ts | 2 +- .../test/integration/publicApi/tags.test.ts | 4 +-- .../integration/publicApi/users.ee.test.ts | 2 +- .../integration/publicApi/workflows.test.ts | 11 +++---- .../cli/test/integration/role.api.test.ts | 18 +++++++----- .../test/integration/saml/saml.api.test.ts | 3 +- .../test/integration/shared/augmentation.d.ts | 10 ------- packages/cli/test/integration/shared/types.ts | 10 ++++--- .../cli/test/integration/tags.api.test.ts | 8 +++-- .../cli/test/integration/users.api.test.ts | 12 ++++---- .../cli/test/integration/variables.test.ts | 5 ++-- .../cli/test/integration/webhooks.api.test.ts | 2 +- .../integration/workflowHistory.api.test.ts | 2 +- .../workflows/workflows.controller.ee.test.ts | 14 ++++----- .../workflows/workflows.controller.test.ts | 12 ++++---- packages/cli/test/unit/webhooks.test.ts | 2 +- pnpm-lock.yaml | 29 +++++++++---------- 35 files changed, 148 insertions(+), 143 deletions(-) delete mode 100644 packages/cli/test/integration/shared/augmentation.d.ts diff --git a/package.json b/package.json index 5ad9b63e5d..0750168494 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "rimraf": "^5.0.1", "run-script-os": "^1.0.7", "start-server-and-test": "^2.0.3", - "supertest": "^6.3.4", + "supertest": "^7.0.0", "ts-jest": "^29.1.1", "tsc-alias": "^1.8.7", "tsc-watch": "^6.0.4", diff --git a/packages/cli/package.json b/packages/cli/package.json index c30c24ce92..bfef67e580 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -76,7 +76,7 @@ "@types/replacestream": "^4.0.1", "@types/shelljs": "^0.8.11", "@types/sshpk": "^1.17.1", - "@types/superagent": "^8.1.4", + "@types/superagent": "^8.1.7", "@types/swagger-ui-express": "^4.1.6", "@types/syslog-client": "^1.1.2", "@types/uuid": "^8.3.2", diff --git a/packages/cli/test/integration/ExternalSecrets/externalSecrets.api.test.ts b/packages/cli/test/integration/ExternalSecrets/externalSecrets.api.test.ts index 868c695f4a..6fc394fa8b 100644 --- a/packages/cli/test/integration/ExternalSecrets/externalSecrets.api.test.ts +++ b/packages/cli/test/integration/ExternalSecrets/externalSecrets.api.test.ts @@ -1,15 +1,15 @@ -import type { SuperAgentTest } from 'supertest'; +import { Container } from 'typedi'; +import { Cipher } from 'n8n-core'; +import { jsonParse, type IDataObject } from 'n8n-workflow'; +import { mock } from 'jest-mock-extended'; + import { License } from '@/License'; import type { ExternalSecretsSettings, SecretsProviderState } from '@/Interfaces'; -import { Cipher } from 'n8n-core'; import { SettingsRepository } from '@db/repositories/settings.repository'; -import { Container } from 'typedi'; import { ExternalSecretsProviders } from '@/ExternalSecrets/ExternalSecretsProviders.ee'; import config from '@/config'; import { ExternalSecretsManager } from '@/ExternalSecrets/ExternalSecretsManager.ee'; import { CREDENTIAL_BLANKING_VALUE } from '@/constants'; -import { jsonParse, type IDataObject } from 'n8n-workflow'; -import { mock } from 'jest-mock-extended'; import { mockInstance } from '../../shared/mocking'; import { setupTestServer } from '../shared/utils'; @@ -20,6 +20,7 @@ import { MockProviders, TestFailProvider, } from '../../shared/ExternalSecrets/utils'; +import type { SuperAgentTest } from '../shared/types'; let authOwnerAgent: SuperAgentTest; let authMemberAgent: SuperAgentTest; diff --git a/packages/cli/test/integration/auth.api.test.ts b/packages/cli/test/integration/auth.api.test.ts index 356a97b662..08d4eb0a66 100644 --- a/packages/cli/test/integration/auth.api.test.ts +++ b/packages/cli/test/integration/auth.api.test.ts @@ -1,16 +1,18 @@ -import type { SuperAgentTest } from 'supertest'; import { Container } from 'typedi'; import validator from 'validator'; + import config from '@/config'; import { AUTH_COOKIE_NAME } from '@/constants'; import type { User } from '@db/entities/User'; +import { UserRepository } from '@db/repositories/user.repository'; +import { MfaService } from '@/Mfa/mfa.service'; + import { LOGGED_OUT_RESPONSE_BODY } from './shared/constants'; import { randomValidPassword } from './shared/random'; import * as testDb from './shared/testDb'; import * as utils from './shared/utils/'; import { createUser, createUserShell } from './shared/db/users'; -import { UserRepository } from '@db/repositories/user.repository'; -import { MfaService } from '@/Mfa/mfa.service'; +import type { SuperAgentTest } from './shared/types'; let owner: User; let authOwnerAgent: SuperAgentTest; diff --git a/packages/cli/test/integration/auth.mw.test.ts b/packages/cli/test/integration/auth.mw.test.ts index c29fda47b7..b4a47667fe 100644 --- a/packages/cli/test/integration/auth.mw.test.ts +++ b/packages/cli/test/integration/auth.mw.test.ts @@ -1,9 +1,9 @@ import { ActiveWorkflowManager } from '@/ActiveWorkflowManager'; -import type { SuperAgentTest } from 'supertest'; import * as utils from './shared/utils/'; import { createUser } from './shared/db/users'; import { mockInstance } from '../shared/mocking'; +import type { SuperAgentTest } from './shared/types'; describe('Auth Middleware', () => { mockInstance(ActiveWorkflowManager); @@ -13,23 +13,23 @@ describe('Auth Middleware', () => { }); /** Routes requiring a valid `n8n-auth` cookie for a user, either owner or member. */ - const ROUTES_REQUIRING_AUTHENTICATION: Readonly> = [ - ['PATCH', '/me'], - ['PATCH', '/me/password'], - ['POST', '/me/survey'], - ]; + const ROUTES_REQUIRING_AUTHENTICATION = [ + ['patch', '/me'], + ['patch', '/me/password'], + ['post', '/me/survey'], + ] as const; /** Routes requiring a valid `n8n-auth` cookie for an owner. */ - const ROUTES_REQUIRING_AUTHORIZATION: Readonly> = [ - ['POST', '/invitations'], - ['DELETE', '/users/123'], - ]; + const ROUTES_REQUIRING_AUTHORIZATION = [ + ['post', '/invitations'], + ['delete', '/users/123'], + ] as const; describe('Routes requiring Authentication', () => { - ROUTES_REQUIRING_AUTHENTICATION.concat(ROUTES_REQUIRING_AUTHORIZATION).forEach( + [...ROUTES_REQUIRING_AUTHENTICATION, ...ROUTES_REQUIRING_AUTHORIZATION].forEach( ([method, endpoint]) => { test(`${method} ${endpoint} should return 401 Unauthorized if no cookie`, async () => { - const { statusCode } = await testServer.authlessAgent[method.toLowerCase()](endpoint); + const { statusCode } = await testServer.authlessAgent[method](endpoint); expect(statusCode).toBe(401); }); }, @@ -45,7 +45,7 @@ describe('Auth Middleware', () => { ROUTES_REQUIRING_AUTHORIZATION.forEach(async ([method, endpoint]) => { test(`${method} ${endpoint} should return 403 Forbidden for member`, async () => { - const { statusCode } = await authMemberAgent[method.toLowerCase()](endpoint); + const { statusCode } = await authMemberAgent[method](endpoint); expect(statusCode).toBe(403); }); }); diff --git a/packages/cli/test/integration/binaryData.api.test.ts b/packages/cli/test/integration/binaryData.api.test.ts index 6a3a314c73..bfa5522948 100644 --- a/packages/cli/test/integration/binaryData.api.test.ts +++ b/packages/cli/test/integration/binaryData.api.test.ts @@ -1,11 +1,11 @@ import fsp from 'node:fs/promises'; import { Readable } from 'node:stream'; import { BinaryDataService, FileNotFoundError } from 'n8n-core'; -import type { SuperAgentTest } from 'supertest'; import { mockInstance } from '../shared/mocking'; import { setupTestServer } from './shared/utils'; import { createOwner } from './shared/db/users'; +import type { SuperAgentTest } from './shared/types'; jest.mock('fs/promises'); diff --git a/packages/cli/test/integration/community-packages.api.test.ts b/packages/cli/test/integration/community-packages.api.test.ts index 03fd43f456..661dbcd0fe 100644 --- a/packages/cli/test/integration/community-packages.api.test.ts +++ b/packages/cli/test/integration/community-packages.api.test.ts @@ -1,5 +1,4 @@ import path from 'path'; -import type { SuperAgentTest } from 'supertest'; import type { InstalledPackages } from '@db/entities/InstalledPackages'; import type { InstalledNodes } from '@db/entities/InstalledNodes'; @@ -10,6 +9,7 @@ import { mockInstance } from '../shared/mocking'; import { COMMUNITY_PACKAGE_VERSION } from './shared/constants'; import { setupTestServer, mockPackage, mockNode, mockPackageName } from './shared/utils'; import { createOwner } from './shared/db/users'; +import type { SuperAgentTest } from './shared/types'; const communityPackagesService = mockInstance(CommunityPackagesService, { hasMissingPackages: false, diff --git a/packages/cli/test/integration/controllers/dynamic-node-parameters.controller.test.ts b/packages/cli/test/integration/controllers/dynamic-node-parameters.controller.test.ts index e28e83a709..fd66cbf5fd 100644 --- a/packages/cli/test/integration/controllers/dynamic-node-parameters.controller.test.ts +++ b/packages/cli/test/integration/controllers/dynamic-node-parameters.controller.test.ts @@ -1,18 +1,20 @@ -import type { SuperTest, Test } from 'supertest'; -import { createOwner } from '../shared/db/users'; -import { setupTestServer } from '../shared/utils'; -import * as AdditionalData from '@/WorkflowExecuteAdditionalData'; import type { INodeListSearchResult, IWorkflowExecuteAdditionalData, ResourceMapperFields, } from 'n8n-workflow'; import { mock } from 'jest-mock-extended'; + import { DynamicNodeParametersService } from '@/services/dynamicNodeParameters.service'; +import * as AdditionalData from '@/WorkflowExecuteAdditionalData'; + +import { createOwner } from '../shared/db/users'; +import { setupTestServer } from '../shared/utils'; +import type { SuperAgentTest } from '../shared/types'; describe('DynamicNodeParametersController', () => { const testServer = setupTestServer({ endpointGroups: ['dynamic-node-parameters'] }); - let ownerAgent: SuperTest; + let ownerAgent: SuperAgentTest; beforeAll(async () => { const owner = await createOwner(); diff --git a/packages/cli/test/integration/credentials/credentials.api.ee.test.ts b/packages/cli/test/integration/credentials/credentials.api.ee.test.ts index b00b0091f4..c711785d91 100644 --- a/packages/cli/test/integration/credentials/credentials.api.ee.test.ts +++ b/packages/cli/test/integration/credentials/credentials.api.ee.test.ts @@ -1,10 +1,14 @@ import { Container } from 'typedi'; -import type { SuperAgentTest } from 'supertest'; import { In } from '@n8n/typeorm'; +import config from '@/config'; import type { ListQuery } from '@/requests'; import type { User } from '@db/entities/User'; import { SharedCredentialsRepository } from '@db/repositories/sharedCredentials.repository'; +import { ProjectRepository } from '@db/repositories/project.repository'; +import type { Project } from '@db/entities/Project'; +import { ProjectService } from '@/services/project.service'; +import { UserManagementMailer } from '@/UserManagement/email'; import { randomCredentialPayload } from '../shared/random'; import * as testDb from '../shared/testDb'; @@ -16,13 +20,8 @@ import { shareCredentialWithUsers, } from '../shared/db/credentials'; import { createManyUsers, createUser, createUserShell } from '../shared/db/users'; -import { UserManagementMailer } from '@/UserManagement/email'; - +import type { SuperAgentTest } from '../shared/types'; import { mockInstance } from '../../shared/mocking'; -import config from '@/config'; -import { ProjectRepository } from '@/databases/repositories/project.repository'; -import type { Project } from '@/databases/entities/Project'; -import { ProjectService } from '@/services/project.service'; const testServer = utils.setupTestServer({ endpointGroups: ['credentials'], diff --git a/packages/cli/test/integration/credentials/credentials.api.test.ts b/packages/cli/test/integration/credentials/credentials.api.test.ts index ac046acbb7..9b238d51c9 100644 --- a/packages/cli/test/integration/credentials/credentials.api.test.ts +++ b/packages/cli/test/integration/credentials/credentials.api.test.ts @@ -1,6 +1,16 @@ +import { Container } from 'typedi'; +import type { Scope } from '@sentry/node'; +import { Credentials } from 'n8n-core'; + import type { ListQuery } from '@/requests'; import type { User } from '@db/entities/User'; import config from '@/config'; +import { ProjectRepository } from '@db/repositories/project.repository'; +import type { Project } from '@db/entities/Project'; +import { CredentialsRepository } from '@db/repositories/credentials.repository'; +import { SharedCredentialsRepository } from '@db/repositories/sharedCredentials.repository'; +import { ProjectService } from '@/services/project.service'; + import * as testDb from '../shared/testDb'; import { setupTestServer } from '../shared/utils'; import { @@ -15,16 +25,8 @@ import { shareCredentialWithUsers, } from '../shared/db/credentials'; import { createManyUsers, createMember, createOwner } from '../shared/db/users'; -import { ProjectRepository } from '@/databases/repositories/project.repository'; -import Container from 'typedi'; -import type { Project } from '@/databases/entities/Project'; import { createTeamProject, linkUserToProject } from '../shared/db/projects'; -import type { SuperAgentTest } from 'supertest'; -import { Credentials } from 'n8n-core'; -import type { Scope } from '@sentry/node'; -import { CredentialsRepository } from '@/databases/repositories/credentials.repository'; -import { SharedCredentialsRepository } from '@/databases/repositories/sharedCredentials.repository'; -import { ProjectService } from '@/services/project.service'; +import type { SuperAgentTest } from '../shared/types'; const { any } = expect; diff --git a/packages/cli/test/integration/debug.controller.test.ts b/packages/cli/test/integration/debug.controller.test.ts index 903d30977c..c44a4fd477 100644 --- a/packages/cli/test/integration/debug.controller.test.ts +++ b/packages/cli/test/integration/debug.controller.test.ts @@ -1,15 +1,16 @@ import { WorkflowRepository } from '@/databases/repositories/workflow.repository'; import { ActiveWorkflowManager } from '@/ActiveWorkflowManager'; -import { mockInstance } from '../shared/mocking'; -import { randomName } from './shared/random'; import { generateNanoId } from '@/databases/utils/generators'; import type { WorkflowEntity } from '@/databases/entities/WorkflowEntity'; -import { setupTestServer } from './shared/utils'; -import type { SuperAgentTest } from 'supertest'; -import { createOwner } from './shared/db/users'; import { OrchestrationService } from '@/services/orchestration.service'; import { MultiMainSetup } from '@/services/orchestration/main/MultiMainSetup.ee'; +import { mockInstance } from '../shared/mocking'; +import { randomName } from './shared/random'; +import { setupTestServer } from './shared/utils'; +import { createOwner } from './shared/db/users'; +import type { SuperAgentTest } from './shared/types'; + describe('DebugController', () => { const workflowRepository = mockInstance(WorkflowRepository); const activeWorkflowManager = mockInstance(ActiveWorkflowManager); diff --git a/packages/cli/test/integration/environments/SourceControl.test.ts b/packages/cli/test/integration/environments/SourceControl.test.ts index e7f5b349fb..84eec3c0da 100644 --- a/packages/cli/test/integration/environments/SourceControl.test.ts +++ b/packages/cli/test/integration/environments/SourceControl.test.ts @@ -1,16 +1,16 @@ import { Container } from 'typedi'; -import type { SuperAgentTest } from 'supertest'; import type { User } from '@db/entities/User'; import config from '@/config'; import { SourceControlPreferencesService } from '@/environments/sourceControl/sourceControlPreferences.service.ee'; import { SourceControlService } from '@/environments/sourceControl/sourceControl.service.ee'; import type { SourceControlledFile } from '@/environments/sourceControl/types/sourceControlledFile'; +import { WaitTracker } from '@/WaitTracker'; import * as utils from '../shared/utils/'; import { createUser } from '../shared/db/users'; import { mockInstance } from '../../shared/mocking'; -import { WaitTracker } from '@/WaitTracker'; +import type { SuperAgentTest } from '../shared/types'; let authOwnerAgent: SuperAgentTest; let owner: User; diff --git a/packages/cli/test/integration/eventbus.ee.test.ts b/packages/cli/test/integration/eventbus.ee.test.ts index a0837fe8ea..0c8627ac48 100644 --- a/packages/cli/test/integration/eventbus.ee.test.ts +++ b/packages/cli/test/integration/eventbus.ee.test.ts @@ -3,7 +3,6 @@ import config from '@/config'; import axios from 'axios'; import syslog from 'syslog-client'; import { v4 as uuid } from 'uuid'; -import type { SuperAgentTest } from 'supertest'; import type { MessageEventBusDestinationSentryOptions, MessageEventBusDestinationSyslogOptions, @@ -28,6 +27,7 @@ import { ExecutionDataRecoveryService } from '@/eventbus/executionDataRecovery.s import * as utils from './shared/utils'; import { createUser } from './shared/db/users'; import { mockInstance } from '../shared/mocking'; +import type { SuperAgentTest } from './shared/types'; jest.unmock('@/eventbus/MessageEventBus/MessageEventBus'); jest.mock('axios'); diff --git a/packages/cli/test/integration/eventbus.test.ts b/packages/cli/test/integration/eventbus.test.ts index 9e3e27dacb..1acb8ffa36 100644 --- a/packages/cli/test/integration/eventbus.test.ts +++ b/packages/cli/test/integration/eventbus.test.ts @@ -1,5 +1,3 @@ -import type { SuperAgentTest } from 'supertest'; - import type { User } from '@db/entities/User'; import { MessageEventBus } from '@/eventbus/MessageEventBus/MessageEventBus'; import { ExecutionDataRecoveryService } from '@/eventbus/executionDataRecovery.service'; @@ -7,6 +5,7 @@ import { ExecutionDataRecoveryService } from '@/eventbus/executionDataRecovery.s import * as utils from './shared/utils/'; import { createUser } from './shared/db/users'; import { mockInstance } from '../shared/mocking'; +import type { SuperAgentTest } from './shared/types'; /** * NOTE: due to issues with mocking the MessageEventBus in multiple tests running in parallel, diff --git a/packages/cli/test/integration/ldap/ldap.api.test.ts b/packages/cli/test/integration/ldap/ldap.api.test.ts index 0ab2f84913..2a2f1f1810 100644 --- a/packages/cli/test/integration/ldap/ldap.api.test.ts +++ b/packages/cli/test/integration/ldap/ldap.api.test.ts @@ -1,11 +1,12 @@ -import Container from 'typedi'; -import type { SuperAgentTest } from 'supertest'; +import { Container } from 'typedi'; import type { Entry as LdapUser } from 'ldapts'; import { Not } from '@n8n/typeorm'; import { Cipher } from 'n8n-core'; import config from '@/config'; import type { User } from '@db/entities/User'; +import { UserRepository } from '@db/repositories/user.repository'; +import { AuthProviderSyncHistoryRepository } from '@db/repositories/authProviderSyncHistory.repository'; import { LDAP_DEFAULT_CONFIGURATION } from '@/Ldap/constants'; import { LdapService } from '@/Ldap/ldap.service'; import { saveLdapSynchronization } from '@/Ldap/helpers'; @@ -14,12 +15,10 @@ import { getCurrentAuthenticationMethod, setCurrentAuthenticationMethod } from ' import { randomEmail, randomName, uniqueId } from './../shared/random'; import * as testDb from './../shared/testDb'; import * as utils from '../shared/utils/'; - import { createLdapUser, createUser, getAllUsers, getLdapIdentities } from '../shared/db/users'; -import { UserRepository } from '@db/repositories/user.repository'; -import { AuthProviderSyncHistoryRepository } from '@db/repositories/authProviderSyncHistory.repository'; import { getPersonalProject } from '../shared/db/projects'; import { createLdapConfig, defaultLdapConfig } from '../shared/ldap'; +import type { SuperAgentTest } from '../shared/types'; jest.mock('@/telemetry'); diff --git a/packages/cli/test/integration/license.api.test.ts b/packages/cli/test/integration/license.api.test.ts index 370d36f436..4bf9dc2995 100644 --- a/packages/cli/test/integration/license.api.test.ts +++ b/packages/cli/test/integration/license.api.test.ts @@ -1,12 +1,13 @@ -import type { SuperAgentTest } from 'supertest'; import config from '@/config'; +import { RESPONSE_ERROR_MESSAGES } from '@/constants'; import type { User } from '@db/entities/User'; import type { ILicensePostResponse, ILicenseReadResponse } from '@/Interfaces'; import { License } from '@/License'; + import * as testDb from './shared/testDb'; import * as utils from './shared/utils/'; import { createUserShell } from './shared/db/users'; -import { RESPONSE_ERROR_MESSAGES } from '@/constants'; +import type { SuperAgentTest } from './shared/types'; const MOCK_SERVER_URL = 'https://server.com/v1'; const MOCK_RENEW_OFFSET = 259200; diff --git a/packages/cli/test/integration/me.api.test.ts b/packages/cli/test/integration/me.api.test.ts index 4e6a6be1fe..218c305c15 100644 --- a/packages/cli/test/integration/me.api.test.ts +++ b/packages/cli/test/integration/me.api.test.ts @@ -1,8 +1,8 @@ import { Container } from 'typedi'; -import type { SuperAgentTest } from 'supertest'; import { IsNull } from '@n8n/typeorm'; import validator from 'validator'; +import config from '@/config'; import type { User } from '@db/entities/User'; import { UserRepository } from '@db/repositories/user.repository'; import { ProjectRepository } from '@db/repositories/project.repository'; @@ -18,7 +18,7 @@ import { import * as testDb from './shared/testDb'; import * as utils from './shared/utils/'; import { addApiKey, createOwner, createUser, createUserShell } from './shared/db/users'; -import config from '@/config'; +import type { SuperAgentTest } from './shared/types'; const testServer = utils.setupTestServer({ endpointGroups: ['me'] }); diff --git a/packages/cli/test/integration/publicApi/credentials.test.ts b/packages/cli/test/integration/publicApi/credentials.test.ts index 378b3725c8..71406a0fd4 100644 --- a/packages/cli/test/integration/publicApi/credentials.test.ts +++ b/packages/cli/test/integration/publicApi/credentials.test.ts @@ -1,5 +1,8 @@ -import type { SuperAgentTest } from 'supertest'; +import { Container } from 'typedi'; + import type { User } from '@db/entities/User'; +import { CredentialsRepository } from '@db/repositories/credentials.repository'; +import { SharedCredentialsRepository } from '@db/repositories/sharedCredentials.repository'; import { randomApiKey, randomName, randomString } from '../shared/random'; import * as utils from '../shared/utils/'; @@ -7,9 +10,7 @@ import type { CredentialPayload, SaveCredentialFunction } from '../shared/types' import * as testDb from '../shared/testDb'; import { affixRoleToSaveCredential } from '../shared/db/credentials'; import { addApiKey, createUser, createUserShell } from '../shared/db/users'; -import { CredentialsRepository } from '@db/repositories/credentials.repository'; -import Container from 'typedi'; -import { SharedCredentialsRepository } from '@db/repositories/sharedCredentials.repository'; +import type { SuperAgentTest } from '../shared/types'; let owner: User; let member: User; diff --git a/packages/cli/test/integration/publicApi/executions.test.ts b/packages/cli/test/integration/publicApi/executions.test.ts index 6dfa8bd3bd..608eabfdf2 100644 --- a/packages/cli/test/integration/publicApi/executions.test.ts +++ b/packages/cli/test/integration/publicApi/executions.test.ts @@ -1,4 +1,3 @@ -import type { SuperAgentTest } from 'supertest'; import type { User } from '@db/entities/User'; import type { ActiveWorkflowManager } from '@/ActiveWorkflowManager'; @@ -17,6 +16,7 @@ import { createSuccessfulExecution, createWaitingExecution, } from '../shared/db/executions'; +import type { SuperAgentTest } from '../shared/types'; let owner: User; let user1: User; diff --git a/packages/cli/test/integration/publicApi/tags.test.ts b/packages/cli/test/integration/publicApi/tags.test.ts index 7e8fcacdea..70798efba4 100644 --- a/packages/cli/test/integration/publicApi/tags.test.ts +++ b/packages/cli/test/integration/publicApi/tags.test.ts @@ -1,5 +1,4 @@ -import type { SuperAgentTest } from 'supertest'; -import Container from 'typedi'; +import { Container } from 'typedi'; import type { User } from '@db/entities/User'; import { TagRepository } from '@db/repositories/tag.repository'; @@ -8,6 +7,7 @@ import * as utils from '../shared/utils/'; import * as testDb from '../shared/testDb'; import { createUser } from '../shared/db/users'; import { createTag } from '../shared/db/tags'; +import type { SuperAgentTest } from '../shared/types'; let owner: User; let member: User; diff --git a/packages/cli/test/integration/publicApi/users.ee.test.ts b/packages/cli/test/integration/publicApi/users.ee.test.ts index 8dfae84625..6e57a629d7 100644 --- a/packages/cli/test/integration/publicApi/users.ee.test.ts +++ b/packages/cli/test/integration/publicApi/users.ee.test.ts @@ -1,4 +1,3 @@ -import type { SuperAgentTest } from 'supertest'; import validator from 'validator'; import { v4 as uuid } from 'uuid'; @@ -9,6 +8,7 @@ import { randomApiKey } from '../shared/random'; import * as utils from '../shared/utils/'; import * as testDb from '../shared/testDb'; import { createUser, createUserShell } from '../shared/db/users'; +import type { SuperAgentTest } from '../shared/types'; mockInstance(License, { getUsersLimit: jest.fn().mockReturnValue(-1), diff --git a/packages/cli/test/integration/publicApi/workflows.test.ts b/packages/cli/test/integration/publicApi/workflows.test.ts index 21863b552c..eb4a7f461a 100644 --- a/packages/cli/test/integration/publicApi/workflows.test.ts +++ b/packages/cli/test/integration/publicApi/workflows.test.ts @@ -1,10 +1,12 @@ -import type { SuperAgentTest } from 'supertest'; -import config from '@/config'; -import Container from 'typedi'; +import { Container } from 'typedi'; import type { INode } from 'n8n-workflow'; + +import config from '@/config'; import { STARTING_NODES } from '@/constants'; import type { TagEntity } from '@db/entities/TagEntity'; import type { User } from '@db/entities/User'; +import type { Project } from '@db/entities/Project'; +import { ProjectRepository } from '@db/repositories/project.repository'; import { SharedWorkflowRepository } from '@db/repositories/sharedWorkflow.repository'; import { WorkflowHistoryRepository } from '@db/repositories/workflowHistory.repository'; import { ActiveWorkflowManager } from '@/ActiveWorkflowManager'; @@ -17,8 +19,7 @@ import { createUser } from '../shared/db/users'; import { createWorkflow, createWorkflowWithTrigger } from '../shared/db/workflows'; import { createTag } from '../shared/db/tags'; import { mockInstance } from '../../shared/mocking'; -import type { Project } from '@/databases/entities/Project'; -import { ProjectRepository } from '@/databases/repositories/project.repository'; +import type { SuperAgentTest } from '../shared/types'; let owner: User; let ownerPersonalProject: Project; diff --git a/packages/cli/test/integration/role.api.test.ts b/packages/cli/test/integration/role.api.test.ts index d5afc38f0c..c912d99a0d 100644 --- a/packages/cli/test/integration/role.api.test.ts +++ b/packages/cli/test/integration/role.api.test.ts @@ -1,13 +1,15 @@ -import type { SuperAgentTest } from 'supertest'; +import { Container } from 'typedi'; +import type { Scope } from '@n8n/permissions'; + +import type { GlobalRole } from '@db/entities/User'; +import type { ProjectRole } from '@db/entities/ProjectRelation'; +import type { CredentialSharingRole } from '@db/entities/SharedCredentials'; +import type { WorkflowSharingRole } from '@db/entities/SharedWorkflow'; +import { RoleService } from '@/services/role.service'; + import * as utils from './shared/utils/'; import { createMember } from './shared/db/users'; -import type { GlobalRole } from '@/databases/entities/User'; -import type { ProjectRole } from '@/databases/entities/ProjectRelation'; -import type { CredentialSharingRole } from '@/databases/entities/SharedCredentials'; -import type { WorkflowSharingRole } from '@/databases/entities/SharedWorkflow'; -import { RoleService } from '@/services/role.service'; -import Container from 'typedi'; -import type { Scope } from '@n8n/permissions'; +import type { SuperAgentTest } from './shared/types'; const testServer = utils.setupTestServer({ endpointGroups: ['role'], diff --git a/packages/cli/test/integration/saml/saml.api.test.ts b/packages/cli/test/integration/saml/saml.api.test.ts index c12f8da175..b9dbe7cb0f 100644 --- a/packages/cli/test/integration/saml/saml.api.test.ts +++ b/packages/cli/test/integration/saml/saml.api.test.ts @@ -1,6 +1,6 @@ import { Container } from 'typedi'; -import type { SuperAgentTest } from 'supertest'; import type { AuthenticationMethod } from 'n8n-workflow'; + import type { User } from '@db/entities/User'; import { setSamlLoginEnabled } from '@/sso/saml/samlHelpers'; import { getCurrentAuthenticationMethod, setCurrentAuthenticationMethod } from '@/sso/ssoHelpers'; @@ -12,6 +12,7 @@ import { randomEmail, randomName, randomValidPassword } from '../shared/random'; import * as utils from '../shared/utils/'; import { sampleConfig } from './sampleMetadata'; import { createOwner, createUser } from '../shared/db/users'; +import type { SuperAgentTest } from '../shared/types'; let someUser: User; let owner: User; diff --git a/packages/cli/test/integration/shared/augmentation.d.ts b/packages/cli/test/integration/shared/augmentation.d.ts deleted file mode 100644 index 4dfa538e9a..0000000000 --- a/packages/cli/test/integration/shared/augmentation.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import superagent = require('superagent'); - -/** - * Make `SuperTest` string-indexable. - */ -declare module 'supertest' { - interface SuperTest - extends superagent.SuperAgent, - Record {} -} diff --git a/packages/cli/test/integration/shared/types.ts b/packages/cli/test/integration/shared/types.ts index 0e74bb87b8..0352386590 100644 --- a/packages/cli/test/integration/shared/types.ts +++ b/packages/cli/test/integration/shared/types.ts @@ -1,6 +1,6 @@ import type { Application } from 'express'; import type { ICredentialDataDecryptedObject } from 'n8n-workflow'; -import type { SuperAgentTest } from 'supertest'; +import type TestAgent from 'supertest/lib/agent'; import type { Server } from 'http'; import type { CredentialsEntity } from '@db/entities/CredentialsEntity'; @@ -44,12 +44,14 @@ export interface SetupProps { quotas?: Partial<{ [K in NumericLicenseFeature]: number }>; } +export type SuperAgentTest = TestAgent; + export interface TestServer { app: Application; httpServer: Server; - authAgentFor: (user: User) => SuperAgentTest; - publicApiAgentFor: (user: User) => SuperAgentTest; - authlessAgent: SuperAgentTest; + authAgentFor: (user: User) => TestAgent; + publicApiAgentFor: (user: User) => TestAgent; + authlessAgent: TestAgent; license: LicenseMocker; } diff --git a/packages/cli/test/integration/tags.api.test.ts b/packages/cli/test/integration/tags.api.test.ts index 73be97a1c2..a452d68da8 100644 --- a/packages/cli/test/integration/tags.api.test.ts +++ b/packages/cli/test/integration/tags.api.test.ts @@ -1,8 +1,10 @@ +import { Container } from 'typedi'; + +import { TagRepository } from '@db/repositories/tag.repository'; + import * as utils from './shared/utils/'; import * as testDb from './shared/testDb'; -import type { SuperAgentTest } from 'supertest'; -import { TagRepository } from '@db/repositories/tag.repository'; -import Container from 'typedi'; +import type { SuperAgentTest } from './shared/types'; import { createUserShell } from './shared/db/users'; let authOwnerAgent: SuperAgentTest; diff --git a/packages/cli/test/integration/users.api.test.ts b/packages/cli/test/integration/users.api.test.ts index b164ae89a3..3c81a2560c 100644 --- a/packages/cli/test/integration/users.api.test.ts +++ b/packages/cli/test/integration/users.api.test.ts @@ -1,11 +1,15 @@ import Container from 'typedi'; -import type { SuperAgentTest } from 'supertest'; +import { v4 as uuid } from 'uuid'; +import { RESPONSE_ERROR_MESSAGES } from '@/constants'; import { UsersController } from '@/controllers/users.controller'; import type { User } from '@db/entities/User'; +import { ProjectRepository } from '@db/repositories/project.repository'; +import { ProjectRelationRepository } from '@db/repositories/projectRelation.repository'; import { UserRepository } from '@db/repositories/user.repository'; import { SharedCredentialsRepository } from '@db/repositories/sharedCredentials.repository'; import { SharedWorkflowRepository } from '@db/repositories/sharedWorkflow.repository'; +import { CacheService } from '@/services/cache/cache.service'; import { ExecutionService } from '@/executions/execution.service'; import { @@ -21,12 +25,8 @@ import { randomCredentialPayload } from './shared/random'; import * as utils from './shared/utils/'; import * as testDb from './shared/testDb'; import { mockInstance } from '../shared/mocking'; -import { RESPONSE_ERROR_MESSAGES } from '@/constants'; -import { ProjectRepository } from '@/databases/repositories/project.repository'; +import type { SuperAgentTest } from './shared/types'; import { createTeamProject, getPersonalProject, linkUserToProject } from './shared/db/projects'; -import { ProjectRelationRepository } from '@/databases/repositories/projectRelation.repository'; -import { CacheService } from '@/services/cache/cache.service'; -import { v4 as uuid } from 'uuid'; mockInstance(ExecutionService); diff --git a/packages/cli/test/integration/variables.test.ts b/packages/cli/test/integration/variables.test.ts index 8b84f67dcf..4a55427000 100644 --- a/packages/cli/test/integration/variables.test.ts +++ b/packages/cli/test/integration/variables.test.ts @@ -1,5 +1,5 @@ -import Container from 'typedi'; -import type { SuperAgentTest } from 'supertest'; +import { Container } from 'typedi'; + import type { Variables } from '@db/entities/Variables'; import { VariablesRepository } from '@db/repositories/variables.repository'; import { generateNanoId } from '@db/utils/generators'; @@ -8,6 +8,7 @@ import { VariablesService } from '@/environments/variables/variables.service.ee' import * as testDb from './shared/testDb'; import * as utils from './shared/utils/'; import { createOwner, createUser } from './shared/db/users'; +import type { SuperAgentTest } from './shared/types'; let authOwnerAgent: SuperAgentTest; let authMemberAgent: SuperAgentTest; diff --git a/packages/cli/test/integration/webhooks.api.test.ts b/packages/cli/test/integration/webhooks.api.test.ts index 9ec198693c..4858d1f7b4 100644 --- a/packages/cli/test/integration/webhooks.api.test.ts +++ b/packages/cli/test/integration/webhooks.api.test.ts @@ -1,5 +1,4 @@ import { readFileSync } from 'fs'; -import type { SuperAgentTest } from 'supertest'; import { agent as testAgent } from 'supertest'; import type { INodeType, INodeTypeDescription, IWebhookFunctions } from 'n8n-workflow'; @@ -15,6 +14,7 @@ import { initActiveWorkflowManager } from './shared/utils'; import * as testDb from './shared/testDb'; import { createUser } from './shared/db/users'; import { createWorkflow } from './shared/db/workflows'; +import type { SuperAgentTest } from './shared/types'; describe('Webhook API', () => { mockInstance(ExternalHooks); diff --git a/packages/cli/test/integration/workflowHistory.api.test.ts b/packages/cli/test/integration/workflowHistory.api.test.ts index b9ccd33b2c..881095d8fb 100644 --- a/packages/cli/test/integration/workflowHistory.api.test.ts +++ b/packages/cli/test/integration/workflowHistory.api.test.ts @@ -1,4 +1,3 @@ -import type { SuperAgentTest } from 'supertest'; import type { User } from '@db/entities/User'; import * as testDb from './shared/testDb'; @@ -6,6 +5,7 @@ import * as utils from './shared/utils/'; import { createOwner, createUser } from './shared/db/users'; import { createWorkflow } from './shared/db/workflows'; import { createWorkflowHistoryItem } from './shared/db/workflowHistory'; +import type { SuperAgentTest } from './shared/types'; let owner: User; let authOwnerAgent: SuperAgentTest; diff --git a/packages/cli/test/integration/workflows/workflows.controller.ee.test.ts b/packages/cli/test/integration/workflows/workflows.controller.ee.test.ts index daca15808d..68126824db 100644 --- a/packages/cli/test/integration/workflows/workflows.controller.ee.test.ts +++ b/packages/cli/test/integration/workflows/workflows.controller.ee.test.ts @@ -1,11 +1,16 @@ import Container from 'typedi'; -import type { SuperAgentTest } from 'supertest'; import { v4 as uuid } from 'uuid'; import type { INode } from 'n8n-workflow'; +import config from '@/config'; +import type { Project } from '@db/entities/Project'; +import { ProjectRepository } from '@db/repositories/project.repository'; import type { User } from '@db/entities/User'; import { WorkflowHistoryRepository } from '@db/repositories/workflowHistory.repository'; import { ActiveWorkflowManager } from '@/ActiveWorkflowManager'; +import { License } from '@/License'; +import { UserManagementMailer } from '@/UserManagement/email'; +import type { WorkflowWithSharingsMetaDataAndCredentials } from '@/workflows/workflows.types'; import { mockInstance } from '../../shared/mocking'; import * as utils from '../shared/utils/'; @@ -16,13 +21,8 @@ import { randomCredentialPayload } from '../shared/random'; import { affixRoleToSaveCredential, shareCredentialWithUsers } from '../shared/db/credentials'; import { createUser, createUserShell } from '../shared/db/users'; import { createWorkflow, getWorkflowSharing, shareWorkflowWithUsers } from '../shared/db/workflows'; -import { License } from '@/License'; -import { UserManagementMailer } from '@/UserManagement/email'; -import config from '@/config'; -import type { WorkflowWithSharingsMetaDataAndCredentials } from '@/workflows/workflows.types'; -import type { Project } from '@/databases/entities/Project'; -import { ProjectRepository } from '@/databases/repositories/project.repository'; import { createTag } from '../shared/db/tags'; +import type { SuperAgentTest } from '../shared/types'; let owner: User; let ownerPersonalProject: Project; diff --git a/packages/cli/test/integration/workflows/workflows.controller.test.ts b/packages/cli/test/integration/workflows/workflows.controller.test.ts index c0ba5e4917..fbfd674d31 100644 --- a/packages/cli/test/integration/workflows/workflows.controller.test.ts +++ b/packages/cli/test/integration/workflows/workflows.controller.test.ts @@ -1,15 +1,19 @@ import Container from 'typedi'; -import type { SuperAgentTest } from 'supertest'; import { v4 as uuid } from 'uuid'; import type { INode, IPinData } from 'n8n-workflow'; +import type { Scope } from '@n8n/permissions'; import type { User } from '@db/entities/User'; import { WorkflowRepository } from '@db/repositories/workflow.repository'; import type { WorkflowEntity } from '@db/entities/WorkflowEntity'; import type { ListQuery } from '@/requests'; import { WorkflowHistoryRepository } from '@db/repositories/workflowHistory.repository'; +import { SharedWorkflowRepository } from '@db/repositories/sharedWorkflow.repository'; +import { ProjectRepository } from '@db/repositories/project.repository'; +import { ProjectService } from '@/services/project.service'; import { ActiveWorkflowManager } from '@/ActiveWorkflowManager'; import { EnterpriseWorkflowService } from '@/workflows/workflow.service.ee'; +import { License } from '@/License'; import { mockInstance } from '../../shared/mocking'; import * as utils from '../shared/utils/'; @@ -20,12 +24,8 @@ import { saveCredential } from '../shared/db/credentials'; import { createManyUsers, createMember, createOwner } from '../shared/db/users'; import { createWorkflow, shareWorkflowWithProjects } from '../shared/db/workflows'; import { createTag } from '../shared/db/tags'; -import { License } from '@/License'; -import { SharedWorkflowRepository } from '@/databases/repositories/sharedWorkflow.repository'; -import { ProjectRepository } from '@/databases/repositories/project.repository'; -import { ProjectService } from '@/services/project.service'; import { createTeamProject, linkUserToProject } from '../shared/db/projects'; -import type { Scope } from '@n8n/permissions'; +import type { SuperAgentTest } from '../shared/types'; let owner: User; let member: User; diff --git a/packages/cli/test/unit/webhooks.test.ts b/packages/cli/test/unit/webhooks.test.ts index 3070a5d478..5fe8f937de 100644 --- a/packages/cli/test/unit/webhooks.test.ts +++ b/packages/cli/test/unit/webhooks.test.ts @@ -1,4 +1,4 @@ -import type { SuperAgentTest } from 'supertest'; +import type SuperAgentTest from 'supertest/lib/agent'; import { agent as testAgent } from 'supertest'; import { mock } from 'jest-mock-extended'; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c895f8e821..95590344e2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -111,8 +111,8 @@ importers: specifier: ^2.0.3 version: 2.0.3 supertest: - specifier: ^6.3.4 - version: 6.3.4 + specifier: ^7.0.0 + version: 7.0.0 ts-jest: specifier: ^29.1.1 version: 29.1.1(@babel/core@7.24.0)(jest@29.6.2)(typescript@5.4.2) @@ -838,8 +838,8 @@ importers: specifier: ^1.17.1 version: 1.17.1 '@types/superagent': - specifier: ^8.1.4 - version: 8.1.4 + specifier: ^8.1.7 + version: 8.1.7 '@types/swagger-ui-express': specifier: ^4.1.6 version: 4.1.6 @@ -10986,8 +10986,8 @@ packages: resolution: {integrity: sha512-n4sx2bqL0mW1tvDf/loQ+aMX7GQD3lc3fkCMC55VFNDu/vBOabO+LTIeXKM14xK0ppk5TUGcWRjiSpIlUpghKw==} dev: true - /@types/superagent@8.1.4: - resolution: {integrity: sha512-uzSBYwrpal8y2X2Pul5ZSWpzRiDha2FLcquaN95qUPnOjYgm/zQ5LIdqeJpQJTRWNTN+Rhm0aC8H06Ds2rqCYw==} + /@types/superagent@8.1.7: + resolution: {integrity: sha512-NmIsd0Yj4DDhftfWvvAku482PZum4DBW7U51OvS8gvOkDDY0WT1jsVyDV3hK+vplrsYw8oDwi9QxOM7U68iwww==} dependencies: '@types/cookiejar': 2.1.5 '@types/methods': 1.1.4 @@ -10998,7 +10998,7 @@ packages: resolution: {integrity: sha512-137ypx2lk/wTQbW6An6safu9hXmajAifU/s7szAHLN/FeIm5w7yR0Wkl9fdJMRSHwOn4HLAI0DaB2TOORuhPDg==} dependencies: '@types/methods': 1.1.4 - '@types/superagent': 8.1.4 + '@types/superagent': 8.1.7 dev: true /@types/swagger-ui-express@4.1.6: @@ -23795,9 +23795,9 @@ packages: ts-interface-checker: 0.1.13 dev: true - /superagent@8.1.2: - resolution: {integrity: sha512-6WTxW1EB6yCxV5VFOIPQruWGHqc3yI7hEmZK6h+pyk69Lk/Ut7rLUY6W/ONF2MjBuGjvmMiIpsrVJ2vjrHlslA==} - engines: {node: '>=6.4.0 <13 || >=14'} + /superagent@9.0.2: + resolution: {integrity: sha512-xuW7dzkUpcJq7QnhOsnNUgtYp3xRwpt2F7abdRYIpCsAt0hhUqia0EdxyXZQQpNmGtsCzYHryaKSV3q3GJnq7w==} + engines: {node: '>=14.18.0'} dependencies: component-emitter: 1.3.0 cookiejar: 2.1.4 @@ -23808,17 +23808,16 @@ packages: methods: 1.1.2 mime: 2.6.0 qs: 6.11.0 - semver: 7.6.0 transitivePeerDependencies: - supports-color dev: true - /supertest@6.3.4: - resolution: {integrity: sha512-erY3HFDG0dPnhw4U+udPfrzXa4xhSG+n4rxfRuZWCUvjFWwKl+OxWf/7zk50s84/fAAs7vf5QAb9uRa0cCykxw==} - engines: {node: '>=6.4.0'} + /supertest@7.0.0: + resolution: {integrity: sha512-qlsr7fIC0lSddmA3tzojvzubYxvlGtzumcdHgPwbFWMISQwL22MhM2Y3LNt+6w9Yyx7559VW5ab70dgphm8qQA==} + engines: {node: '>=14.18.0'} dependencies: methods: 1.1.2 - superagent: 8.1.2 + superagent: 9.0.2 transitivePeerDependencies: - supports-color dev: true