test: add unit tests for 7 missing controllers#5
Open
GaneshPatil7517 wants to merge 1 commit intosugarlabs:mainfrom
Open
test: add unit tests for 7 missing controllers#5GaneshPatil7517 wants to merge 1 commit intosugarlabs:mainfrom
GaneshPatil7517 wants to merge 1 commit intosugarlabs:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds comprehensive unit tests for 7 previously untested controllers, increasing controller test coverage from 36% (4/11) to 100% (11/11). Additionally, it fixes a critical bug in the verifyOwner middleware by adding missing return statements after error responses.
Changes:
- Added unit tests for createBranch, forkProject, forkWithHistory, getProjectDataWithCommit, getProjects, getPullRequest, and pullRequest controllers
- Fixed middleware bug by adding return statements after error responses in verifyOwner.ts to prevent continued execution
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/controllers/createBranch.test.ts | Adds 9 tests covering branch creation, validation (missing repoName/branchName), default/custom branchedFrom parameter, and error handling |
| tests/controllers/forkProject.test.ts | Adds 7 tests for fork functionality, including validation of missing repositoryName and error handling |
| tests/controllers/forkWithHistory.test.ts | Adds 8 tests for history-preserving forks, including validation of empty/missing sourceRepo and error handling |
| tests/controllers/getProjectDataWithCommit.test.ts | Adds 8 tests covering query parameter validation, type checking (array vs string), and service error handling |
| tests/controllers/getProjects.test.ts | Adds 5 tests for pagination, empty lists, and missing page parameter validation |
| tests/controllers/getPullRequest.test.ts | Adds 8 tests for PR retrieval, including validation of invalid/null repo values and error handling |
| tests/controllers/pullRequest.test.ts | Adds 8 tests for PR creation, including validation of missing fields and non-fork error scenarios |
| src/middleware/verifyOwner.ts | Critical bug fix adding return statements after error responses (lines 10, 25, 32) to prevent execution from continuing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add test files for all untested controllers to increase coverage from 36% (4/11) to 100% (11/11): - createBranch.test.ts: validation, success, error cases - forkProject.test.ts: fork flow, missing fields, service errors - forkWithHistory.test.ts: history fork, validation, error handling - getProjectDataWithCommit.test.ts: query params, type checks, errors - getProjects.test.ts: pagination, missing page param, error handling - getPullRequest.test.ts: PR retrieval, invalid repo, service errors - pullRequest.test.ts: PR creation, missing fields, error handling Controller coverage: 99.34% statements, 96.96% branches Closes sugarlabs#3
c967ab2 to
c9ac10d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds unit tests for all 7 untested controllers, bringing controller test coverage from 36% (4/11) to 100% (11/11).
Problem
Only createProject, editProject, getProjectData, and getCommits had tests. The remaining 7 controllers were completely untested, leaving critical functionality vulnerable to regressions.
Solution
Added test files following existing patterns in createProject.test.ts:
Each test covers success, validation (400), and error (500) scenarios with mocked services.
Testing
200 tests passing
Controller coverage: 99.34% statements, 96.96% branches, 100% functions
No lint errors
Closes #3