mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
refactor: Rewrite workflow public-api tests to avoid timeouts (no-changelog) (#5696)
This commit is contained in:
parent
6c74d41f23
commit
b4e60c3b47
|
@ -1,6 +1,6 @@
|
|||
import type express from 'express';
|
||||
import { Container } from 'typedi';
|
||||
import type { FindManyOptions, FindOptionsWhere } from 'typeorm';
|
||||
import type { FindOptionsWhere } from 'typeorm';
|
||||
import { In } from 'typeorm';
|
||||
|
||||
import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
|
||||
|
@ -20,12 +20,11 @@ import {
|
|||
updateWorkflow,
|
||||
hasStartNode,
|
||||
getStartNode,
|
||||
getWorkflows,
|
||||
getSharedWorkflows,
|
||||
getWorkflowsCount,
|
||||
createWorkflow,
|
||||
getWorkflowIdsViaTags,
|
||||
parseTagNames,
|
||||
getWorkflowsAndCount,
|
||||
} from './workflows.service';
|
||||
import { WorkflowsService } from '@/workflows/workflows.services';
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
|
@ -98,28 +97,15 @@ export = {
|
|||
async (req: WorkflowRequest.GetAll, res: express.Response): Promise<express.Response> => {
|
||||
const { offset = 0, limit = 100, active = undefined, tags = undefined } = req.query;
|
||||
|
||||
let workflows: WorkflowEntity[];
|
||||
let count: number;
|
||||
|
||||
const where: FindOptionsWhere<WorkflowEntity> = {
|
||||
...(active !== undefined && { active }),
|
||||
};
|
||||
const query: FindManyOptions<WorkflowEntity> = {
|
||||
skip: offset,
|
||||
take: limit,
|
||||
where,
|
||||
...(!config.getEnv('workflowTagsDisabled') && { relations: ['tags'] }),
|
||||
};
|
||||
|
||||
if (isInstanceOwner(req.user)) {
|
||||
if (tags) {
|
||||
const workflowIds = await getWorkflowIdsViaTags(parseTagNames(tags));
|
||||
Object.assign(where, { id: In(workflowIds) });
|
||||
where.id = In(workflowIds);
|
||||
}
|
||||
|
||||
workflows = await getWorkflows(query);
|
||||
|
||||
count = await getWorkflowsCount(query);
|
||||
} else {
|
||||
const options: { workflowIds?: string[] } = {};
|
||||
|
||||
|
@ -137,14 +123,16 @@ export = {
|
|||
}
|
||||
|
||||
const workflowsIds = sharedWorkflows.map((shareWorkflow) => shareWorkflow.workflowId);
|
||||
|
||||
Object.assign(where, { id: In(workflowsIds) });
|
||||
|
||||
workflows = await getWorkflows(query);
|
||||
|
||||
count = await getWorkflowsCount(query);
|
||||
where.id = In(workflowsIds);
|
||||
}
|
||||
|
||||
const [workflows, count] = await getWorkflowsAndCount({
|
||||
skip: offset,
|
||||
take: limit,
|
||||
where,
|
||||
...(!config.getEnv('workflowTagsDisabled') && { relations: ['tags'] }),
|
||||
});
|
||||
|
||||
void Container.get(InternalHooks).onUserRetrievedAllWorkflows({
|
||||
user_id: req.user.id,
|
||||
public_api: true,
|
||||
|
|
|
@ -109,14 +109,10 @@ export async function deleteWorkflow(workflow: WorkflowEntity): Promise<Workflow
|
|||
return Db.collections.Workflow.remove(workflow);
|
||||
}
|
||||
|
||||
export async function getWorkflows(
|
||||
export async function getWorkflowsAndCount(
|
||||
options: FindManyOptions<WorkflowEntity>,
|
||||
): Promise<WorkflowEntity[]> {
|
||||
return Db.collections.Workflow.find(options);
|
||||
}
|
||||
|
||||
export async function getWorkflowsCount(options: FindManyOptions<WorkflowEntity>): Promise<number> {
|
||||
return Db.collections.Workflow.count(options);
|
||||
): Promise<[WorkflowEntity[], number]> {
|
||||
return Db.collections.Workflow.findAndCount(options);
|
||||
}
|
||||
|
||||
export async function updateWorkflow(
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -172,7 +172,7 @@ export async function createUser(attributes: Partial<User> = {}): Promise<User>
|
|||
password: await hashPassword(password ?? randomValidPassword()),
|
||||
firstName: firstName ?? randomName(),
|
||||
lastName: lastName ?? randomName(),
|
||||
globalRole: globalRole ?? (await getGlobalMemberRole()),
|
||||
globalRoleId: (globalRole ?? (await getGlobalMemberRole())).id,
|
||||
...rest,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue