mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 16:44:07 -08:00
596c472ecc
Signed-off-by: Oleg Ivaniv <me@olegivaniv.com> Co-authored-by: Val <68596159+valya@users.noreply.github.com> Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in> Co-authored-by: Valya Bullions <valya@n8n.io> Co-authored-by: Danny Martini <danny@n8n.io> Co-authored-by: Danny Martini <despair.blue@gmail.com> Co-authored-by: Iván Ovejero <ivov.src@gmail.com> Co-authored-by: Omar Ajoue <krynble@gmail.com> Co-authored-by: oleg <me@olegivaniv.com> Co-authored-by: Michael Kret <michael.k@radency.com> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: Elias Meire <elias@meire.dev> Co-authored-by: Giulio Andreini <andreini@netseven.it> Co-authored-by: Giulio Andreini <g.andreini@gmail.com> Co-authored-by: Ayato Hayashi <go12limchangyong@gmail.com>
86 lines
2.7 KiB
TypeScript
86 lines
2.7 KiB
TypeScript
import Container from 'typedi';
|
|
import { mock } from 'jest-mock-extended';
|
|
import { ActiveWorkflowManager } from '@/ActiveWorkflowManager';
|
|
import { SharedWorkflowRepository } from '@db/repositories/sharedWorkflow.repository';
|
|
import { WorkflowRepository } from '@db/repositories/workflow.repository';
|
|
import { MessageEventBus } from '@/eventbus/MessageEventBus/MessageEventBus';
|
|
import { Telemetry } from '@/telemetry';
|
|
import { OrchestrationService } from '@/services/orchestration.service';
|
|
import { WorkflowService } from '@/workflows/workflow.service';
|
|
|
|
import * as testDb from '../shared/testDb';
|
|
import { mockInstance } from '../../shared/mocking';
|
|
import { createOwner } from '../shared/db/users';
|
|
import { createWorkflow } from '../shared/db/workflows';
|
|
|
|
let workflowService: WorkflowService;
|
|
const activeWorkflowManager = mockInstance(ActiveWorkflowManager);
|
|
const orchestrationService = mockInstance(OrchestrationService);
|
|
mockInstance(MessageEventBus);
|
|
mockInstance(Telemetry);
|
|
|
|
beforeAll(async () => {
|
|
await testDb.init();
|
|
|
|
workflowService = new WorkflowService(
|
|
mock(),
|
|
Container.get(SharedWorkflowRepository),
|
|
Container.get(WorkflowRepository),
|
|
mock(),
|
|
mock(),
|
|
mock(),
|
|
mock(),
|
|
mock(),
|
|
orchestrationService,
|
|
mock(),
|
|
activeWorkflowManager,
|
|
mock(),
|
|
mock(),
|
|
mock(),
|
|
mock(),
|
|
);
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await testDb.truncate(['Workflow']);
|
|
jest.restoreAllMocks();
|
|
});
|
|
|
|
describe('update()', () => {
|
|
test('should remove and re-add to active workflows on `active: true` payload', async () => {
|
|
const owner = await createOwner();
|
|
const workflow = await createWorkflow({ active: true }, owner);
|
|
|
|
const removeSpy = jest.spyOn(activeWorkflowManager, 'remove');
|
|
const addSpy = jest.spyOn(activeWorkflowManager, 'add');
|
|
|
|
await workflowService.update(owner, workflow, workflow.id);
|
|
|
|
expect(removeSpy).toHaveBeenCalledTimes(1);
|
|
const [removedWorkflowId] = removeSpy.mock.calls[0];
|
|
expect(removedWorkflowId).toBe(workflow.id);
|
|
|
|
expect(addSpy).toHaveBeenCalledTimes(1);
|
|
const [addedWorkflowId, activationMode] = addSpy.mock.calls[0];
|
|
expect(addedWorkflowId).toBe(workflow.id);
|
|
expect(activationMode).toBe('update');
|
|
});
|
|
|
|
test('should remove from active workflows on `active: false` payload', async () => {
|
|
const owner = await createOwner();
|
|
const workflow = await createWorkflow({ active: true }, owner);
|
|
|
|
const removeSpy = jest.spyOn(activeWorkflowManager, 'remove');
|
|
const addSpy = jest.spyOn(activeWorkflowManager, 'add');
|
|
|
|
workflow.active = false;
|
|
await workflowService.update(owner, workflow, workflow.id);
|
|
|
|
expect(removeSpy).toHaveBeenCalledTimes(1);
|
|
const [removedWorkflowId] = removeSpy.mock.calls[0];
|
|
expect(removedWorkflowId).toBe(workflow.id);
|
|
|
|
expect(addSpy).not.toHaveBeenCalled();
|
|
});
|
|
});
|