-
Notifications
You must be signed in to change notification settings - Fork 0
feat(android): add getRegion/getJurisdiction with config caching #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ethanpschoen
merged 3 commits into
justin/feat/cross-activity-lifecycle
from
ethan/feat/headless-region-jurisdiction
Jul 15, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
ceda824
feat(android): add getRegion/getJurisdiction with config caching
ethanpschoen dcadd53
fix(android): treat blank env/jurisdiction/language/hash as absent
ethanpschoen ed1586b
refactor(android): drop Ketch.getLocation(), keep getRegion/getJurisd…
ethanpschoen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
ketchsdk/src/test/java/com/ketch/android/api/HeadlessFullConfigurationPathTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package com.ketch.android.api | ||
|
|
||
| import com.ketch.android.data.FullConfigurationRequest | ||
| import kotlinx.coroutines.runBlocking | ||
| import okhttp3.OkHttpClient | ||
| import okhttp3.mockwebserver.MockResponse | ||
| import okhttp3.mockwebserver.MockWebServer | ||
| import org.junit.After | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
| import java.net.HttpURLConnection | ||
|
|
||
| /** | ||
| * Regression coverage for the actual URL getFullConfiguration() requests: a blank | ||
| * environmentCode/jurisdictionCode/languageCode/hash must be treated the same as a null one | ||
| * (matching ketch-tag), since Ketch's config cache key relies on this to never disagree with | ||
| * the real request the HTTP client makes. | ||
| */ | ||
| class HeadlessFullConfigurationPathTest { | ||
| private lateinit var mockWebServer: MockWebServer | ||
|
|
||
| @Before | ||
| fun setUp() { | ||
| mockWebServer = MockWebServer() | ||
| mockWebServer.start() | ||
| mockWebServer.enqueue( | ||
| MockResponse() | ||
| .setResponseCode(HttpURLConnection.HTTP_OK) | ||
| .setBody("{}") | ||
| .addHeader("Content-Type", "application/json"), | ||
| ) | ||
| } | ||
|
|
||
| @After | ||
| fun tearDown() { | ||
| mockWebServer.shutdown() | ||
| } | ||
|
|
||
| @Test | ||
| fun allFieldsPresent_includesEnvJurisdictionLanguage() = runBlocking { | ||
| client().getFullConfiguration( | ||
| FullConfigurationRequest( | ||
| organizationCode = "org", | ||
| propertyCode = "prop", | ||
| environmentCode = "production", | ||
| jurisdictionCode = "us-ca", | ||
| languageCode = "en-US", | ||
| ), | ||
| ) | ||
| assertEquals("/web/v3/config/org/prop/production/us-ca/en-US/config.json", mockWebServer.takeRequest().path) | ||
| } | ||
|
|
||
| @Test | ||
| fun nullEnvironment_omitsSegmentEntirely() = runBlocking { | ||
| client().getFullConfiguration( | ||
| FullConfigurationRequest( | ||
| organizationCode = "org", | ||
| propertyCode = "prop", | ||
| environmentCode = null, | ||
| jurisdictionCode = "us-ca", | ||
| languageCode = "en-US", | ||
| ), | ||
| ) | ||
| assertEquals("/web/v3/config/org/prop/config.json", mockWebServer.takeRequest().path) | ||
| } | ||
|
|
||
| @Test | ||
| fun blankEnvironment_treatedSameAsNull_omitsSegmentEntirely() = runBlocking { | ||
| client().getFullConfiguration( | ||
| FullConfigurationRequest( | ||
| organizationCode = "org", | ||
| propertyCode = "prop", | ||
| environmentCode = "", | ||
| jurisdictionCode = "us-ca", | ||
| languageCode = "en-US", | ||
| ), | ||
| ) | ||
| assertEquals("/web/v3/config/org/prop/config.json", mockWebServer.takeRequest().path) | ||
| } | ||
|
|
||
| @Test | ||
| fun blankHash_omitsHashQueryParam() = runBlocking { | ||
| client().getFullConfiguration( | ||
| FullConfigurationRequest(organizationCode = "org", propertyCode = "prop", hash = ""), | ||
| ) | ||
| assertEquals("/web/v3/config/org/prop/config.json", mockWebServer.takeRequest().path) | ||
| } | ||
|
|
||
| @Test | ||
| fun nonBlankHash_includesHashQueryParam() = runBlocking { | ||
| client().getFullConfiguration( | ||
| FullConfigurationRequest(organizationCode = "org", propertyCode = "prop", hash = "abc123"), | ||
| ) | ||
| assertEquals("/web/v3/config/org/prop/config.json?hash=abc123", mockWebServer.takeRequest().path) | ||
| } | ||
|
|
||
| private fun client(): HeadlessApiClient { | ||
| val okHttpClient = OkHttpClient.Builder() | ||
| .addInterceptor { chain -> | ||
| val original = chain.request() | ||
| val redirected = original.newBuilder() | ||
| .url( | ||
| original.url.newBuilder() | ||
| .scheme("http") | ||
| .host(mockWebServer.hostName) | ||
| .port(mockWebServer.port) | ||
| .build(), | ||
| ) | ||
| .build() | ||
| chain.proceed(redirected) | ||
| } | ||
| .build() | ||
| return HeadlessApiClient(dataCenter = KetchDataCenter.US, okHttpClient = okHttpClient) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.