@@ -8,7 +8,10 @@ import type {
88 IExecutionContext ,
99} from 'n8n-workflow' ;
1010
11- import type { CredentialResolveMetadata } from '@/credentials/credential-resolution-provider.interface' ;
11+ import type {
12+ CredentialResolutionResult ,
13+ CredentialResolveMetadata ,
14+ } from '@/credentials/credential-resolution-provider.interface' ;
1215import type { LoadNodesAndCredentials } from '@/load-nodes-and-credentials' ;
1316import { StaticAuthService } from '@/services/static-auth-service' ;
1417
@@ -215,6 +218,11 @@ describe('DynamicCredentialService', () => {
215218 apiKey : 'static-key' ,
216219 } ;
217220
221+ const expectStaticResult = ( result : CredentialResolutionResult ) => {
222+ expect ( result . data ) . toBe ( staticData ) ;
223+ expect ( result . isDynamic ) . toBe ( false ) ;
224+ } ;
225+
218226 describe ( 'should return static credentials when' , ( ) => {
219227 it ( 'credential is not resolvable' , async ( ) => {
220228 const credentialsEntity = createMockCredentialsMetadata ( {
@@ -223,7 +231,7 @@ describe('DynamicCredentialService', () => {
223231
224232 const result = await service . resolveIfNeeded ( credentialsEntity , staticData , undefined ) ;
225233
226- expect ( result ) . toBe ( staticData ) ;
234+ expectStaticResult ( result ) ;
227235 expect ( mockResolverRepository . findOneBy ) . not . toHaveBeenCalled ( ) ;
228236 } ) ;
229237
@@ -236,7 +244,7 @@ describe('DynamicCredentialService', () => {
236244
237245 const result = await service . resolveIfNeeded ( credentialsEntity , staticData , undefined ) ;
238246
239- expect ( result ) . toBe ( staticData ) ;
247+ expectStaticResult ( result ) ;
240248 expect ( mockLogger . debug ) . toHaveBeenCalledWith (
241249 'Resolver not found, falling back to static credentials' ,
242250 expect . objectContaining ( {
@@ -257,7 +265,7 @@ describe('DynamicCredentialService', () => {
257265
258266 const result = await service . resolveIfNeeded ( credentialsEntity , staticData , undefined ) ;
259267
260- expect ( result ) . toBe ( staticData ) ;
268+ expectStaticResult ( result ) ;
261269 expect ( mockLogger . debug ) . toHaveBeenCalled ( ) ;
262270 } ) ;
263271
@@ -273,7 +281,7 @@ describe('DynamicCredentialService', () => {
273281
274282 const result = await service . resolveIfNeeded ( credentialsEntity , staticData , undefined ) ;
275283
276- expect ( result ) . toBe ( staticData ) ;
284+ expectStaticResult ( result ) ;
277285 expect ( mockLogger . debug ) . toHaveBeenCalledWith (
278286 'No execution context available, falling back to static credentials' ,
279287 expect . objectContaining ( {
@@ -304,7 +312,7 @@ describe('DynamicCredentialService', () => {
304312 undefined ,
305313 ) ;
306314
307- expect ( result ) . toBe ( staticData ) ;
315+ expectStaticResult ( result ) ;
308316 expect ( mockLogger . error ) . toHaveBeenCalledWith (
309317 'Failed to decrypt credential context from execution context' ,
310318 expect . any ( Object ) ,
@@ -334,7 +342,7 @@ describe('DynamicCredentialService', () => {
334342 undefined ,
335343 ) ;
336344
337- expect ( result ) . toBe ( staticData ) ;
345+ expectStaticResult ( result ) ;
338346 expect ( mockLogger . debug ) . toHaveBeenCalledWith (
339347 'Dynamic credential resolution failed, falling back to static' ,
340348 expect . objectContaining ( {
@@ -368,7 +376,7 @@ describe('DynamicCredentialService', () => {
368376 undefined ,
369377 ) ;
370378
371- expect ( result ) . toBe ( staticData ) ;
379+ expectStaticResult ( result ) ;
372380 expect ( mockLogger . debug ) . toHaveBeenCalledWith (
373381 'Dynamic credential resolution failed, falling back to static' ,
374382 expect . objectContaining ( {
@@ -543,7 +551,8 @@ describe('DynamicCredentialService', () => {
543551 ) ;
544552
545553 // Verify merge: static fields preserved, dynamic fields added/overridden
546- expect ( result ) . toEqual ( {
554+ expect ( result . isDynamic ) . toBe ( true ) ;
555+ expect ( result . data ) . toEqual ( {
547556 clientId : 'static-client-id' , // From static (preserved)
548557 clientSecret : 'static-client-secret' , // From static (preserved)
549558 token : 'dynamic-token' , // From dynamic (overridden)
@@ -664,7 +673,7 @@ describe('DynamicCredentialService', () => {
664673 undefined ,
665674 ) ;
666675
667- expect ( result ) . toBe ( staticData ) ;
676+ expectStaticResult ( result ) ;
668677 expect ( mockCipher . decrypt ) . not . toHaveBeenCalled ( ) ;
669678 } ) ;
670679
@@ -688,7 +697,7 @@ describe('DynamicCredentialService', () => {
688697 undefined ,
689698 ) ;
690699
691- expect ( result ) . toBe ( staticData ) ;
700+ expectStaticResult ( result ) ;
692701 expect ( mockLogger . debug ) . toHaveBeenCalled ( ) ;
693702 } ) ;
694703
@@ -757,7 +766,8 @@ describe('DynamicCredentialService', () => {
757766 expect ( mockResolverRepository . findOneBy ) . toHaveBeenCalledWith ( {
758767 id : 'workflow-resolver-789' ,
759768 } ) ;
760- expect ( result ) . toEqual ( { token : 'dynamic-token' , apiKey : 'dynamic-key' } ) ;
769+ expect ( result . isDynamic ) . toBe ( true ) ;
770+ expect ( result . data ) . toEqual ( { token : 'dynamic-token' , apiKey : 'dynamic-key' } ) ;
761771 expect ( mockLogger . debug ) . toHaveBeenCalledWith (
762772 'Successfully resolved dynamic credentials' ,
763773 expect . objectContaining ( {
@@ -800,7 +810,8 @@ describe('DynamicCredentialService', () => {
800810 expect ( mockResolverRepository . findOneBy ) . toHaveBeenCalledWith ( {
801811 id : 'credential-resolver-456' ,
802812 } ) ;
803- expect ( result ) . toEqual ( { token : 'dynamic-token' , apiKey : 'dynamic-key' } ) ;
813+ expect ( result . isDynamic ) . toBe ( true ) ;
814+ expect ( result . data ) . toEqual ( { token : 'dynamic-token' , apiKey : 'dynamic-key' } ) ;
804815 expect ( mockLogger . debug ) . toHaveBeenCalledWith (
805816 'Successfully resolved dynamic credentials' ,
806817 expect . objectContaining ( {
@@ -832,7 +843,7 @@ describe('DynamicCredentialService', () => {
832843 additionalData . workflowSettings ,
833844 ) ;
834845
835- expect ( result ) . toBe ( staticData ) ;
846+ expectStaticResult ( result ) ;
836847 expect ( mockLogger . debug ) . toHaveBeenCalledWith (
837848 'Resolver not found, falling back to static credentials' ,
838849 expect . objectContaining ( {
0 commit comments