|
| 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 | +}); |
0 commit comments