Skip to content

Add comprehensive test coverage for WealthsimpleTransaction#266

Merged
Nef10 merged 5 commits intomainfrom
copilot/fix-261-2
Sep 3, 2025
Merged

Add comprehensive test coverage for WealthsimpleTransaction#266
Nef10 merged 5 commits intomainfrom
copilot/fix-261-2

Conversation

Copy link
Contributor

Copilot AI commented Sep 2, 2025

This PR adds comprehensive test coverage for the WealthsimpleTransaction struct, following the established patterns from TokenTests and WealthsimpleAccountTests. The implementation includes 34 test cases that thoroughly exercise all code paths in the transaction JSON parsing logic.

Key Features

Complete JSON Parsing Coverage:

  • Tests all required field validations (15+ missing field scenarios)
  • Validates nested dictionary parsing for market_price, market_value, and net_cash
  • Covers date parsing validation for both processDate and effectiveDate
  • Tests transaction type validation with camelCase string conversion
  • Validates object type requirement ("transaction")

Comprehensive Error Handling:

  • Network failure scenarios
  • Invalid JSON responses
  • Missing and malformed data validation
  • HTTP error codes and response type validation

Transaction Type Support:

  • Tests multiple transaction types including buy, sell, dividend, custodianFee
  • Validates camelCase conversion for complex enum cases like paymentTransferIn
  • Covers edge cases in transaction type mapping

Infrastructure Improvements:

  • Extended MockURLProtocol to support transaction request mocking
  • Added TransactionError.Equatable conformance for robust test assertions
  • Proper SwiftLint compliance with appropriate disable comments for file/class length

Example Test Coverage

func testGetTransactionsSuccess() throws {
    // Tests complete property mapping from JSON
    let transaction = transactions[0]
    XCTAssertEqual(transaction.id, "transaction-123")
    XCTAssertEqual(transaction.transactionType, .buy)
    XCTAssertEqual(transaction.marketPriceAmount, "150.00")
    // ... validates all 15 properties
}

func testTransactionMissingMarketPrice() throws {
    // Tests error handling for missing nested dictionaries
    var transaction = createValidTransactionJSON()
    transaction.removeValue(forKey: "market_price")
    // Validates TransactionError.missingResultParamenter is thrown
}

The test suite ensures robust error handling for malformed API responses and validates that all transaction properties are correctly parsed from the Wealthsimple API JSON format.

Fixes #261.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Loading
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 WealthsimpleTransaction struct

2 participants