1
+ const { EcoTwoTone } = require ( '@material-ui/icons' ) ;
1
2
const Chronos = require ( '../chronos_npm_package/chronos.js' ) ;
2
3
const helpers = require ( '../chronos_npm_package/controllers/utilities.js' ) ;
3
4
const hpropagate = require ( 'hpropagate' ) ;
4
-
5
+ const mongo = require ( '../chronos_npm_package/controllers/mongo.js' ) ;
5
6
// utilities.addNotifications
6
7
7
8
// Mock the utilities module functions
@@ -13,6 +14,15 @@ jest.mock('../chronos_npm_package/controllers/utilities.js', () => ({
13
14
// mock propogate from Chronos
14
15
jest . mock ( 'hpropagate' ) ;
15
16
17
+ //mock fns found in track
18
+ jest . mock ( '../chronos_npm_package/controllers/mongo.js' , ( ) => ( {
19
+ connect : jest . fn ( config => config ) ,
20
+ services : jest . fn ( config => config ) ,
21
+ docker : jest . fn ( config => config ) ,
22
+ health : jest . fn ( config => config ) ,
23
+ communications : jest . fn ( config => config ) ,
24
+ } ) ) ;
25
+
16
26
describe ( 'Chronos Config' , ( ) => {
17
27
afterEach ( ( ) => {
18
28
// Clear mock function calls after each test
@@ -70,7 +80,29 @@ describe('Chronos Config', () => {
70
80
describe ( 'track' , ( ) => {
71
81
test ( 'should check if track function works' , ( ) => {
72
82
//check if we can destructure database and dockerized from config
73
-
74
- } )
83
+ const config = {
84
+ microservice : 'test' ,
85
+ interval : 300 ,
86
+ mode : 'micro' ,
87
+ dockerized : true ,
88
+ database : {
89
+ connection : 'REST' ,
90
+ type : 'MongoDB' ,
91
+ URI : process . env . CHRONOS_URI ,
92
+ } ,
93
+ notifications : [ ] ,
94
+ } ;
95
+ const { database, dockerized } = config ;
96
+ const falseDock = { dockerized : false } ;
97
+ const chronos = new Chronos ( config ) ;
98
+ chronos . track ( ) ;
99
+ if ( database . type === 'MongoDB' ) {
100
+ expect ( mongo . connect ) . toHaveBeenCalledWith ( config ) ;
101
+ expect ( mongo . services ) . toHaveBeenCalledWith ( config ) ;
102
+ if ( dockerized ) expect ( mongo . docker ) . toHaveBeenCalledWith ( config ) ;
103
+ if ( ! falseDock ) expect ( mongo . health ) . toHaveBeenCalledWith ( config ) ;
104
+ if ( database . connection === 'REST' ) expect ( mongo . communications ) . not . toBeUndefined ( ) ;
105
+ }
106
+ } ) ;
75
107
} ) ;
76
108
} ) ;
0 commit comments