first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
import {
|
||||
mockInstance,
|
||||
testDb,
|
||||
createWorkflowWithTriggerAndHistory,
|
||||
getWorkflowById,
|
||||
} from '@n8n/backend-test-utils';
|
||||
|
||||
import { PublishWorkflowCommand } from '@/commands/publish/workflow';
|
||||
import { LoadNodesAndCredentials } from '@/load-nodes-and-credentials';
|
||||
import { setupTestCommand } from '@test-integration/utils/test-command';
|
||||
|
||||
mockInstance(LoadNodesAndCredentials);
|
||||
const command = setupTestCommand(PublishWorkflowCommand);
|
||||
|
||||
beforeEach(async () => {
|
||||
await testDb.truncate(['WorkflowEntity', 'WorkflowHistory']);
|
||||
});
|
||||
|
||||
test('publish:workflow can publish a specific workflow version', async () => {
|
||||
//
|
||||
// ARRANGE
|
||||
//
|
||||
const workflow = await createWorkflowWithTriggerAndHistory();
|
||||
|
||||
//
|
||||
// ACT
|
||||
//
|
||||
await command.run([`--id=${workflow.id}`, `--versionId=${workflow.versionId}`]);
|
||||
|
||||
//
|
||||
// ASSERT
|
||||
//
|
||||
const updatedWorkflow = await getWorkflowById(workflow.id);
|
||||
|
||||
expect(updatedWorkflow).toMatchObject({
|
||||
activeVersionId: workflow.versionId,
|
||||
active: true,
|
||||
});
|
||||
});
|
||||
|
||||
test('publish:workflow does not publish when --all flag is used', async () => {
|
||||
//
|
||||
// ARRANGE
|
||||
//
|
||||
const workflow = await createWorkflowWithTriggerAndHistory();
|
||||
|
||||
//
|
||||
// ACT
|
||||
//
|
||||
await command.run(['--all', `--id=${workflow.id}`, `--versionId=${workflow.versionId}`]);
|
||||
|
||||
//
|
||||
// ASSERT
|
||||
//
|
||||
// Verify the workflow was not published (--all flag prevents publishing)
|
||||
const unchangedWorkflow = await getWorkflowById(workflow.id);
|
||||
expect(unchangedWorkflow).toMatchObject({
|
||||
activeVersionId: null,
|
||||
active: false,
|
||||
});
|
||||
});
|
||||
|
||||
test('publish:workflow publishes current version when --versionId is missing', async () => {
|
||||
//
|
||||
// ARRANGE
|
||||
//
|
||||
const workflow = await createWorkflowWithTriggerAndHistory();
|
||||
|
||||
//
|
||||
// ACT
|
||||
//
|
||||
await command.run([`--id=${workflow.id}`]);
|
||||
|
||||
//
|
||||
// ASSERT
|
||||
//
|
||||
const updatedWorkflow = await getWorkflowById(workflow.id);
|
||||
expect(updatedWorkflow).toMatchObject({
|
||||
activeVersionId: workflow.versionId,
|
||||
active: true,
|
||||
});
|
||||
});
|
||||
|
||||
test('unpublish:workflow throws error when workflow does not exist', async () => {
|
||||
//
|
||||
// ARRANGE
|
||||
//
|
||||
const nonExistentWorkflowId = 'non-existent-workflow-id';
|
||||
|
||||
//
|
||||
// ACT & ASSERT
|
||||
//
|
||||
await expect(command.run([`--id=${nonExistentWorkflowId}`])).rejects.toThrow(
|
||||
`Workflow "${nonExistentWorkflowId}" not found.`,
|
||||
);
|
||||
});
|
||||
|
||||
test('publish:workflow throws error when version does not exist', async () => {
|
||||
//
|
||||
// ARRANGE
|
||||
//
|
||||
const workflow = await createWorkflowWithTriggerAndHistory();
|
||||
const nonExistentVersionId = 'non-existent-version';
|
||||
|
||||
//
|
||||
// ACT & ASSERT
|
||||
//
|
||||
await expect(
|
||||
command.run([`--id=${workflow.id}`, `--versionId=${nonExistentVersionId}`]),
|
||||
).rejects.toThrow(`Version "${nonExistentVersionId}" not found for workflow "${workflow.id}".`);
|
||||
});
|
||||
Reference in New Issue
Block a user