Skip to content

Commit

Permalink
fix: cio sdk version attribute using client value
Browse files Browse the repository at this point in the history
  • Loading branch information
mrehan27 committed Nov 15, 2022
1 parent 145c047 commit bb90f35
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
Expand Up @@ -34,7 +34,7 @@ class DeviceStoreStub {
override val isPushEnabled: Boolean
get() = true
},
version = cioConfig.client.sdkVersion
version = "1.0.0-alpha.6"
)
}
}
10 changes: 10 additions & 0 deletions sdk/src/main/java/io/customer/sdk/data/store/Client.kt
Expand Up @@ -31,6 +31,11 @@ sealed class Client(
*/
class Expo(sdkVersion: String) : Client(source = SOURCE_EXPO, sdkVersion = sdkVersion)

/**
* Simpler class for Flutter clients.
*/
class Flutter(sdkVersion: String) : Client(source = SOURCE_FLUTTER, sdkVersion = sdkVersion)

/**
* Other class to allow adding custom sources for clients that are not
* supported above.
Expand All @@ -46,6 +51,7 @@ sealed class Client(
internal const val SOURCE_ANDROID = "Android"
internal const val SOURCE_REACT_NATIVE = "ReactNative"
internal const val SOURCE_EXPO = "Expo"
internal const val SOURCE_FLUTTER = "Flutter"

/**
* Helper method to create client from raw values
Expand All @@ -67,6 +73,10 @@ sealed class Client(
other = SOURCE_EXPO,
ignoreCase = true
) -> Expo(sdkVersion = sdkVersion)
source.equals(
other = SOURCE_FLUTTER,
ignoreCase = true
) -> Flutter(sdkVersion = sdkVersion)
else -> Other(source = source, sdkVersion = sdkVersion)
}
}
Expand Down
3 changes: 1 addition & 2 deletions sdk/src/main/java/io/customer/sdk/di/CustomerIOComponent.kt
Expand Up @@ -4,7 +4,6 @@ import android.content.Context
import com.squareup.moshi.Moshi
import io.customer.sdk.CustomerIOActivityLifecycleCallbacks
import io.customer.sdk.CustomerIOConfig
import io.customer.sdk.Version
import io.customer.sdk.api.*
import io.customer.sdk.api.interceptors.HeadersInterceptor
import io.customer.sdk.data.moshi.adapter.BigDecimalAdapter
Expand Down Expand Up @@ -157,7 +156,7 @@ class CustomerIOComponent(
sdkConfig = sdkConfig,
buildStore = BuildStoreImp(),
applicationStore = ApplicationStoreImp(context),
version = Version.version
version = sdkConfig.client.sdkVersion
)
}
}
Expand Down
20 changes: 20 additions & 0 deletions sdk/src/sharedTest/java/io/customer/sdk/data/store/ClientTest.kt
Expand Up @@ -29,6 +29,13 @@ class ClientTest : BaseTest() {
reactNativeClient.toString().shouldBeEqualTo(expected = "ReactNative Client/7.3.2")
}

@Test
fun initialize_givenFlutter_expectFlutterClient() {
val flutterClient = Client.Flutter(sdkVersion = "3.5.8")

flutterClient.toString().shouldBeEqualTo(expected = "Flutter Client/3.5.8")
}

@Test
fun initialize_givenOther_expectOtherClient() {
val iOSClient = Client.fromRawValue(source = "iOS", sdkVersion = "4.6.7")
Expand Down Expand Up @@ -75,6 +82,19 @@ class ClientTest : BaseTest() {
mixedCaseClient.toString().shouldBeEqualTo(expected = "Expo Client/4.5.6")
}

@Test
fun initialize_givenRawValueFlutter_expectFlutterClient() {
val lowerCaseClient = Client.fromRawValue(source = "flutter", sdkVersion = "1.2.3")
val upperCaseClient = Client.fromRawValue(source = "FLUTTER", sdkVersion = "2.3.4")
val titleCaseClient = Client.fromRawValue(source = "Flutter", sdkVersion = "3.4.5")
val mixedCaseClient = Client.fromRawValue(source = "FlutTer", sdkVersion = "4.5.6")

lowerCaseClient.toString().shouldBeEqualTo(expected = "Flutter Client/1.2.3")
upperCaseClient.toString().shouldBeEqualTo(expected = "Flutter Client/2.3.4")
titleCaseClient.toString().shouldBeEqualTo(expected = "Flutter Client/3.4.5")
mixedCaseClient.toString().shouldBeEqualTo(expected = "Flutter Client/4.5.6")
}

@Test
fun initialize_givenRawValueOther_expectOtherClient() {
val lowerCaseClient = Client.fromRawValue(source = "ios", sdkVersion = "1.2.3")
Expand Down

0 comments on commit bb90f35

Please sign in to comment.