Skip to content

Commit 1a514df

Browse files
Eisha KaushalEisha Kaushal
authored andcommitted
modified tests
1 parent 05fbbf3 commit 1a514df

17 files changed

+1205
-57
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//const mongoose = require('mongoose');
2+
const mongo = require('../../chronos_npm_package/controllers/mongo');
3+
const ServicesModel = require( '../../chronos_npm_package/models/ServicesModel');
4+
require('dotenv').config();
5+
6+
jest.mock('mongoose', () => {
7+
return {
8+
connect: jest.fn().mockResolvedValue(undefined),
9+
};
10+
});
11+
12+
jest.spyOn(console, 'log').mockImplementation(() => {});
13+
14+
describe('mongo.connect', () => {
15+
beforeEach(() => {
16+
jest.clearAllMocks();
17+
});
18+
19+
test('should connect to MongoDB database', async () => {
20+
const databaseURI = 'mongodb://localhost:27017/testdb';
21+
await mongo.connect({ databaseURI });
22+
expect(mongoose.connect).toHaveBeenCalledWith(databaseURI);
23+
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('MongoDB database connected at'));
24+
});
25+
26+
test('should handle connection error', async () => {
27+
const errorMessage = 'Connection failed';
28+
const databaseURI = 'mongodb://localhost:27017/testdb';
29+
30+
jest.spyOn(mongoose, 'connect').mockRejectedValueOnce(new Error(errorMessage));
31+
32+
await mongo.connect({ databaseURI });
33+
expect(mongoose.connect).toHaveBeenCalledWith(databaseURI);
34+
expect(console.log).toHaveBeenCalledWith(expect.stringContaining(errorMessage));
35+
36+
});
37+
});
38+
39+
describe('mongo.services', () => {
40+
beforeEach(() => {
41+
jest.clearAllMocks();
42+
});
43+
44+
test('should create a new document', async () => {
45+
46+
});
47+
});

__backend-tests__/controllers/utilities.test.ts

Whitespace-only changes.

__backend-tests__/jest.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
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+

0 commit comments

Comments
 (0)