1
1
import type { Logger } from '@n8n/backend-common' ;
2
2
import { GlobalConfig } from '@n8n/config' ;
3
3
import { captor , mock } from 'jest-mock-extended' ;
4
+ import { InstanceSettings } from 'n8n-core' ;
5
+ import type { InstanceType } from 'n8n-core' ;
4
6
5
7
import config from '@/config' ;
6
8
import { mockInstance } from '@test/mocking' ;
@@ -10,7 +12,8 @@ import { DeprecationService } from '../deprecation.service';
10
12
describe ( 'DeprecationService' , ( ) => {
11
13
const logger = mock < Logger > ( ) ;
12
14
const globalConfig = mockInstance ( GlobalConfig , { nodes : { exclude : [ ] } } ) ;
13
- const deprecationService = new DeprecationService ( logger , globalConfig ) ;
15
+ const instanceSettings = mockInstance ( InstanceSettings , { instanceType : 'main' } ) ;
16
+ const deprecationService = new DeprecationService ( logger , globalConfig , instanceSettings ) ;
14
17
15
18
beforeEach ( ( ) => {
16
19
// Ignore environment variables coming in from the environment when running
@@ -122,7 +125,7 @@ describe('DeprecationService', () => {
122
125
} ,
123
126
} ) ;
124
127
125
- new DeprecationService ( logger , globalConfig ) . warn ( ) ;
128
+ new DeprecationService ( logger , globalConfig , instanceSettings ) . warn ( ) ;
126
129
127
130
expect ( logger . warn ) . not . toHaveBeenCalled ( ) ;
128
131
} ) ;
@@ -140,62 +143,89 @@ describe('DeprecationService', () => {
140
143
} ) ;
141
144
} ) ;
142
145
143
- describe ( 'when executions.mode is queue' , ( ) => {
144
- test ( 'should warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is false' , ( ) => {
145
- process . env [ envVar ] = 'false' ;
146
-
147
- const service = new DeprecationService ( logger , globalConfig ) ;
148
- service . warn ( ) ;
146
+ describe ( 'when executions.mode is not queue' , ( ) => {
147
+ test . each ( [ [ 'main' ] , [ 'worker' ] , [ 'webhook' ] ] ) (
148
+ 'should not warn for instanceType %s' ,
149
+ ( instanceType : InstanceType ) => {
150
+ jest . spyOn ( config , 'getEnv' ) . mockImplementation ( ( key ) => {
151
+ if ( key === 'executions.mode' ) return 'regular' ;
152
+ return ;
153
+ } ) ;
154
+ process . env [ envVar ] = 'false' ;
155
+ const service = new DeprecationService (
156
+ logger ,
157
+ globalConfig ,
158
+ mock < InstanceSettings > ( { instanceType } ) ,
159
+ ) ;
160
+ service . warn ( ) ;
161
+ expect ( logger . warn ) . not . toHaveBeenCalled ( ) ;
162
+ } ,
163
+ ) ;
164
+ } ) ;
149
165
150
- expect ( logger . warn ) . toHaveBeenCalledTimes ( 1 ) ;
151
- const warningMessage = logger . warn . mock . calls [ 0 ] [ 0 ] ;
152
- expect ( warningMessage ) . toContain ( envVar ) ;
166
+ describe ( 'when executions.mode is queue' , ( ) => {
167
+ describe ( 'when instanceType is worker' , ( ) => {
168
+ test . each ( [
169
+ [ 'false' , 'false' ] ,
170
+ [ 'empty string' , '' ] ,
171
+ ] ) ( `should not warn when ${ envVar } is %s` , ( _description , envValue ) => {
172
+ process . env [ envVar ] = envValue ;
173
+ const service = new DeprecationService (
174
+ logger ,
175
+ globalConfig ,
176
+ mock < InstanceSettings > ( { instanceType : 'worker' } ) ,
177
+ ) ;
178
+ service . warn ( ) ;
179
+ expect ( logger . warn ) . not . toHaveBeenCalled ( ) ;
180
+ } ) ;
153
181
} ) ;
154
182
155
- test ( 'should warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is empty' , ( ) => {
156
- process . env [ envVar ] = '' ;
157
-
158
- const service = new DeprecationService ( logger , globalConfig ) ;
159
- service . warn ( ) ;
160
-
161
- expect ( logger . warn ) . toHaveBeenCalledTimes ( 1 ) ;
162
- const warningMessage = logger . warn . mock . calls [ 0 ] [ 0 ] ;
163
- expect ( warningMessage ) . toContain ( envVar ) ;
183
+ describe ( 'when instanceType is webhook' , ( ) => {
184
+ test . each ( [
185
+ [ 'false' , 'false' ] ,
186
+ [ 'empty string' , '' ] ,
187
+ ] ) ( `should not warn when ${ envVar } is %s` , ( _description , envValue ) => {
188
+ process . env [ envVar ] = envValue ;
189
+ const service = new DeprecationService (
190
+ logger ,
191
+ globalConfig ,
192
+ mock < InstanceSettings > ( { instanceType : 'webhook' } ) ,
193
+ ) ;
194
+ service . warn ( ) ;
195
+ expect ( logger . warn ) . not . toHaveBeenCalled ( ) ;
196
+ } ) ;
164
197
} ) ;
165
198
166
- test ( 'should not warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is true' , ( ) => {
167
- process . env [ envVar ] = 'true' ;
199
+ describe ( 'when instanceType is main' , ( ) => {
200
+ test . each ( [
201
+ [ 'false' , 'false' ] ,
202
+ [ 'empty string' , '' ] ,
203
+ ] ) ( `should warn when ${ envVar } is %s` , ( _description , envValue ) => {
204
+ process . env [ envVar ] = envValue ;
205
+ const service = new DeprecationService ( logger , globalConfig , instanceSettings ) ;
206
+ service . warn ( ) ;
207
+ expect ( logger . warn ) . toHaveBeenCalled ( ) ;
208
+ } ) ;
168
209
169
- const service = new DeprecationService ( logger , globalConfig ) ;
170
- service . warn ( ) ;
210
+ test ( 'should not warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is true' , ( ) => {
211
+ process . env [ envVar ] = 'true' ;
171
212
172
- expect ( logger . warn ) . not . toHaveBeenCalled ( ) ;
173
- } ) ;
213
+ const service = new DeprecationService ( logger , globalConfig , instanceSettings ) ;
214
+ service . warn ( ) ;
174
215
175
- test ( 'should warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is undefined' , ( ) => {
176
- delete process . env [ envVar ] ;
216
+ expect ( logger . warn ) . not . toHaveBeenCalled ( ) ;
217
+ } ) ;
177
218
178
- const service = new DeprecationService ( logger , globalConfig ) ;
179
- service . warn ( ) ;
219
+ test ( 'should warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is undefined' , ( ) => {
220
+ delete process . env [ envVar ] ;
180
221
181
- expect ( logger . warn ) . toHaveBeenCalledTimes ( 1 ) ;
182
- const warningMessage = logger . warn . mock . calls [ 0 ] [ 0 ] ;
183
- expect ( warningMessage ) . toContain ( envVar ) ;
184
- } ) ;
185
- } ) ;
222
+ const service = new DeprecationService ( logger , globalConfig , instanceSettings ) ;
223
+ service . warn ( ) ;
186
224
187
- describe ( 'when executions.mode is not queue' , ( ) => {
188
- test ( 'should not warn' , ( ) => {
189
- jest . spyOn ( config , 'getEnv' ) . mockImplementation ( ( key ) => {
190
- if ( key === 'executions.mode' ) return 'regular' ;
191
- return ;
225
+ expect ( logger . warn ) . toHaveBeenCalledTimes ( 1 ) ;
226
+ const warningMessage = logger . warn . mock . calls [ 0 ] [ 0 ] ;
227
+ expect ( warningMessage ) . toContain ( envVar ) ;
192
228
} ) ;
193
- process . env [ envVar ] = 'false' ;
194
-
195
- const service = new DeprecationService ( logger , globalConfig ) ;
196
- service . warn ( ) ;
197
-
198
- expect ( logger . warn ) . not . toHaveBeenCalled ( ) ;
199
229
} ) ;
200
230
} ) ;
201
231
} ) ;
0 commit comments