Skip to content

Make URL base configurable with singleton URLConfiguration class#251

Merged
Nef10 merged 3 commits intomainfrom
copilot/fix-250
Aug 31, 2025
Merged

Make URL base configurable with singleton URLConfiguration class#251
Nef10 merged 3 commits intomainfrom
copilot/fix-250

Conversation

Copy link
Contributor

Copilot AI commented Aug 31, 2025

This PR implements a configurable URL base system to enable easy redirection of all Wealthsimple API calls for testing purposes. Previously, all API endpoints used hardcoded URLs throughout the codebase, making it impossible to redirect calls to mock servers during unit testing.

Changes Made

New URLConfiguration Singleton Class

  • Created URLConfiguration singleton that manages the base URL for all API endpoints
  • Default base URL: https://api.production.wealthsimple.com/v1/
  • Internal access setBaseURL() method for testing configuration
  • Helper methods for creating URL, URLComponents, and string representations

Updated All API Classes

  • Token.swift: Replaced hardcoded URLs for /oauth/token and /oauth/token/info
  • WealthsimpleAccount.swift: Replaced hardcoded URL for /accounts
  • WealthsimplePosition.swift: Replaced hardcoded URL for /positions
  • WealthsimpleTransaction.swift: Replaced hardcoded URL for /transactions

Comprehensive Test Coverage

  • Added 9 comprehensive tests covering all URLConfiguration functionality
  • Tests verify singleton pattern, URL construction, and configuration persistence
  • All existing functionality remains unchanged (backward compatibility maintained)

Usage for Testing

// Redirect all API calls to mock server
URLConfiguration.shared.setBaseURL("https://mock.test.server/v1/")

// All subsequent API calls will use the mock server
// Token.getToken(), WealthsimpleAccount.getAccounts(), etc.

Benefits

  • Easy Mock Testing: Single line change redirects all API calls to test servers
  • Clean Architecture: Centralized URL management instead of scattered hardcoded URLs
  • Backward Compatible: No changes to existing public API
  • Type Safe: Proper Swift access control with internal-only configuration method

Fixes #250.


💡 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.

Co-authored-by: Nef10 <4551135+Nef10@users.noreply.github.com>
Copilot AI changed the title [WIP] Make URL base configurable Make URL base configurable with singleton URLConfiguration class Aug 31, 2025
Copilot AI requested a review from Nef10 August 31, 2025 17:20
@Nef10 Nef10 marked this pull request as ready for review August 31, 2025 17:28
@Nef10 Nef10 enabled auto-merge (squash) August 31, 2025 17:29
@github-actions
Copy link

github-actions bot commented Aug 31, 2025

Minimum coverage required: 0%


Coverage after merging copilot/fix-250 into main

4.30%

Coverage Report
FileStmtsFuncsLinesUncovered Lines
Sources/Wealthsimple
   Token.swift0%0%0%100–104, 111–124, 132–154, 156–167, 169–192, 194–198, 200–206, 208–210, 212–220, 222–226, 37–38, 47–52, 54–66, 68–79, 81–99
   TransactionError.swift0%0%0%29–46
   URLConfiguration.swift100%100%100%
   WealthsimpleAccount.swift0%0%0%100–114, 116–139, 141–160, 75, 82–97, 99
   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–117, 119–142, 144–163, 51, 53–57, 66–92, 94–99
   WealthsimpleTransaction.swift0%0%0%127, 129–133, 152–196, 198–223, 225–248, 250–269
Sources/Wealthsimple/Extensions
   String+CamelCase.swift100%100%100%

@Nef10 Nef10 merged commit b3d056d into main Aug 31, 2025
19 of 24 checks passed
@Nef10 Nef10 deleted the copilot/fix-250 branch August 31, 2025 19:52
@Nef10 Nef10 added refactoring Code refactoring tests Improvements to automated tests labels Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring Code refactoring tests Improvements to automated tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make URL base configurable

2 participants