Skip to content

Commit 6637717

Browse files
committed
connect for postgres works
1 parent 3940f73 commit 6637717

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

__backend-tests__/chronosMethods.test.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const Chronos = require('../chronos_npm_package/chronos.js');
33
const helpers = require('../chronos_npm_package/controllers/utilities.js');
44
const hpropagate = require('hpropagate');
55
const mongo = require('../chronos_npm_package/controllers/mongo.js');
6-
// utilities.addNotifications
6+
const postgres = require('../chronos_npm_package/controllers/postgres.js');
77

88
// Mock the utilities module functions
99
jest.mock('../chronos_npm_package/controllers/utilities.js', () => ({
@@ -23,6 +23,14 @@ jest.mock('../chronos_npm_package/controllers/mongo.js', () => ({
2323
communications: jest.fn(config => config),
2424
}));
2525

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+
2634
describe('Chronos Config', () => {
2735
afterEach(() => {
2836
// Clear mock function calls after each test
@@ -78,7 +86,7 @@ describe('Chronos Config', () => {
7886
});
7987

8088
describe('track', () => {
81-
test('should check if track function works', () => {
89+
test('should check if track function for MongoDB works', () => {
8290
//check if we can destructure database and dockerized from config
8391
const config = {
8492
microservice: 'test',
@@ -104,5 +112,31 @@ describe('Chronos Config', () => {
104112
if (database.connection === 'REST') expect(mongo.communications).not.toBeUndefined();
105113
}
106114
});
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+
});
107141
});
108142
});

0 commit comments

Comments
 (0)