Skip to content

Add comprehensive test coverage for WealthsimpleAccount#258

Merged
Nef10 merged 6 commits intomainfrom
copilot/fix-257
Sep 2, 2025
Merged

Add comprehensive test coverage for WealthsimpleAccount#258
Nef10 merged 6 commits intomainfrom
copilot/fix-257

Conversation

Copy link
Contributor

Copilot AI commented Sep 2, 2025

This PR adds comprehensive test coverage for the WealthsimpleAccount struct, following the established pattern from TokenTests. The implementation includes 18 new test cases that thoroughly exercise all public methods and error handling paths.

What's Added

New Test File: WealthsimpleAccountTests.swift

  • 18 comprehensive test cases covering all aspects of WealthsimpleAccount.getAccounts()
  • Helper methods to reduce code duplication and improve maintainability
  • Extended MockURLProtocol to support the /accounts endpoint

Test Coverage

Successful Scenarios (2 tests)

  • Valid JSON responses with proper account data validation
  • Multiple account types: ca_tfsa, ca_rrsp, ca_cash_msb, ca_cash, ca_non_registered

Network & HTTP Error Handling (4 tests)

  • Network connection failures (URLError.networkConnectionLost)
  • HTTP error status codes (401, 500, etc.)
  • Invalid response types (non-HTTPURLResponse)
  • Empty data responses

JSON Parsing Error Coverage (5 tests)

  • Invalid JSON syntax
  • Wrong JSON structure (arrays instead of objects)
  • Missing required top-level fields (results, object)
  • Invalid field values (wrong object type)

Individual Account Validation (6 tests)

  • Missing required account fields (id, type, base_currency, custodian_account_number)
  • Invalid account type values
  • Invalid account object values

Edge Cases (1 test)

  • Empty results array handling

Technical Implementation

The tests follow the same patterns established in TokenTests:

  • Uses MockURLProtocol for network request interception
  • Creates valid tokens through MockCredentialStorage
  • Uses XCTestExpectation for async testing
  • Validates all AccountError enum cases
  • Tests property access and data mapping

Error Coverage

All AccountError cases are tested:

  • noDataReceived
  • httpError(error: String)
  • invalidJson(error: String)
  • invalidJsonType(json: Any)
  • missingResultParamenter(json: [String: Any])
  • invalidResultParamenter(json: [String: Any])
  • tokenError(_ error: TokenError)

Test Results

  • ✅ All 18 new tests pass
  • ✅ All existing tests continue to pass (42 total tests)
  • ✅ Code builds successfully with strict warnings
  • ✅ Follows Swift coding conventions and project style

The implementation provides thorough validation of the WealthsimpleAccount struct's behavior under both normal and error conditions, ensuring robust error handling and proper data parsing.

Fixes #257.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: Nef10 <4551135+Nef10@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Test coverage for WealthsimpleAccount struct Add comprehensive test coverage for WealthsimpleAccount struct Sep 2, 2025
Copilot AI requested a review from Nef10 September 2, 2025 05:19
@Nef10 Nef10 marked this pull request as ready for review September 2, 2025 07:05
@github-actions
Copy link

github-actions bot commented Sep 2, 2025

Minimum coverage required: 30%


Coverage after merging copilot/fix-257 into main

41.95%

Coverage Report
FileStmtsFuncsLinesUncovered Lines
Sources/Wealthsimple
   Token.swift97.29%95.24%97.50%117–118, 137–138
   TransactionError.swift0%0%0%29–46
   URLConfiguration.swift100%100%100%
   WealthsimpleAccount.swift89.01%63.64%92.50%114–115
   WealthsimpleAsset.swift0%0%0%52–68
   WealthsimpleDownloader.swift0%0%0%102–115, 122–135, 137–149, 48–51, 55–78, 82–95
   WealthsimplePosition.swift0%0%0%100–112, 114–137, 139–158, 51, 53–57, 66–92, 94–99
   WealthsimpleTransaction.swift0%0%0%127, 129–133, 152–196, 198–218, 220–243, 245–264
Sources/Wealthsimple/Extensions
   String+CamelCase.swift100%100%100%

@Nef10 Nef10 merged commit 5055214 into main Sep 2, 2025
5 of 8 checks passed
@Nef10 Nef10 deleted the copilot/fix-257 branch September 2, 2025 07:19
@Nef10 Nef10 added the tests Improvements to automated tests label Sep 2, 2025
@Nef10 Nef10 changed the title Add comprehensive test coverage for WealthsimpleAccount struct Add comprehensive test coverage for WealthsimpleAccount 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 WealthsimpleAccount struct

2 participants