Skip to content

Add comprehensive test coverage for WealthsimpleDownloader#263

Merged
Nef10 merged 10 commits intomainfrom
copilot/fix-262
Sep 8, 2025
Merged

Add comprehensive test coverage for WealthsimpleDownloader#263
Nef10 merged 10 commits intomainfrom
copilot/fix-262

Conversation

Copy link
Contributor

Copilot AI commented Sep 2, 2025

This PR adds comprehensive test coverage for the WealthsimpleDownloader class, following the established testing patterns used for Token and WealthsimpleAccount classes.

What's Added

New Test File: Tests/WealthsimpleTests/WealthsimpleDownloaderTests.swift with 16 comprehensive test cases covering all public methods and major code paths:

Test Coverage

  • Constructor (1 test): Validates proper instantiation
  • Authentication (5 tests):
    • Token refresh scenarios (success/failure)
    • Credential storage handling (valid/empty)
    • New token authentication flows
  • getAccounts (4 tests): No token, success, HTTP errors, network errors
  • getPositions (3 tests): No token, success, network errors
  • getTransactions (3 tests): No token, success, network errors

Infrastructure Enhancements

  • Extended MockURLProtocol to support /positions and /transactions endpoints
  • Added MockAccount helper struct implementing the Account protocol
  • Proper JSON response mocking matching actual API formats

Implementation Details

The tests follow the existing patterns from TokenTests and WealthsimpleAccountTests:

  • Use MockCredentialStorage for credential mocking
  • Use MockURLProtocol for network request interception
  • Use XCTestExpectation for async operation testing
  • All network calls are mocked - no external dependencies

Example test structure:

func testGetAccountsWithTokenSuccess() throws {
    // Setup mock responses
    MockURLProtocol.accountsRequestHandler = { url, request in
        // Validate headers and return mock data
    }
    
    // Test the actual functionality
    downloader.getAccounts { result in
        // Verify expected behavior
    }
}

Quality Assurance

  • ✅ All 56 tests pass (40 existing + 16 new)
  • ✅ Builds without warnings using -Xswiftc -warnings-as-errors
  • ✅ SwiftLint compliant with appropriate disable comments for file/function length only
  • ✅ No external network calls in tests
  • ✅ Comprehensive error scenario coverage

The tests ensure robust coverage of all error conditions, success paths, and edge cases while maintaining the existing code quality standards.

Fixes #262.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits September 2, 2025 07:47
Co-authored-by: Nef10 <4551135+Nef10@users.noreply.github.com>
… SwiftLint compliance

Co-authored-by: Nef10 <4551135+Nef10@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Test coverage for WealthsimpleDownloader class Add comprehensive test coverage for WealthsimpleDownloader class Sep 2, 2025
Copilot AI requested a review from Nef10 September 2, 2025 07:52
* main:
  Add test coverage for WealthsimpleTransaction and TransactionError
  Add test coverage for WealthsimplePosition struct (#265)

# Conflicts:
#	Tests/WealthsimpleTests/Helpers/MockURLProtocol.swift
@github-actions
Copy link

github-actions bot commented Sep 3, 2025

Minimum coverage required: 96%


Coverage after merging copilot/fix-262 into main

96.28%

Coverage Report
FileStmtsFuncsLinesUncovered Lines
Sources/Wealthsimple
   Token.swift97.29%95.24%97.50%117–118, 137–138
   URLConfiguration.swift100%100%100%
   WealthsimpleAccount.swift89.01%63.64%92.50%114–115
   WealthsimpleAsset.swift81.82%33.33%89.47%
   WealthsimpleDownloader.swift99.22%100%99.14%60
   WealthsimplePosition.swift91.53%66.67%94.34%117–118
   WealthsimpleTransaction.swift93.55%69.23%95.77%241–242
Sources/Wealthsimple/Extensions
   String+CamelCase.swift100%100%100%

@Nef10 Nef10 marked this pull request as ready for review September 8, 2025 04:59
@Nef10 Nef10 enabled auto-merge (squash) September 8, 2025 05:05
@Nef10 Nef10 merged commit a543638 into main Sep 8, 2025
13 of 24 checks passed
@Nef10 Nef10 deleted the copilot/fix-262 branch September 8, 2025 05:14
@Nef10 Nef10 added the tests Improvements to automated tests label Nov 10, 2025
@Nef10 Nef10 changed the title Add comprehensive test coverage for WealthsimpleDownloader class Add comprehensive test coverage for WealthsimpleDownloader Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Improvements to automated tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Test coverage for WealthsimpleDownloader class

2 participants