Skip to content

Conversation

@onevcat
Copy link
Member

@onevcat onevcat commented Jul 30, 2025

Summary

This PR improves the test coverage and simplified some test code.

  • Add comprehensive test coverage for exchangeToken error handling and retry mechanism
  • Add comprehensive window management tests
  • Refactor LoginManagerTests to eliminate code duplication

onevdog added 3 commits July 29, 2025 17:17
Extract common test setup and execution logic from three test methods
(testLoginAction, testLoginActionWithOpenID, testLoginActionWithNonIsolatedResumeOpenURL)
into reusable helper methods:

- setupSessionStub(): Centralized session stub configuration
- performLoginTest(): Parameterized login test execution with support for
  different permissions, OpenID expectations, and URL resume methods

This reduces code duplication from ~150 lines to ~25 lines while maintaining
all original test functionality and assertions.
Add 5 focused test methods for UIWindow.findKeyWindow() and UIViewController.topMost:
- testFindKeyWindowWithCreatedWindow: Tests key window detection
- testTopMostViewControllerWithSetup: Tests basic top-most controller finding
- testTopMostViewControllerWithPresentation: Tests single presentation layer
- testTopMostViewControllerWithNestedPresentation: Tests nested presentations
- testWindowWithoutRootViewController: Tests edge case handling

These tests eliminate non-deterministic conditional patterns and provide
comprehensive coverage with reduced code duplication (~130 to ~85 lines).
…retry mechanism

This commit adds three new test methods to LoginManagerTests.swift that significantly improve
test coverage for the exchangeToken method's error handling logic:

1. testExchangeTokenWithNonNetworkError: Tests that non-network errors directly call
   invokeFailure without retry attempts

2. testExchangeTokenWithNetworkErrorRetrySuccess: Tests that NSURLErrorNetworkConnectionLost
   errors trigger the retry mechanism and succeed on the second attempt with proper 0.3s delay

3. testExchangeTokenWithNetworkErrorRetryFail: Tests that network errors fail gracefully
   after retry attempts are exhausted

Key technical improvements:
- Proper SessionDelegateStub sequencing for retry scenarios
- Correct error wrapping behavior validation
- Network connection lost error type distinction
- Retry delay mechanism verification
- Comprehensive catch block coverage in exchangeToken method

These tests ensure robust error handling for token exchange operations and improve overall
SDK reliability in network-unstable environments.
@onevcat onevcat temporarily deployed to Coverage Badge Env July 30, 2025 02:10 — with GitHub Actions Inactive
@onevcat onevcat changed the title Improve LoginProcess test coverage with dependency injection Refactor and improve test coverage a bit Jul 30, 2025
@onevcat onevcat merged commit 5a87f2f into master Jul 30, 2025
32 of 34 checks passed
@onevcat onevcat deleted the fix/test-coverage branch July 30, 2025 05:16
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.

3 participants