mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
fix(core): Comply with custom default for workflow saving settings (#7634)
https://linear.app/n8n/issue/PAY-982
This commit is contained in:
parent
ac877014ed
commit
48c068f97b
|
@ -1,20 +1,24 @@
|
||||||
import config from '@/config';
|
import config from '@/config';
|
||||||
import type { IWorkflowSettings } from 'n8n-workflow';
|
import type { IWorkflowSettings } from 'n8n-workflow';
|
||||||
|
|
||||||
const DEFAULTS = {
|
|
||||||
ERROR: config.getEnv('executions.saveDataOnError'),
|
|
||||||
SUCCESS: config.getEnv('executions.saveDataOnSuccess'),
|
|
||||||
MANUAL: config.getEnv('executions.saveDataManualExecutions'),
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether a workflow execution is configured to be saved or not,
|
* Return whether a workflow execution is configured to be saved or not,
|
||||||
* for error executions, success executions, and manual executions.
|
* for error executions, success executions, and manual executions.
|
||||||
*/
|
*/
|
||||||
export function toSaveSettings(workflowSettings: IWorkflowSettings = {}) {
|
export function toSaveSettings(workflowSettings: IWorkflowSettings = {}) {
|
||||||
|
const DEFAULTS = {
|
||||||
|
ERROR: config.getEnv('executions.saveDataOnError'),
|
||||||
|
SUCCESS: config.getEnv('executions.saveDataOnSuccess'),
|
||||||
|
MANUAL: config.getEnv('executions.saveDataManualExecutions'),
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
error: workflowSettings.saveDataErrorExecution !== 'none' ?? DEFAULTS.ERROR !== 'none',
|
error: workflowSettings.saveDataErrorExecution
|
||||||
success: workflowSettings.saveDataSuccessExecution !== 'none' ?? DEFAULTS.SUCCESS !== 'none',
|
? workflowSettings.saveDataErrorExecution !== 'none'
|
||||||
|
: DEFAULTS.ERROR !== 'none',
|
||||||
|
success: workflowSettings.saveDataSuccessExecution
|
||||||
|
? workflowSettings.saveDataSuccessExecution !== 'none'
|
||||||
|
: DEFAULTS.SUCCESS !== 'none',
|
||||||
manual: workflowSettings?.saveManualExecutions ?? DEFAULTS.MANUAL,
|
manual: workflowSettings?.saveManualExecutions ?? DEFAULTS.MANUAL,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,43 +145,96 @@ for (const mode of ['filesystem-v2', 's3'] as const) {
|
||||||
describe('toSaveSettings()', () => {
|
describe('toSaveSettings()', () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
jest.restoreAllMocks();
|
jest.restoreAllMocks();
|
||||||
|
config.load(config.default);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set `error` based on workflow settings', () => {
|
describe('when setting `error`', () => {
|
||||||
const saveSettings = toSaveSettings({ saveDataErrorExecution: 'all' });
|
it('should favor workflow settings over defaults', () => {
|
||||||
|
config.set('executions.saveDataOnError', 'none');
|
||||||
|
|
||||||
expect(saveSettings.error).toBe(true);
|
const saveSettings = toSaveSettings({ saveDataErrorExecution: 'all' });
|
||||||
|
|
||||||
const _saveSettings = toSaveSettings({ saveDataErrorExecution: 'none' });
|
expect(saveSettings.error).toBe(true);
|
||||||
|
|
||||||
expect(_saveSettings.error).toBe(false);
|
config.set('executions.saveDataOnError', 'all');
|
||||||
|
|
||||||
|
const _saveSettings = toSaveSettings({ saveDataErrorExecution: 'none' });
|
||||||
|
|
||||||
|
expect(_saveSettings.error).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fall back to default if no workflow setting', () => {
|
||||||
|
config.set('executions.saveDataOnError', 'all');
|
||||||
|
|
||||||
|
const saveSettings = toSaveSettings();
|
||||||
|
|
||||||
|
expect(saveSettings.error).toBe(true);
|
||||||
|
|
||||||
|
config.set('executions.saveDataOnError', 'none');
|
||||||
|
|
||||||
|
const _saveSettings = toSaveSettings();
|
||||||
|
|
||||||
|
expect(_saveSettings.error).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set `success` based on workflow settings', () => {
|
describe('when setting `success`', () => {
|
||||||
const saveSettings = toSaveSettings({ saveDataSuccessExecution: 'all' });
|
it('should favor workflow settings over defaults', () => {
|
||||||
|
config.set('executions.saveDataOnSuccess', 'none');
|
||||||
|
|
||||||
expect(saveSettings.success).toBe(true);
|
const saveSettings = toSaveSettings({ saveDataSuccessExecution: 'all' });
|
||||||
|
|
||||||
const _saveSettings = toSaveSettings({ saveDataSuccessExecution: 'none' });
|
expect(saveSettings.success).toBe(true);
|
||||||
|
|
||||||
expect(_saveSettings.success).toBe(false);
|
config.set('executions.saveDataOnSuccess', 'all');
|
||||||
|
|
||||||
|
const _saveSettings = toSaveSettings({ saveDataSuccessExecution: 'none' });
|
||||||
|
|
||||||
|
expect(_saveSettings.success).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fall back to default if no workflow setting', () => {
|
||||||
|
config.set('executions.saveDataOnSuccess', 'all');
|
||||||
|
|
||||||
|
const saveSettings = toSaveSettings();
|
||||||
|
|
||||||
|
expect(saveSettings.success).toBe(true);
|
||||||
|
|
||||||
|
config.set('executions.saveDataOnSuccess', 'none');
|
||||||
|
|
||||||
|
const _saveSettings = toSaveSettings();
|
||||||
|
|
||||||
|
expect(_saveSettings.success).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set `manual` based on workflow settings', () => {
|
describe('when setting `manual`', () => {
|
||||||
const saveSettings = toSaveSettings({ saveManualExecutions: true });
|
it('should favor workflow settings over defaults', () => {
|
||||||
|
config.set('executions.saveDataManualExecutions', false);
|
||||||
|
|
||||||
expect(saveSettings.manual).toBe(true);
|
const saveSettings = toSaveSettings({ saveManualExecutions: true });
|
||||||
|
|
||||||
const _saveSettings = toSaveSettings({ saveManualExecutions: false });
|
expect(saveSettings.manual).toBe(true);
|
||||||
|
|
||||||
expect(_saveSettings.manual).toBe(false);
|
config.set('executions.saveDataManualExecutions', true);
|
||||||
});
|
|
||||||
|
|
||||||
it('should return defaults if no workflow settings', async () => {
|
const _saveSettings = toSaveSettings({ saveManualExecutions: false });
|
||||||
const saveSettings = toSaveSettings();
|
|
||||||
|
|
||||||
expect(saveSettings.error).toBe(true);
|
expect(_saveSettings.manual).toBe(false);
|
||||||
expect(saveSettings.success).toBe(true);
|
});
|
||||||
expect(saveSettings.manual).toBe(true);
|
|
||||||
|
it('should fall back to default if no workflow setting', () => {
|
||||||
|
config.set('executions.saveDataManualExecutions', true);
|
||||||
|
|
||||||
|
const saveSettings = toSaveSettings();
|
||||||
|
|
||||||
|
expect(saveSettings.manual).toBe(true);
|
||||||
|
|
||||||
|
config.set('executions.saveDataManualExecutions', false);
|
||||||
|
|
||||||
|
const _saveSettings = toSaveSettings();
|
||||||
|
|
||||||
|
expect(_saveSettings.manual).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue