Skip to content

feat: implement dynamic API URL configuration with Firebase Remote Config#2

Merged
Sloy merged 4 commits into
masterfrom
dynamic-url
Jun 22, 2025
Merged

feat: implement dynamic API URL configuration with Firebase Remote Config#2
Sloy merged 4 commits into
masterfrom
dynamic-url

Conversation

@Sloy

@Sloy Sloy commented Jun 22, 2025

Copy link
Copy Markdown
Owner

Summary

  • Add Firebase Remote Config integration for dynamic API URL management
  • Implement DynamicApiUrlInterceptor for runtime URL replacement
  • Add comprehensive unit tests with Mockito for interceptor functionality
  • Upgrade to mockito-kotlin 5.4.0 and remove unnecessary mockito-core dependency

Technical Changes

  • ApiConfigurationManager: Manages current API URL with default build-variant-specific URLs
  • DynamicApiUrlInterceptor: OkHttp interceptor that replaces placeholder base URLs with configured URLs
  • RemoteConfigService: Firebase Remote Config integration with real-time updates and error handling
  • Comprehensive unit tests: 12 test scenarios covering URL transformation, query parameters, headers preservation, and edge cases

Test Coverage

  • URL replacement with different substitute URLs (AWS API Gateway, custom domains, ports)
  • Query parameter and header preservation
  • Edge cases (trailing slashes, multiple path segments, non-matching URLs)
  • Proper mocking with Mockito to test input/output behavior

🤖 Generated with Claude Code

@Sloy
Sloy requested a review from Copilot June 22, 2025 15:29

This comment was marked as outdated.

@Sloy
Sloy requested a review from Copilot June 22, 2025 16:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Implements dynamic API URL configuration using Firebase Remote Config and an OkHttp interceptor, updates dependency versions, and augments the DI setup and tests.

  • Integrate Firebase Remote Config to fetch and apply API URL at runtime
  • Introduce DynamicApiUrlInterceptor and corresponding comprehensive unit tests
  • Update DI modules and application class to wire in new services; bump Java/Kotlin target to 17 and add Firebase Config & Mockito-Kotlin

Reviewed Changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
gradle/libs.versions.toml Added mockito, mockito-kotlin, and firebase-config entries
DynamicApiUrlInterceptorTest.kt New tests covering URL replacement, query/fragment preservation
FakeSevibusApi.kt Added getCardInfo and getCardTransactions methods to fake API
RemoteConfigService.kt New service for Firebase Remote Config setup, listener, fetch
DynamicApiUrlInterceptor.kt OkHttp interceptor to swap placeholder base URL at runtime
ApiConfigurationManager.kt Manages current API URL with defaults and trailing‐slash logic
DI.kt Registered config manager, interceptor, remote config service; replaced hardcoded URLs
SevApplication.kt Initialized RemoteConfigService in onCreate
app/build.gradle.kts Updated Java/Kotlin compatibility to 17; added dependencies
Comments suppressed due to low confidence (2)

app/src/main/java/com/sloy/sevibus/infrastructure/config/RemoteConfigService.kt:22

  • Core logic in initialize() (setupConfigUpdateListener, fetchAndActivate) isn't covered by unit tests. Consider adding tests to simulate success and failure paths for fetch and update flows.
    fun initialize() {

app/src/test/java/com/sloy/sevibus/data/api/FakeSevibusApi.kt:110

  • Missing imports for kotlinx.coroutines.Dispatchers and kotlinx.coroutines.withContext, causing a compilation error.
    override suspend fun getCardInfo(card: CardId): CardInfoDto = withContext(Dispatchers.IO) {

fun setup() {
apiConfigurationManager = ApiConfigurationManager()
interceptor = DynamicApiUrlInterceptor(apiConfigurationManager)
mockChain = mock()

Copilot AI Jun 22, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] You're mixing Mockito.mock() with Mockito-Kotlin extensions—consider using mock<Interceptor.Chain>() from org.mockito.kotlin.mock for consistency and clearer Kotlin integration.

Suggested change
mockChain = mock()
mockChain = mock<Interceptor.Chain>()

Copilot uses AI. Check for mistakes.
- Replace string replacement with HttpUrl.Builder for robust URL construction
- Extract BASE_URL_PLACEHOLDER constant to interceptor companion object
- Update DI.kt and tests to use the shared constant
- Properly handle paths in currentApiUrl (e.g., /dev/, /prod/)
- Preserve query parameters and URL fragments correctly
- All tests passing with improved URL handling

Addresses PR review feedback about brittle string replacement and code duplication.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@Sloy
Sloy merged commit 6b52f2c into master Jun 22, 2025
1 check passed
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.

2 participants