From ab13a295fd6f378562c21cff659fbe089976b722 Mon Sep 17 00:00:00 2001 From: Raushan Singh <19raushaniiitu@gmail.com> Date: Tue, 3 Feb 2026 15:17:51 +0530 Subject: [PATCH 1/7] Add src/__tests__/notifications.test.ts --- src/__tests__/notifications.test.ts | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/__tests__/notifications.test.ts diff --git a/src/__tests__/notifications.test.ts b/src/__tests__/notifications.test.ts new file mode 100644 index 0000000..ba44f49 --- /dev/null +++ b/src/__tests__/notifications.test.ts @@ -0,0 +1,34 @@ +import { sendNotification } from '../services/notifications'; + +jest.mock('../services/notifications', () => ({ + sendNotification: jest.fn(), +})); + +describe('Notifications Service', () => { + it('should send notification with correct parameters', async () => { + const notification = { + userId: 'user-1', + type: 'TASK_COMPLETED', + data: { taskId: 'task-123' } + }; + + await sendNotification(notification); + + expect(sendNotification).toHaveBeenCalledWith(notification); + expect(sendNotification).toHaveBeenCalledTimes(1); + }); + + it('should handle errors without throwing', async () => { + const errorMock = jest.fn().mockRejectedValue(new Error('Network error')); + const notification = { + userId: 'user-1', + type: 'TASK_COMPLETED', + data: { taskId: 'task-123' } + }; + + sendNotification.mockImplementationOnce(errorMock); + + await expect(sendNotification(notification)).resolves.not.toThrow(); + expect(sendNotification).toHaveBeenCalledWith(notification); + }); +}); \ No newline at end of file From b4a69ee85d662d0f15486eef2b3a3fbf6f3fc205 Mon Sep 17 00:00:00 2001 From: Raushan Singh <19raushaniiitu@gmail.com> Date: Tue, 3 Feb 2026 19:35:15 +0530 Subject: [PATCH 2/7] Address comment from @CodeForContribute: tests/test_latest_changes.py --- tests/test_latest_changes.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/test_latest_changes.py diff --git a/tests/test_latest_changes.py b/tests/test_latest_changes.py new file mode 100644 index 0000000..50b54f0 --- /dev/null +++ b/tests/test_latest_changes.py @@ -0,0 +1,12 @@ +import unittest +from my_module import latest_changes_function + +class TestLatestChanges(unittest.TestCase): + def test_latest_changes_function(self): + # Assuming latest_changes_function should return True for valid input + input_data = 'some valid input' + expected_output = True + self.assertEqual(latest_changes_function(input_data), expected_output) + +if __name__ == '__main__': + unittest.main() From e221ca3bf3384dd7171f69b02230c7ed0109dfc6 Mon Sep 17 00:00:00 2001 From: Raushan Singh <19raushaniiitu@gmail.com> Date: Tue, 3 Feb 2026 20:15:09 +0530 Subject: [PATCH 3/7] Add src/__tests__/codeReview.test.ts --- src/__tests__/codeReview.test.ts | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/__tests__/codeReview.test.ts diff --git a/src/__tests__/codeReview.test.ts b/src/__tests__/codeReview.test.ts new file mode 100644 index 0000000..a047ad4 --- /dev/null +++ b/src/__tests__/codeReview.test.ts @@ -0,0 +1,51 @@ +import { test, describe, expect } from '@jest/globals'; +import { handleCodeReview } from '../services/github'; + +// Mock data for testing +const mockPullRequestData = { + id: 1, + title: 'Add new feature', + comments: [ + { + id: 101, + body: 'Please update the README.', + user: { + login: 'reviewer1' + } + }, + { + id: 102, + body: 'LGTM', + user: { + login: 'reviewer2' + } + } + ] +}; + +const mockReviewHandlerResponse = { + updated: true, + messages: ['Reviewed: Please update the README.'] +}; + +// Mock the actual function that will handle the business logic +jest.mock('../services/github', () => ({ + handleCodeReview: jest.fn(() => mockReviewHandlerResponse) +})); + +describe('Code Review Feature', () => { + test('should process code review comments correctly', async () => { + const response = await handleCodeReview(mockPullRequestData); + + expect(response.updated).toBe(true); + expect(response.messages.length).toBeGreaterThan(0); + expect(response.messages[0]).toBe('Reviewed: Please update the README.'); + }); + + test('should handle empty comments', async () => { + const response = await handleCodeReview({ ...mockPullRequestData, comments: [] }); + + expect(response.updated).toBe(false); + expect(response.messages.length).toBe(0); + }); +}); From c3901a556d5136d069d68cc157962722f81b4385 Mon Sep 17 00:00:00 2001 From: Raushan Singh <19raushaniiitu@gmail.com> Date: Tue, 3 Feb 2026 20:23:34 +0530 Subject: [PATCH 4/7] Address comment from @CodeForContribute: tests/test_code_review_feature.py --- tests/test_code_review_feature.py | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/test_code_review_feature.py diff --git a/tests/test_code_review_feature.py b/tests/test_code_review_feature.py new file mode 100644 index 0000000..eb86aa7 --- /dev/null +++ b/tests/test_code_review_feature.py @@ -0,0 +1,39 @@ +import unittest +from code_review_module import CodeReviewFeature + +class TestCodeReviewFeature(unittest.TestCase): + + def setUp(self): + self.feature = CodeReviewFeature() + + def test_feature_initialization(self): + """Test that the feature initializes correctly""" + self.assertIsNotNone(self.feature) + + def test_add_review_comment(self): + """Test adding a review comment""" + comment = "This is a test comment." + self.feature.add_comment(comment) + self.assertIn(comment, self.feature.comments) + + def test_remove_review_comment(self): + """Test removing a review comment""" + comment = "This is a test comment." + self.feature.add_comment(comment) + self.feature.remove_comment(comment) + self.assertNotIn(comment, self.feature.comments) + + def test_add_duplicate_comment(self): + """Test adding a duplicate comment raises ValueError""" + comment = "This is a duplicate comment." + self.feature.add_comment(comment) + with self.assertRaises(ValueError): + self.feature.add_comment(comment) + + def test_remove_nonexistent_comment(self): + """Test removing a non-existent comment raises ValueError""" + with self.assertRaises(ValueError): + self.feature.remove_comment("Non-existent comment") + +if __name__ == "__main__": + unittest.main() From ba8952380b2bfb3c3cfdf5c58b7193b81c31c181 Mon Sep 17 00:00:00 2001 From: Raushan Singh <19raushaniiitu@gmail.com> Date: Tue, 3 Feb 2026 20:30:14 +0530 Subject: [PATCH 5/7] Address comment from @CodeForContribute: tests/test_code_review_feature.py --- tests/test_code_review_feature.py | 52 +++++++++++++------------------ 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/tests/test_code_review_feature.py b/tests/test_code_review_feature.py index eb86aa7..bfde5cd 100644 --- a/tests/test_code_review_feature.py +++ b/tests/test_code_review_feature.py @@ -1,39 +1,29 @@ + import unittest -from code_review_module import CodeReviewFeature +from code_review import FeatureUnderTest class TestCodeReviewFeature(unittest.TestCase): def setUp(self): - self.feature = CodeReviewFeature() - - def test_feature_initialization(self): - """Test that the feature initializes correctly""" - self.assertIsNotNone(self.feature) - - def test_add_review_comment(self): - """Test adding a review comment""" - comment = "This is a test comment." - self.feature.add_comment(comment) - self.assertIn(comment, self.feature.comments) - - def test_remove_review_comment(self): - """Test removing a review comment""" - comment = "This is a test comment." - self.feature.add_comment(comment) - self.feature.remove_comment(comment) - self.assertNotIn(comment, self.feature.comments) - - def test_add_duplicate_comment(self): - """Test adding a duplicate comment raises ValueError""" - comment = "This is a duplicate comment." - self.feature.add_comment(comment) - with self.assertRaises(ValueError): - self.feature.add_comment(comment) - - def test_remove_nonexistent_comment(self): - """Test removing a non-existent comment raises ValueError""" + self.feature = FeatureUnderTest() + + def test_feature_case_1(self): + """Test normal case.""" + input_data = "some input" + expected_output = "expected output" + self.assertEqual(self.feature.method_to_test(input_data), expected_output) + + def test_feature_edge_case(self): + """Test an edge case to improve coverage.""" + input_data = "edge case input" + expected_output = "edge case output" + self.assertEqual(self.feature.method_to_test(input_data), expected_output) + + def test_feature_invalid_input(self): + """Test invalid input handling.""" + input_data = None with self.assertRaises(ValueError): - self.feature.remove_comment("Non-existent comment") + self.feature.method_to_test(input_data) -if __name__ == "__main__": +if __name__ == '__main__': unittest.main() From b46c6ae7119045ecb0680014c9921b49cf3db54d Mon Sep 17 00:00:00 2001 From: Raushan Singh <19raushaniiitu@gmail.com> Date: Tue, 3 Feb 2026 20:49:48 +0530 Subject: [PATCH 6/7] Address comment from @CodeForContribute: tests/test_code_review_feature.py --- tests/test_code_review_feature.py | 74 ++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 22 deletions(-) diff --git a/tests/test_code_review_feature.py b/tests/test_code_review_feature.py index bfde5cd..f0d0c19 100644 --- a/tests/test_code_review_feature.py +++ b/tests/test_code_review_feature.py @@ -1,29 +1,59 @@ import unittest -from code_review import FeatureUnderTest +from code_review import CodeReview class TestCodeReviewFeature(unittest.TestCase): - def setUp(self): - self.feature = FeatureUnderTest() - - def test_feature_case_1(self): - """Test normal case.""" - input_data = "some input" - expected_output = "expected output" - self.assertEqual(self.feature.method_to_test(input_data), expected_output) - - def test_feature_edge_case(self): - """Test an edge case to improve coverage.""" - input_data = "edge case input" - expected_output = "edge case output" - self.assertEqual(self.feature.method_to_test(input_data), expected_output) - - def test_feature_invalid_input(self): - """Test invalid input handling.""" - input_data = None - with self.assertRaises(ValueError): - self.feature.method_to_test(input_data) + self.review = CodeReview() + + def test_add_comment(self): + result = self.review.add_comment('Great job!') + self.assertTrue(result) + + def test_add_duplicate_comment(self): + self.review.add_comment('Great work!') + result = self.review.add_comment('Great work!') + self.assertFalse(result) + + def test_remove_comment(self): + self.review.add_comment('Needs improvement.') + result = self.review.remove_comment('Needs improvement.') + self.assertTrue(result) + + def test_remove_non_existent_comment(self): + result = self.review.remove_comment('This is wrong!') + self.assertFalse(result) + + def test_get_all_comments(self): + self.review.add_comment('Well done!') + comments = self.review.get_all_comments() + self.assertIn('Well done!', comments) + + def test_get_comments_count(self): + self.review.add_comment('Consider refactoring.') + self.review.add_comment('Looks good.') + count = self.review.get_comments_count() + self.assertEqual(count, 2) + + def test_clear_comments(self): + self.review.add_comment('Clean code!') + self.review.clear_comments() + comments = self.review.get_all_comments() + self.assertEqual(len(comments), 0) + + def test_update_comment(self): + self.review.add_comment('Typo here.') + result = self.review.update_comment('Typo here.', 'Spelling mistake.') + self.assertTrue(result) + + def test_update_non_existent_comment(self): + result = self.review.update_comment('Invalid comment', 'New suggestion') + self.assertFalse(result) + + def test_contains_comment(self): + self.review.add_comment('Review this part.') + contains = self.review.contains_comment('Review this part.') + self.assertTrue(contains) if __name__ == '__main__': - unittest.main() + unittest.main() \ No newline at end of file From 4acab771564824729d4ce64a4e5242eeaa944747 Mon Sep 17 00:00:00 2001 From: Raushan Singh <19raushaniiitu@gmail.com> Date: Wed, 11 Feb 2026 22:02:40 +0530 Subject: [PATCH 7/7] Add src/__tests__/codeReviewFeature.test.ts --- src/__tests__/codeReviewFeature.test.ts | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/__tests__/codeReviewFeature.test.ts diff --git a/src/__tests__/codeReviewFeature.test.ts b/src/__tests__/codeReviewFeature.test.ts new file mode 100644 index 0000000..a1f2379 --- /dev/null +++ b/src/__tests__/codeReviewFeature.test.ts @@ -0,0 +1,45 @@ +import { describe, it, expect } from '@jest/globals'; + +// Mock function or service to simulate code review changes +type MockReviewService = { + addComment: (comment: string) => void; + removeComment: (commentId: string) => void; + listComments: () => string[]; +}; + +// Simulating a basic mock for code review service +const mockReviewService: MockReviewService = { + comments: [], + addComment(comment) { + this.comments.push(comment); + }, + removeComment(commentId) { + this.comments = this.comments.filter(c => c !== commentId); + }, + listComments() { + return this.comments; + } +}; + +// Unit test for code review feature +describe('Code Review Feature', () => { + it('should add a comment', () => { + mockReviewService.addComment('This is a new comment'); + const comments = mockReviewService.listComments(); + expect(comments).toContain('This is a new comment'); + }); + + it('should remove a comment', () => { + mockReviewService.addComment('Comment to be removed'); + mockReviewService.removeComment('Comment to be removed'); + const comments = mockReviewService.listComments(); + expect(comments).not.toContain('Comment to be removed'); + }); + + it('should list comments correctly', () => { + mockReviewService.addComment('First comment'); + mockReviewService.addComment('Second comment'); + const comments = mockReviewService.listComments(); + expect(comments).toEqual(['First comment', 'Second comment']); + }); +});