refactor(core): Improve community node repo code (#3767)

* 📘 Tighten `NodeRequest`

* :blue: Add `AuthAgent` type

*  Add constants

* 📘 Namespace npm types

* 🧪 Set up `createAuthAgent`

* 🧪 Refactor helpers tests

* 🧪 Refactor endpoints tests

*  Refactor CNR helpers

*  Return promises in `packageModel`

*  Refactor endpoints

* ✏️ Restore naming

*  Expose dependency `jest-mock`

* 📦 Update `package-lock.json`

* 📦 Update `package-lock.json`

* 👕 Fix lint

* 🚚 Rename namespace

* 🔥 Remove outdated comment

* 🐛 Fix `Promise` comparison

*  Undo `ResponseHelper` change

* ✏️ Document `ResponseError`

* 🎨 Fix formatting
This commit is contained in:
Iván Ovejero
2022-08-02 10:40:57 +02:00
committed by GitHub
parent ad8d662976
commit 7e578b7f4d
13 changed files with 1042 additions and 867 deletions

View File

@@ -23,7 +23,12 @@ import {
} from 'n8n-workflow';
import config from '../../../config';
import { AUTHLESS_ENDPOINTS, CURRENT_PACKAGE_VERSION, PUBLIC_API_REST_PATH_SEGMENT, REST_PATH_SEGMENT } from './constants';
import {
AUTHLESS_ENDPOINTS,
CURRENT_PACKAGE_VERSION,
PUBLIC_API_REST_PATH_SEGMENT,
REST_PATH_SEGMENT,
} from './constants';
import { AUTH_COOKIE_NAME, NODE_PACKAGE_PREFIX } from '../../../src/constants';
import { addRoutes as authMiddleware } from '../../../src/UserManagement/routes';
import {
@@ -56,6 +61,7 @@ import type { N8nApp } from '../../../src/UserManagement/Interfaces';
import { workflowsController } from '../../../src/api/workflows.api';
import { nodesController } from '../../../src/api/nodes.api';
import { randomName } from './random';
import { InstalledPackages } from '../../../src/databases/entities/InstalledPackages';
/**
* Initialize a test server.
@@ -101,7 +107,7 @@ export async function initTestServer({
credentials: { controller: credentialsController, path: 'credentials' },
workflows: { controller: workflowsController, path: 'workflows' },
nodes: { controller: nodesController, path: 'nodes' },
publicApi: apiRouters
publicApi: apiRouters,
};
for (const group of routerEndpoints) {
@@ -139,6 +145,9 @@ export function initTestTelemetry() {
void InternalHooksManager.init('test-instance-id', 'test-version', mockNodeTypes);
}
export const createAuthAgent = (app: express.Application) => (user: User) =>
createAgent(app, { auth: true, user });
/**
* Classify endpoint groups into `routerEndpoints` (newest, using `express.Router`),
* and `functionEndpoints` (legacy, namespaced inside a function).
@@ -893,7 +902,7 @@ export function getPostgresSchemaSection(
}
// ----------------------------------
// nodes
// community nodes
// ----------------------------------
export function installedPackagePayload(): InstalledPackagePayload {
@@ -912,3 +921,11 @@ export function installedNodePayload(packageName: string): InstalledNodePayload
package: packageName,
};
}
export const emptyPackage = () => {
const installedPackage = new InstalledPackages();
installedPackage.installedNodes = [];
return Promise.resolve(installedPackage);
};