Skip to content

Commit 3940f73

Browse files
committed
completed connect for mongo
1 parent 1ffa2ec commit 3940f73

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

__backend-tests__/chronosMethods.test.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
const { EcoTwoTone } = require('@material-ui/icons');
12
const Chronos = require('../chronos_npm_package/chronos.js');
23
const helpers = require('../chronos_npm_package/controllers/utilities.js');
34
const hpropagate = require('hpropagate');
4-
5+
const mongo = require('../chronos_npm_package/controllers/mongo.js');
56
// utilities.addNotifications
67

78
// Mock the utilities module functions
@@ -13,6 +14,15 @@ jest.mock('../chronos_npm_package/controllers/utilities.js', () => ({
1314
// mock propogate from Chronos
1415
jest.mock('hpropagate');
1516

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+
1626
describe('Chronos Config', () => {
1727
afterEach(() => {
1828
// Clear mock function calls after each test
@@ -70,7 +80,29 @@ describe('Chronos Config', () => {
7080
describe('track', () => {
7181
test('should check if track function works', () => {
7282
//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+
});
75107
});
76108
});

0 commit comments

Comments
 (0)