mirror of
https://github.com/n8n-io/n8n.git
synced 2026-07-27 19:15:01 +02:00
fix(core): Fix MCP workflow update failing for active workflows on SQLite (#34964)
This commit is contained in:
parent
082b5d9190
commit
bc88dc4bd2
|
|
@ -61,6 +61,7 @@ export class WorkflowFinderService {
|
|||
relations: { workflow: true },
|
||||
select: {
|
||||
workflowId: true,
|
||||
projectId: true,
|
||||
workflow: { id: true, versionId: true, updatedAt: true },
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
import { createWorkflow, testDb } from '@n8n/backend-test-utils';
|
||||
import { GLOBAL_MEMBER_ROLE, GLOBAL_OWNER_ROLE, type User } from '@n8n/db';
|
||||
import { Container } from '@n8n/di';
|
||||
|
||||
import { WorkflowFinderService } from '@/workflows/workflow-finder.service';
|
||||
|
||||
import { createUser } from '../shared/db/users';
|
||||
|
||||
let owner: User;
|
||||
let member: User;
|
||||
let anotherMember: User;
|
||||
let workflowFinderService: WorkflowFinderService;
|
||||
|
||||
beforeAll(async () => {
|
||||
await testDb.init();
|
||||
owner = await createUser({ role: GLOBAL_OWNER_ROLE });
|
||||
member = await createUser({ role: GLOBAL_MEMBER_ROLE });
|
||||
anotherMember = await createUser({ role: GLOBAL_MEMBER_ROLE });
|
||||
workflowFinderService = Container.get(WorkflowFinderService);
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await testDb.truncate(['WorkflowEntity', 'SharedWorkflow']);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await testDb.terminate();
|
||||
});
|
||||
|
||||
describe('WorkflowFinderService', () => {
|
||||
describe('findWorkflowHeadForUser', () => {
|
||||
it('should return the workflow head for a user with a project-scoped role', async () => {
|
||||
const workflow = await createWorkflow({}, member);
|
||||
|
||||
const head = await workflowFinderService.findWorkflowHeadForUser(workflow.id, member, [
|
||||
'workflow:publish',
|
||||
]);
|
||||
|
||||
expect(head?.versionId).toBe(workflow.versionId);
|
||||
expect(head?.updatedAt).toBeInstanceOf(Date);
|
||||
});
|
||||
|
||||
it('should return the workflow head for a user with a global scope', async () => {
|
||||
const workflow = await createWorkflow({}, member);
|
||||
|
||||
const head = await workflowFinderService.findWorkflowHeadForUser(workflow.id, owner, [
|
||||
'workflow:publish',
|
||||
]);
|
||||
|
||||
expect(head?.versionId).toBe(workflow.versionId);
|
||||
expect(head?.updatedAt).toBeInstanceOf(Date);
|
||||
});
|
||||
|
||||
it('should return null for a user without access to the workflow', async () => {
|
||||
const workflow = await createWorkflow({}, member);
|
||||
|
||||
const head = await workflowFinderService.findWorkflowHeadForUser(workflow.id, anotherMember, [
|
||||
'workflow:publish',
|
||||
]);
|
||||
|
||||
expect(head).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user