Skip to content

test: add unit tests for 7 missing controllers#5

Open
GaneshPatil7517 wants to merge 1 commit intosugarlabs:mainfrom
GaneshPatil7517:test/increase-controller-coverage
Open

test: add unit tests for 7 missing controllers#5
GaneshPatil7517 wants to merge 1 commit intosugarlabs:mainfrom
GaneshPatil7517:test/increase-controller-coverage

Conversation

@GaneshPatil7517
Copy link
Contributor

@GaneshPatil7517 GaneshPatil7517 commented Feb 11, 2026

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:

  • createBranch.test.ts — 9 tests (validation, default/custom branchedFrom, falsy result, error logging)
  • forkProject.test.ts — 7 tests (fork flow, missing repositoryName, service errors)
  • forkWithHistory.test.ts — 8 tests (history fork, empty/missing sourceRepo, error handling)
  • getProjectDataWithCommit.test.ts — 8 tests (query param type validation, missing params, service errors)
  • getProjects.test.ts — 5 tests (pagination, empty list, missing page param)
  • getPullRequest.test.ts — 8 tests (PR retrieval, invalid/null repo, service errors)
  • pullRequest.test.ts — 8 tests (PR creation, missing fields, non-fork error)

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

Copilot AI review requested due to automatic review settings February 11, 2026 14:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@GaneshPatil7517 GaneshPatil7517 force-pushed the test/increase-controller-coverage branch from c967ab2 to c9ac10d Compare February 11, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TESTING] Increase test coverage - 7 controllers missing unit tests

1 participant