Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1cb2d618d | ||
|
|
8c9a3b5b37 |
@@ -34,8 +34,8 @@ android {
|
||||
applicationId = "pl.firmatpp.kierowca"
|
||||
minSdk = 26
|
||||
targetSdk = 35
|
||||
versionCode = 118
|
||||
versionName = "1.0.65"
|
||||
versionCode = 119
|
||||
versionName = "1.0.66"
|
||||
setProperty("archivesBaseName", "pl.firmatpp.kierowca")
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
package pl.firmatpp.kierowca.data.api
|
||||
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import pl.firmatpp.kierowca.BuildConfig
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
|
||||
internal const val DRIVER_APP_VERSION_HEADER = "X-Driver-App-Version"
|
||||
|
||||
internal fun Request.withDriverAppVersion(appVersion: String): Request =
|
||||
newBuilder()
|
||||
.header(DRIVER_APP_VERSION_HEADER, appVersion)
|
||||
.build()
|
||||
|
||||
object ApiFactory {
|
||||
fun mobileDriverApi(): MobileDriverApi {
|
||||
val logging = HttpLoggingInterceptor().apply {
|
||||
@@ -13,6 +21,9 @@ object ApiFactory {
|
||||
}
|
||||
|
||||
val client = OkHttpClient.Builder()
|
||||
.addInterceptor { chain ->
|
||||
chain.proceed(chain.request().withDriverAppVersion(BuildConfig.VERSION_NAME))
|
||||
}
|
||||
.addInterceptor(logging)
|
||||
.build()
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package pl.firmatpp.kierowca.data.api
|
||||
|
||||
import okhttp3.Request
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class ApiFactoryTest {
|
||||
@Test
|
||||
fun `request contains current driver app version header`() {
|
||||
val request = Request.Builder()
|
||||
.url("https://api.example.test/mobile/driver/bootstrap")
|
||||
.header(DRIVER_APP_VERSION_HEADER, "old-version")
|
||||
.build()
|
||||
|
||||
val updated = request.withDriverAppVersion("1.0.65")
|
||||
|
||||
assertEquals("1.0.65", updated.header(DRIVER_APP_VERSION_HEADER))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user