From aecd4c3c4eb73d3ee7db5924ae5772d9c65092b0 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 27 Dec 2023 20:39:43 +0000 Subject: [PATCH 1/3] feat: Add unit test for getSiblings function in re --- backend/test/regionController.test.js | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 backend/test/regionController.test.js diff --git a/backend/test/regionController.test.js b/backend/test/regionController.test.js new file mode 100644 index 0000000..23f8f69 --- /dev/null +++ b/backend/test/regionController.test.js @@ -0,0 +1,39 @@ +// backend/test/regionController.test.js + +// Import necessary modules and functions +const { getSiblings } = require('../controllers/regionController'); +const { Region } = require('../models/Region'); + +// Test cases for getSiblings function +describe('getSiblings', () => { + // Test case for when the region exists + test('should return an array of sibling regions when the region exists', () => { + // Create a mock region + const region = new Region({ name: 'Region A' }); + + // Mock the Region.findOne method to return the mock region + Region.findOne = jest.fn().mockResolvedValue(region); + + // Call the getSiblings function + const siblings = getSiblings('Region A'); + + // Assert that the result is an array of sibling regions + expect(Array.isArray(siblings)).toBe(true); + expect(siblings).toHaveLength(2); + expect(siblings).toContainEqual({ name: 'Region B' }); + expect(siblings).toContainEqual({ name: 'Region C' }); + }); + + // Test case for when the region does not exist + test('should return an empty array when the region does not exist', () => { + // Mock the Region.findOne method to return null + Region.findOne = jest.fn().mockResolvedValue(null); + + // Call the getSiblings function + const siblings = getSiblings('Region D'); + + // Assert that the result is an empty array + expect(Array.isArray(siblings)).toBe(true); + expect(siblings).toHaveLength(0); + }); +}); From 82cafa071fd6d3e246f164f80e480a5347f9b2dd Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 27 Dec 2023 20:39:50 +0000 Subject: [PATCH 2/3] feat: Create unit test for getSiblings function in --- backend/test/Hierarchy.test.js | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 backend/test/Hierarchy.test.js diff --git a/backend/test/Hierarchy.test.js b/backend/test/Hierarchy.test.js new file mode 100644 index 0000000..955576f --- /dev/null +++ b/backend/test/Hierarchy.test.js @@ -0,0 +1,38 @@ +// backend/test/Hierarchy.test.js + +// Import necessary modules and functions +const { getSiblings } = require('../models/Hierarchy'); + +// Test cases for getSiblings function +describe('getSiblings', () => { + // Test case for when there are siblings + test('should return an array of sibling hierarchies when there are siblings', () => { + // Create a mock hierarchy + const hierarchy = { id: 1, name: 'Hierarchy A' }; + + // Mock the Hierarchy.findOne method to return the mock hierarchy + Hierarchy.findOne = jest.fn().mockResolvedValue(hierarchy); + + // Call the getSiblings function + const siblings = getSiblings(1); + + // Assert that the result is an array of sibling hierarchies + expect(Array.isArray(siblings)).toBe(true); + expect(siblings).toHaveLength(2); + expect(siblings).toContainEqual({ id: 2, name: 'Hierarchy B' }); + expect(siblings).toContainEqual({ id: 3, name: 'Hierarchy C' }); + }); + + // Test case for when there are no siblings + test('should return an empty array when there are no siblings', () => { + // Mock the Hierarchy.findOne method to return null + Hierarchy.findOne = jest.fn().mockResolvedValue(null); + + // Call the getSiblings function + const siblings = getSiblings(4); + + // Assert that the result is an empty array + expect(Array.isArray(siblings)).toBe(true); + expect(siblings).toHaveLength(0); + }); +}); From 60ec56b537989003cca94f7507f536b0d034d769 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 27 Dec 2023 20:39:56 +0000 Subject: [PATCH 3/3] feat: Modify backend/test/package.json to include --- backend/test/package.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 backend/test/package.json diff --git a/backend/test/package.json b/backend/test/package.json new file mode 100644 index 0000000..0d03977 --- /dev/null +++ b/backend/test/package.json @@ -0,0 +1,11 @@ +{ + "name": "backend-test", + "version": "1.0.0", + "description": "Unit tests for the backend", + "scripts": { + "test": "jest regionController.test.js Hierarchy.test.js" + }, + "devDependencies": { + "jest": "^27.0.6" + } +}