@@ -3,7 +3,7 @@ const Chronos = require('../chronos_npm_package/chronos.js');
3
3
const helpers = require ( '../chronos_npm_package/controllers/utilities.js' ) ;
4
4
const hpropagate = require ( 'hpropagate' ) ;
5
5
const mongo = require ( '../chronos_npm_package/controllers/mongo.js' ) ;
6
- // utilities.addNotifications
6
+ const postgres = require ( '../chronos_npm_package/controllers/postgres.js' ) ;
7
7
8
8
// Mock the utilities module functions
9
9
jest . mock ( '../chronos_npm_package/controllers/utilities.js' , ( ) => ( {
@@ -23,6 +23,14 @@ jest.mock('../chronos_npm_package/controllers/mongo.js', () => ({
23
23
communications : jest . fn ( config => config ) ,
24
24
} ) ) ;
25
25
26
+ jest . mock ( '../chronos_npm_package/controllers/postgres.js' , ( ) => ( {
27
+ connect : jest . fn ( config => config ) ,
28
+ services : jest . fn ( config => config ) ,
29
+ docker : jest . fn ( config => config ) ,
30
+ health : jest . fn ( config => config ) ,
31
+ communications : jest . fn ( config => config ) ,
32
+ } ) ) ;
33
+
26
34
describe ( 'Chronos Config' , ( ) => {
27
35
afterEach ( ( ) => {
28
36
// Clear mock function calls after each test
@@ -78,7 +86,7 @@ describe('Chronos Config', () => {
78
86
} ) ;
79
87
80
88
describe ( 'track' , ( ) => {
81
- test ( 'should check if track function works' , ( ) => {
89
+ test ( 'should check if track function for MongoDB works' , ( ) => {
82
90
//check if we can destructure database and dockerized from config
83
91
const config = {
84
92
microservice : 'test' ,
@@ -104,5 +112,31 @@ describe('Chronos Config', () => {
104
112
if ( database . connection === 'REST' ) expect ( mongo . communications ) . not . toBeUndefined ( ) ;
105
113
}
106
114
} ) ;
115
+ test ( 'should check if track function for Postgres works' , ( ) => {
116
+ //check if we can destructure database and dockerized from config
117
+ const config = {
118
+ microservice : 'test' ,
119
+ interval : 300 ,
120
+ mode : 'micro' ,
121
+ dockerized : true ,
122
+ database : {
123
+ connection : 'REST' ,
124
+ type : 'PostgreSQL' ,
125
+ URI : process . env . CHRONOS_URI ,
126
+ } ,
127
+ notifications : [ ] ,
128
+ } ;
129
+ const { database, dockerized } = config ;
130
+ const falseDock = { dockerized : false } ;
131
+ const chronos = new Chronos ( config ) ;
132
+ chronos . track ( ) ;
133
+ if ( database . type === 'PostgreSQL' ) {
134
+ expect ( postgres . connect ) . toHaveBeenCalledWith ( config ) ;
135
+ expect ( postgres . services ) . toHaveBeenCalledWith ( config ) ;
136
+ if ( dockerized ) expect ( postgres . docker ) . toHaveBeenCalledWith ( config ) ;
137
+ if ( ! falseDock ) expect ( postgres . health ) . toHaveBeenCalledWith ( config ) ;
138
+ if ( database . connection === 'REST' ) expect ( postgres . communications ) . not . toBeUndefined ( ) ;
139
+ }
140
+ } ) ;
107
141
} ) ;
108
142
} ) ;
0 commit comments