refactor: Rewrite workflow public-api tests to avoid timeouts (no-changelog) (#5696)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2023-03-15 14:24:09 +01:00 committed by GitHub
parent 6c74d41f23
commit b4e60c3b47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 926 additions and 1291 deletions

View file

@ -1,6 +1,6 @@
import type express from 'express'; import type express from 'express';
import { Container } from 'typedi'; import { Container } from 'typedi';
import type { FindManyOptions, FindOptionsWhere } from 'typeorm'; import type { FindOptionsWhere } from 'typeorm';
import { In } from 'typeorm'; import { In } from 'typeorm';
import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner'; import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
@ -20,12 +20,11 @@ import {
updateWorkflow, updateWorkflow,
hasStartNode, hasStartNode,
getStartNode, getStartNode,
getWorkflows,
getSharedWorkflows, getSharedWorkflows,
getWorkflowsCount,
createWorkflow, createWorkflow,
getWorkflowIdsViaTags, getWorkflowIdsViaTags,
parseTagNames, parseTagNames,
getWorkflowsAndCount,
} from './workflows.service'; } from './workflows.service';
import { WorkflowsService } from '@/workflows/workflows.services'; import { WorkflowsService } from '@/workflows/workflows.services';
import { InternalHooks } from '@/InternalHooks'; import { InternalHooks } from '@/InternalHooks';
@ -98,28 +97,15 @@ export = {
async (req: WorkflowRequest.GetAll, res: express.Response): Promise<express.Response> => { async (req: WorkflowRequest.GetAll, res: express.Response): Promise<express.Response> => {
const { offset = 0, limit = 100, active = undefined, tags = undefined } = req.query; const { offset = 0, limit = 100, active = undefined, tags = undefined } = req.query;
let workflows: WorkflowEntity[];
let count: number;
const where: FindOptionsWhere<WorkflowEntity> = { const where: FindOptionsWhere<WorkflowEntity> = {
...(active !== undefined && { active }), ...(active !== undefined && { active }),
}; };
const query: FindManyOptions<WorkflowEntity> = {
skip: offset,
take: limit,
where,
...(!config.getEnv('workflowTagsDisabled') && { relations: ['tags'] }),
};
if (isInstanceOwner(req.user)) { if (isInstanceOwner(req.user)) {
if (tags) { if (tags) {
const workflowIds = await getWorkflowIdsViaTags(parseTagNames(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 { } else {
const options: { workflowIds?: string[] } = {}; const options: { workflowIds?: string[] } = {};
@ -137,14 +123,16 @@ export = {
} }
const workflowsIds = sharedWorkflows.map((shareWorkflow) => shareWorkflow.workflowId); const workflowsIds = sharedWorkflows.map((shareWorkflow) => shareWorkflow.workflowId);
where.id = In(workflowsIds);
Object.assign(where, { id: In(workflowsIds) });
workflows = await getWorkflows(query);
count = await getWorkflowsCount(query);
} }
const [workflows, count] = await getWorkflowsAndCount({
skip: offset,
take: limit,
where,
...(!config.getEnv('workflowTagsDisabled') && { relations: ['tags'] }),
});
void Container.get(InternalHooks).onUserRetrievedAllWorkflows({ void Container.get(InternalHooks).onUserRetrievedAllWorkflows({
user_id: req.user.id, user_id: req.user.id,
public_api: true, public_api: true,

View file

@ -109,14 +109,10 @@ export async function deleteWorkflow(workflow: WorkflowEntity): Promise<Workflow
return Db.collections.Workflow.remove(workflow); return Db.collections.Workflow.remove(workflow);
} }
export async function getWorkflows( export async function getWorkflowsAndCount(
options: FindManyOptions<WorkflowEntity>, options: FindManyOptions<WorkflowEntity>,
): Promise<WorkflowEntity[]> { ): Promise<[WorkflowEntity[], number]> {
return Db.collections.Workflow.find(options); return Db.collections.Workflow.findAndCount(options);
}
export async function getWorkflowsCount(options: FindManyOptions<WorkflowEntity>): Promise<number> {
return Db.collections.Workflow.count(options);
} }
export async function updateWorkflow( export async function updateWorkflow(

File diff suppressed because it is too large Load diff

View file

@ -172,7 +172,7 @@ export async function createUser(attributes: Partial<User> = {}): Promise<User>
password: await hashPassword(password ?? randomValidPassword()), password: await hashPassword(password ?? randomValidPassword()),
firstName: firstName ?? randomName(), firstName: firstName ?? randomName(),
lastName: lastName ?? randomName(), lastName: lastName ?? randomName(),
globalRole: globalRole ?? (await getGlobalMemberRole()), globalRoleId: (globalRole ?? (await getGlobalMemberRole())).id,
...rest, ...rest,
}; };