1
- import { SdkFacade , SdkFacadeConfiguration } from '@croct-tech/sdk' ;
1
+ import { Logger , SdkFacade , SdkFacadeConfiguration } from '@croct-tech/sdk' ;
2
2
import croct , { Configuration , Plugin , PluginController , PluginSdk } from '../src/index' ;
3
3
4
+ function createLoggerMock ( ) : Logger {
5
+ return {
6
+ debug : jest . fn ( ) ,
7
+ info : jest . fn ( ) ,
8
+ warn : jest . fn ( ) ,
9
+ error : jest . fn ( ) ,
10
+ } ;
11
+ }
12
+
4
13
describe ( 'The Croct plug' , ( ) => {
5
14
const appId = '7e9d59a9-e4b3-45d4-b1c7-48287f1e5e8a' ;
6
15
@@ -70,6 +79,31 @@ describe('The Croct plug', () => {
70
79
expect ( barPlugin . initialize ) . toBeCalled ( ) ;
71
80
} ) ;
72
81
82
+ test ( 'should log a warn message if multiple plugins share the same name' , async ( ) => {
83
+ const fooPlugin : Plugin = {
84
+ getName ( ) : string {
85
+ return 'foo' ;
86
+ } ,
87
+ initialize ( ) : void {
88
+ // does nothing
89
+ } ,
90
+ } ;
91
+
92
+ const logger : Logger = createLoggerMock ( ) ;
93
+
94
+ croct . plug ( {
95
+ appId : appId ,
96
+ plugins : [ fooPlugin , fooPlugin ] ,
97
+ logger : logger ,
98
+ } ) ;
99
+
100
+ await croct . plugged ;
101
+
102
+ expect ( logger . warn ) . toHaveBeenCalledWith (
103
+ expect . stringContaining ( 'Multiple plugins registered with name "foo" which may cause unexpected errors' ) ,
104
+ ) ;
105
+ } ) ;
106
+
73
107
test ( 'should handle failures enabling plugins' , async ( ) => {
74
108
const fooController : PluginController = {
75
109
enable : jest . fn ( ) . mockReturnValue ( Promise . reject ( new Error ( 'Failure' ) ) ) ,
@@ -80,7 +114,7 @@ describe('The Croct plug', () => {
80
114
return 'foo' ;
81
115
} ,
82
116
initialize ( ) : PluginController {
83
- return fooController
117
+ return fooController ;
84
118
} ,
85
119
} ;
86
120
@@ -107,7 +141,7 @@ describe('The Croct plug', () => {
107
141
initialize ( ) : PluginController {
108
142
return {
109
143
enable : fooEnable ,
110
- }
144
+ } ;
111
145
} ,
112
146
} ;
113
147
@@ -120,7 +154,7 @@ describe('The Croct plug', () => {
120
154
initialize ( ) : PluginController {
121
155
return {
122
156
enable : barEnable ,
123
- }
157
+ } ;
124
158
} ,
125
159
} ;
126
160
@@ -455,7 +489,7 @@ describe('The Croct plug', () => {
455
489
initialize ( ) : PluginController {
456
490
return {
457
491
disable : fooDisable ,
458
- }
492
+ } ;
459
493
} ,
460
494
} ;
461
495
@@ -468,7 +502,7 @@ describe('The Croct plug', () => {
468
502
initialize ( ) : PluginController {
469
503
return {
470
504
disable : barDisable ,
471
- }
505
+ } ;
472
506
} ,
473
507
} ;
474
508
@@ -529,7 +563,7 @@ describe('The Croct plug', () => {
529
563
return 'foo' ;
530
564
} ,
531
565
initialize ( ) : PluginController {
532
- return fooController
566
+ return fooController ;
533
567
} ,
534
568
} ;
535
569
0 commit comments