@@ -24,6 +24,7 @@ jest.mock('../chronos_npm_package/controllers/mongo.js', () => ({
2424 health : jest . fn ( config => config ) ,
2525 communications : jest . fn ( config => config ) ,
2626 serverQuery : jest . fn ( config => config ) ,
27+ storeGrafanaAPIKey : jest . fn ( config => config ) ,
2728} ) ) ;
2829
2930jest . mock ( '../chronos_npm_package/controllers/postgres.js' , ( ) => ( {
@@ -144,7 +145,7 @@ describe('Chronos Config', () => {
144145 } ) ;
145146 } ) ;
146147 describe ( 'kafka' , ( ) => {
147- test ( 'should check if kafka is functional' , async ( ) => {
148+ test ( 'should check if kafka with MongoDB functional' , async ( ) => {
148149 const config = {
149150 microservice : 'test' ,
150151 interval : 300 ,
@@ -166,6 +167,25 @@ describe('Chronos Config', () => {
166167 expect ( mongo . connect ) . toHaveBeenCalledWith ( config ) ;
167168 expect ( mongo . serverQuery ) . toHaveBeenCalledWith ( config ) ;
168169 }
170+ } ) ;
171+ test ( 'should check if kafka with PostgreSQL is functional' , async ( ) => {
172+ const config = {
173+ microservice : 'test' ,
174+ interval : 300 ,
175+ mode : 'micro' ,
176+ dockerized : true ,
177+ database : {
178+ connection : 'REST' ,
179+ type : 'PostgreSQL' ,
180+ URI : process . env . CHRONOS_URI ,
181+ } ,
182+ notifications : [ ] ,
183+ } ;
184+ const { database, dockerized } = config ;
185+ const falseDock = { dockerized : false } ;
186+ const chronos = new Chronos ( config ) ;
187+ chronos . kafka ( ) ;
188+ await helpers . testMetricsQuery ( config ) ;
169189 if ( database . type === 'PostgreSQL' ) {
170190 expect ( postgres . connect ) . toHaveBeenCalledWith ( config ) ;
171191 expect ( postgres . serverQuery ) . toHaveBeenCalledWith ( config ) ;
@@ -174,11 +194,11 @@ describe('Chronos Config', () => {
174194 } ) ;
175195
176196 describe ( 'kubernetes' , ( ) => {
177- test ( 'should check if kubernetes is functional' , async ( ) => {
197+ test ( 'should check if kubernetes with mongodb is functional' , async ( ) => {
178198 const config = {
179199 microservice : 'test' ,
180200 interval : 300 ,
181- mode : 'micro ' ,
201+ mode : 'kubernetes ' ,
182202 dockerized : true ,
183203 database : {
184204 connection : 'REST' ,
@@ -193,9 +213,33 @@ describe('Chronos Config', () => {
193213 chronos . kubernetes ( ) ;
194214 await helpers . testMetricsQuery ( config ) ;
195215 if ( database . type === 'MongoDB' ) {
196- expect ( mongo . connect ) . toHaveBeenCalledWith ( config ) ;
216+ await expect ( mongo . connect ) . toHaveBeenCalledWith ( config ) ;
217+ await expect ( mongo . storeGrafanaAPIKey ) . toHaveBeenCalledWith ( config ) ;
197218 expect ( mongo . serverQuery ) . toHaveBeenCalledWith ( config ) ;
198219 }
220+ if ( database . type === 'PostgreSQL' ) {
221+ expect ( postgres . connect ) . toHaveBeenCalledWith ( config2 ) ;
222+ expect ( postgres . serverQuery ) . toHaveBeenCalledWith ( config2 ) ;
223+ }
224+ } ) ;
225+ test ( 'should check if kubernetes with PostGres is functional' , async ( ) => {
226+ const config = {
227+ microservice : 'test' ,
228+ interval : 300 ,
229+ mode : 'kubernetes' ,
230+ dockerized : true ,
231+ database : {
232+ connection : 'REST' ,
233+ type : 'PostgreSQL' ,
234+ URI : process . env . CHRONOS_URI ,
235+ } ,
236+ notifications : [ ] ,
237+ } ;
238+ const { database, dockerized } = config ;
239+ const falseDock = { dockerized : false } ;
240+ const chronos = new Chronos ( config ) ;
241+ chronos . kubernetes ( ) ;
242+ await helpers . testMetricsQuery ( config ) ;
199243 if ( database . type === 'PostgreSQL' ) {
200244 expect ( postgres . connect ) . toHaveBeenCalledWith ( config ) ;
201245 expect ( postgres . serverQuery ) . toHaveBeenCalledWith ( config ) ;
0 commit comments