Skip to content

Commit 1ffa2ec

Browse files
committed
working on track fn on chronos.js
1 parent deab2b7 commit 1ffa2ec

File tree

2 files changed

+88
-13
lines changed

2 files changed

+88
-13
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const Chronos = require('../chronos_npm_package/chronos.js');
2+
const helpers = require('../chronos_npm_package/controllers/utilities.js');
3+
const hpropagate = require('hpropagate');
4+
5+
// utilities.addNotifications
6+
7+
// Mock the utilities module functions
8+
jest.mock('../chronos_npm_package/controllers/utilities.js', () => ({
9+
validateInput: jest.fn(config => config),
10+
addNotifications: jest.fn(config => config),
11+
}));
12+
13+
// mock propogate from Chronos
14+
jest.mock('hpropagate');
15+
16+
describe('Chronos Config', () => {
17+
afterEach(() => {
18+
// Clear mock function calls after each test
19+
jest.clearAllMocks();
20+
});
21+
22+
test('should throw an error if config is undefined', () => {
23+
expect(() => new Chronos()).toThrow('Chronos config is undefined');
24+
});
25+
26+
test('should call utilities functions with the correct parm', () => {
27+
const config = {
28+
microservice: 'test',
29+
interval: 300,
30+
mode: 'micro',
31+
dockerized: false,
32+
database: {
33+
connection: 'REST',
34+
type: process.env.CHRONOS_DB,
35+
URI: process.env.CHRONOS_URI,
36+
},
37+
notifications: [],
38+
};
39+
40+
const chronos = new Chronos(config);
41+
42+
// Ensure the config property is correctly set in the instance
43+
expect(chronos.config).toEqual(config);
44+
// Ensure the constructor called the validateInput and addNotifications functions
45+
expect(helpers.validateInput).toHaveBeenCalledWith(config);
46+
expect(helpers.addNotifications).toHaveBeenCalledWith(config);
47+
});
48+
49+
describe('propagate', () => {
50+
test('should check if propagate func properply calls hpropagate', () => {
51+
const config = {
52+
microservice: 'test',
53+
interval: 300,
54+
mode: 'micro',
55+
dockerized: false,
56+
database: {
57+
connection: 'REST',
58+
type: process.env.CHRONOS_DB,
59+
URI: process.env.CHRONOS_URI,
60+
},
61+
notifications: [],
62+
};
63+
64+
const chronos = new Chronos(config);
65+
chronos.propagate();
66+
expect(hpropagate).toHaveBeenCalledWith({ propagateInResponses: true });
67+
});
68+
});
69+
70+
describe('track', () => {
71+
test('should check if track function works', () => {
72+
//check if we can destructure database and dockerized from config
73+
74+
})
75+
});
76+
});

__backend-tests__/jest.config.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
module.exports = {
2-
testEnvironment: 'node', // Use the Node.js environment for testing
3-
roots: ['<rootDir>/controllers'], // Set the root directory for test files (adjust this path to your test folder)
4-
5-
testRegex: '(/tests/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
6-
7-
// Code coverage settings
8-
collectCoverage: true,
9-
coverageDirectory: 'coverage',
10-
11-
// Specify the test path patterns to ignore (frontend tests)
12-
testPathIgnorePatterns: ['/node_modules/', '/__tests__/'],
13-
};
14-
2+
testEnvironment: 'node', // Use the Node.js environment for testing
3+
roots: ['<rootDir>'], // Set the root directory for test files (adjust this path to your test folder)
4+
5+
testRegex: '(/tests/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
6+
7+
// Code coverage settings
8+
collectCoverage: true,
9+
coverageDirectory: 'coverage',
10+
11+
// Specify the test path patterns to ignore (frontend tests)
12+
testPathIgnorePatterns: ['/node_modules/', '/__tests__/'],
13+
};

0 commit comments

Comments
 (0)