From a3cf3371db16eccdd4a56c8a602cf19a4a45ac81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Fri, 15 Mar 2024 18:39:49 +0100 Subject: [PATCH] delete duplicate mock settings, and fix the tests --- packages/editor-ui/src/__tests__/defaults.ts | 110 +++++++++++++++++- .../__tests__/server/endpoints/settings.ts | 110 +----------------- packages/editor-ui/src/__tests__/utils.ts | 90 +------------- .../src/stores/__tests__/posthog.test.ts | 2 + 4 files changed, 115 insertions(+), 197 deletions(-) diff --git a/packages/editor-ui/src/__tests__/defaults.ts b/packages/editor-ui/src/__tests__/defaults.ts index ded1b5f3229bf..eb65ba38e0a53 100644 --- a/packages/editor-ui/src/__tests__/defaults.ts +++ b/packages/editor-ui/src/__tests__/defaults.ts @@ -1,4 +1,4 @@ -import type { INodeTypeData, INodeTypeDescription } from 'n8n-workflow'; +import type { INodeTypeData, INodeTypeDescription, IN8nUISettings } from 'n8n-workflow'; import { AGENT_NODE_TYPE, CHAT_TRIGGER_NODE_TYPE, MANUAL_TRIGGER_NODE_TYPE } from '@/constants'; import nodeTypesJson from '../../../nodes-base/dist/types/nodes.json'; import aiNodeTypesJson from '../../../@n8n/nodes-langchain/dist/types/nodes.json'; @@ -42,3 +42,111 @@ export function mockNodeTypesToArray(nodeTypes: INodeTypeData): INodeTypeDescrip export const defaultMockNodeTypesArray: INodeTypeDescription[] = mockNodeTypesToArray(defaultMockNodeTypes); + +export const defaultSettings: IN8nUISettings = { + allowedModules: {}, + communityNodesEnabled: false, + defaultLocale: '', + endpointForm: '', + endpointFormTest: '', + endpointFormWaiting: '', + endpointWebhook: '', + endpointWebhookTest: '', + enterprise: { + sharing: false, + ldap: false, + saml: false, + logStreaming: false, + debugInEditor: false, + advancedExecutionFilters: false, + variables: true, + sourceControl: false, + auditLogs: false, + showNonProdBanner: false, + workflowHistory: false, + binaryDataS3: false, + externalSecrets: false, + workerView: false, + advancedPermissions: false, + }, + expressions: { + evaluator: 'tournament', + }, + executionMode: 'regular', + executionTimeout: 0, + hideUsagePage: false, + hiringBannerEnabled: false, + instanceId: '', + isNpmAvailable: false, + license: { environment: 'development' }, + logLevel: 'info', + maxExecutionTimeout: 0, + oauthCallbackUrls: { oauth1: '', oauth2: '' }, + onboardingCallPromptEnabled: false, + personalizationSurveyEnabled: false, + releaseChannel: 'stable', + posthog: { + apiHost: '', + apiKey: '', + autocapture: false, + debug: false, + disableSessionRecording: false, + enabled: false, + }, + publicApi: { enabled: false, latestVersion: 0, path: '', swaggerUi: { enabled: false } }, + pushBackend: 'websocket', + saveDataErrorExecution: 'DEFAULT', + saveDataSuccessExecution: 'DEFAULT', + saveManualExecutions: false, + sso: { + ldap: { loginEnabled: false, loginLabel: '' }, + saml: { loginEnabled: false, loginLabel: '' }, + }, + telemetry: { + enabled: false, + }, + templates: { enabled: false, host: '' }, + timezone: '', + urlBaseEditor: '', + urlBaseWebhook: '', + authCookie: { + secure: false, + }, + userManagement: { + showSetupOnFirstLoad: false, + smtpSetup: true, + authenticationMethod: 'email', + quota: 10, + }, + versionCli: '', + versionNotifications: { + enabled: true, + endpoint: '', + infoUrl: '', + }, + workflowCallerPolicyDefaultOption: 'any', + workflowTagsDisabled: false, + variables: { + limit: -1, + }, + deployment: { + type: 'default', + }, + banners: { + dismissed: [], + }, + binaryDataMode: 'default', + previewMode: false, + mfa: { + enabled: false, + }, + ai: { + enabled: false, + provider: '', + errorDebugging: false, + }, + workflowHistory: { + pruneTime: 0, + licensePruneTime: 0, + }, +}; diff --git a/packages/editor-ui/src/__tests__/server/endpoints/settings.ts b/packages/editor-ui/src/__tests__/server/endpoints/settings.ts index 59b4171ac9a1f..62050417fcea7 100644 --- a/packages/editor-ui/src/__tests__/server/endpoints/settings.ts +++ b/packages/editor-ui/src/__tests__/server/endpoints/settings.ts @@ -1,115 +1,7 @@ import type { Server } from 'miragejs'; import { Response } from 'miragejs'; import type { AppSchema } from '../types'; -import type { IN8nUISettings } from 'n8n-workflow'; - -const defaultSettings: IN8nUISettings = { - allowedModules: {}, - communityNodesEnabled: false, - defaultLocale: '', - endpointForm: '', - endpointFormTest: '', - endpointFormWaiting: '', - endpointWebhook: '', - endpointWebhookTest: '', - enterprise: { - sharing: false, - ldap: false, - saml: false, - logStreaming: false, - debugInEditor: false, - advancedExecutionFilters: false, - variables: true, - sourceControl: false, - auditLogs: false, - showNonProdBanner: false, - workflowHistory: false, - binaryDataS3: false, - externalSecrets: false, - workerView: false, - advancedPermissions: false, - }, - expressions: { - evaluator: 'tournament', - }, - executionMode: 'regular', - executionTimeout: 0, - hideUsagePage: false, - hiringBannerEnabled: false, - instanceId: '', - isNpmAvailable: false, - license: { environment: 'development' }, - logLevel: 'info', - maxExecutionTimeout: 0, - oauthCallbackUrls: { oauth1: '', oauth2: '' }, - onboardingCallPromptEnabled: false, - personalizationSurveyEnabled: false, - releaseChannel: 'stable', - posthog: { - apiHost: '', - apiKey: '', - autocapture: false, - debug: false, - disableSessionRecording: false, - enabled: false, - }, - publicApi: { enabled: false, latestVersion: 0, path: '', swaggerUi: { enabled: false } }, - pushBackend: 'websocket', - saveDataErrorExecution: 'DEFAULT', - saveDataSuccessExecution: 'DEFAULT', - saveManualExecutions: false, - sso: { - ldap: { loginEnabled: false, loginLabel: '' }, - saml: { loginEnabled: false, loginLabel: '' }, - }, - telemetry: { - enabled: false, - }, - templates: { enabled: false, host: '' }, - timezone: '', - urlBaseEditor: '', - urlBaseWebhook: '', - authCookie: { - secure: false, - }, - userManagement: { - showSetupOnFirstLoad: false, - smtpSetup: true, - authenticationMethod: 'email', - quota: 10, - }, - versionCli: '', - versionNotifications: { - enabled: true, - endpoint: '', - infoUrl: '', - }, - workflowCallerPolicyDefaultOption: 'any', - workflowTagsDisabled: false, - variables: { - limit: -1, - }, - deployment: { - type: 'default', - }, - banners: { - dismissed: [], - }, - binaryDataMode: 'default', - previewMode: false, - mfa: { - enabled: false, - }, - ai: { - enabled: false, - provider: '', - errorDebugging: false, - }, - workflowHistory: { - pruneTime: 0, - licensePruneTime: 0, - }, -}; +import { defaultSettings } from '../../defaults'; export function routesForSettings(server: Server) { server.get('/rest/settings', (schema: AppSchema) => { diff --git a/packages/editor-ui/src/__tests__/utils.ts b/packages/editor-ui/src/__tests__/utils.ts index 8168b94ae0523..3e62559f74cb2 100644 --- a/packages/editor-ui/src/__tests__/utils.ts +++ b/packages/editor-ui/src/__tests__/utils.ts @@ -1,5 +1,6 @@ import type { ISettingsState } from '@/Interface'; import { UserManagementAuthenticationMethod } from '@/Interface'; +import { defaultSettings } from './defaults'; export const retry = async ( assertion: () => ReturnType, @@ -25,92 +26,7 @@ export const retry = async ( export const waitAllPromises = async () => await new Promise((resolve) => setTimeout(resolve)); export const SETTINGS_STORE_DEFAULT_STATE: ISettingsState = { - settings: { - allowedModules: {}, - communityNodesEnabled: false, - defaultLocale: '', - endpointForm: '', - endpointFormTest: '', - endpointFormWaiting: '', - endpointWebhook: '', - endpointWebhookTest: '', - enterprise: { - advancedExecutionFilters: false, - sharing: false, - ldap: false, - saml: false, - logStreaming: false, - variables: false, - sourceControl: false, - auditLogs: false, - }, - executionMode: 'regular', - executionTimeout: 0, - hideUsagePage: false, - hiringBannerEnabled: false, - instanceId: '', - isNpmAvailable: false, - license: { environment: 'production' }, - logLevel: 'info', - maxExecutionTimeout: 0, - oauthCallbackUrls: { oauth1: '', oauth2: '' }, - onboardingCallPromptEnabled: false, - personalizationSurveyEnabled: false, - posthog: { - apiHost: '', - apiKey: '', - autocapture: false, - debug: false, - disableSessionRecording: false, - enabled: false, - }, - publicApi: { enabled: false, latestVersion: 0, path: '', swaggerUi: { enabled: false } }, - pushBackend: 'sse', - saveDataErrorExecution: 'all', - saveDataSuccessExecution: 'all', - saveManualExecutions: false, - sso: { - ldap: { loginEnabled: false, loginLabel: '' }, - saml: { loginEnabled: false, loginLabel: '' }, - }, - telemetry: { enabled: false }, - templates: { enabled: false, host: '' }, - timezone: '', - urlBaseEditor: '', - urlBaseWebhook: '', - userManagement: { - enabled: false, - smtpSetup: false, - authenticationMethod: UserManagementAuthenticationMethod.Email, - }, - versionCli: '', - versionNotifications: { - enabled: false, - endpoint: '', - infoUrl: '', - }, - workflowCallerPolicyDefaultOption: 'any', - workflowTagsDisabled: false, - deployment: { - type: 'default', - }, - variables: { - limit: 100, - }, - expressions: { - evaluator: 'tournament', - }, - banners: { - dismissed: [], - }, - ai: { - enabled: false, - }, - workflowHistory: { - pruneTime: -1, - licensePruneTime: -1, - }, - }, + settings: defaultSettings, promptsData: { message: '', title: '', @@ -118,10 +34,10 @@ export const SETTINGS_STORE_DEFAULT_STATE: ISettingsState = { showValueSurvey: false, }, userManagement: { - enabled: false, showSetupOnFirstLoad: false, smtpSetup: false, authenticationMethod: UserManagementAuthenticationMethod.Email, + quota: defaultSettings.userManagement.quota, }, templatesEndpointHealthy: false, api: { diff --git a/packages/editor-ui/src/stores/__tests__/posthog.test.ts b/packages/editor-ui/src/stores/__tests__/posthog.test.ts index d485dc5af60d0..c007ab0d7ca51 100644 --- a/packages/editor-ui/src/stores/__tests__/posthog.test.ts +++ b/packages/editor-ui/src/stores/__tests__/posthog.test.ts @@ -7,6 +7,7 @@ import { useTelemetryStore } from '@/stores/telemetry.store'; import type { IN8nUISettings } from 'n8n-workflow'; import { LOCAL_STORAGE_EXPERIMENT_OVERRIDES } from '@/constants'; import { nextTick } from 'vue'; +import { defaultSettings } from '../../__tests__/defaults'; const DEFAULT_POSTHOG_SETTINGS: IN8nUISettings['posthog'] = { enabled: true, @@ -21,6 +22,7 @@ const CURRENT_INSTANCE_ID = '456'; function setSettings(overrides?: Partial) { useSettingsStore().setSettings({ + ...defaultSettings, posthog: DEFAULT_POSTHOG_SETTINGS, instanceId: CURRENT_INSTANCE_ID, ...overrides,