Skip to content

test(oauth): add unit tests for storage backends and auth middleware#19

Merged
polaz merged 2 commits intomainfrom
test/#12-oauth-storage-coverage
Jan 19, 2026
Merged

test(oauth): add unit tests for storage backends and auth middleware#19
polaz merged 2 commits intomainfrom
test/#12-oauth-storage-coverage

Conversation

@polaz
Copy link
Copy Markdown
Member

@polaz polaz commented Jan 18, 2026

Summary

  • Add comprehensive unit tests to improve OAuth code coverage

Coverage Improvements

Component Before After
src/oauth/storage/memory.ts 30.26% 98.68%
src/oauth/storage/file.ts 4.22% 97.18%
src/middleware/oauth-auth.ts 10.71% 100%

Tests Added

  • 70 tests for MemoryStorageBackend (session CRUD, device flows, auth codes, cleanup, export/import)
  • 43 tests for FileStorageBackend (persistence, atomic writes, recovery scenarios)
  • 21 tests for OAuth auth middleware (token validation, refresh, error handling)
  • Total: 134 new tests (1178 -> 1312 tests passing)

Test plan

  • All 1312 tests pass
  • Lint passes
  • Build succeeds

Related to #12

Add comprehensive unit tests to improve OAuth code coverage:

- MemoryStorageBackend: 70 tests covering session CRUD, device flows,
  auth codes, cleanup, and export/import functionality (30% -> 99%)
- FileStorageBackend: 43 tests covering persistence, atomic writes,
  recovery scenarios, and file operations (4% -> 97%)
- OAuth auth middleware: 21 tests covering token validation, refresh,
  error handling, and optional auth mode (11% -> 100%)

Total: 134 new tests added (1178 -> 1312 tests passing)
Copilot AI review requested due to automatic review settings January 18, 2026 23:02
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

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 PR adds comprehensive unit tests to improve code coverage for OAuth functionality, specifically targeting storage backends and authentication middleware. The tests achieve near-complete coverage (97-100%) for the targeted components.

Changes:

  • Added 70 unit tests for MemoryStorageBackend covering CRUD operations, cleanup, and data export/import
  • Added 43 unit tests for FileStorageBackend covering persistence, atomic writes, and recovery scenarios
  • Added 21 unit tests for OAuth authentication middleware covering token validation, refresh, and error handling

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/unit/oauth/storage/memory.test.ts Comprehensive tests for in-memory storage backend including session management, device flows, auth codes, cleanup operations, and import/export functionality
tests/unit/oauth/storage/file.test.ts Tests for file-based storage backend including persistence verification, atomic writes, corruption handling, and various edge cases
tests/unit/middleware/oauth-auth.test.ts Tests for OAuth authentication middleware covering token validation, session management, GitLab token refresh, and both required and optional authentication flows

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@polaz polaz merged commit e679fb7 into main Jan 19, 2026
8 of 10 checks passed
@polaz polaz deleted the test/#12-oauth-storage-coverage branch January 19, 2026 07:43
polaz added a commit that referenced this pull request Jan 19, 2026
README FIXES:
- Clarify migration guide heading: "v5.0" → "v5.x → v6.0"
- Update summary heading: "Consolidated Tools in v5.0" → "CQRS Tools Introduced in v6.0"
- Fix Core/Projects count: "8 tools → CQRS" → "13 tools → 5 CQRS tools"

TEST IMPROVEMENTS (coverage 90.35% → 92.1%):
- Add test for create draft note with in_reply_to_discussion_id
- Add test for update MR with array parameters (assignee_ids, reviewer_ids)
- Statements: 92.1%, Branches: 86.84%, Functions: 100%, Lines: 99.01%

Note: Copilot review incorrectly flagged Files/Core CQRS tools as
non-existent, but they DO exist from previous PRs (#12, #19, #20).
sw-release-bot bot pushed a commit that referenced this pull request Jan 19, 2026
## [6.1.0](v6.0.0...v6.1.0) (2026-01-19)

### ⚠ BREAKING CHANGES

* **mrs:** Individual MR tools replaced with action-based CQRS tools

### Features

* **mrs:** consolidate 20 MR tools into 5 CQRS tools ([#15](#15)) ([ec06fae](ec06fae))

### Bug Fixes

* **mrs:** address PR [#23](#23) review comments and increase coverage ([0e6410b](0e6410b)), closes [#12](#12) [#19](#19) [#20](#20)
* **mrs:** address PR review comments from Copilot ([#23](#23)) ([1905ac4](1905ac4))
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.

2 participants