Crashlytics Setup (#33)

* Setup crashlytics

* Fix possible crash when trying to retrieve external authentication
This commit is contained in:
Cedrick Flocon 2019-11-19 11:52:55 +01:00 committed by GitHub
parent 809501cc6f
commit 961ecaeb7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 4 deletions

View file

@ -4,6 +4,7 @@ apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.firebase.appdistribution'
apply plugin: 'com.github.triplet.play'
apply plugin: 'de.mannodermaus.android-junit5'
apply plugin: 'io.fabric'
buildscript {
repositories {
@ -87,6 +88,8 @@ dependencies {
exclude group: 'org.threeten'
}
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
testImplementation "org.spekframework.spek2:spek-dsl-jvm:$spek2Version"
testImplementation "org.spekframework.spek2:spek-runner-junit5:$spek2Version"
testImplementation "org.assertj:assertj-core:$assertJVersion"

View file

@ -1,6 +1,7 @@
package io.homeassistant.companion.android.webview
import android.net.Uri
import android.util.Log
import io.homeassistant.companion.android.domain.authentication.AuthenticationUseCase
import kotlinx.coroutines.*
import javax.inject.Inject
@ -33,7 +34,11 @@ class WebViewPresenterImpl @Inject constructor(
override fun onGetExternalAuth(callback: String) {
mainScope.launch {
view.setExternalAuth(callback, authenticationUseCase.retrieveExternalAuthentication())
try {
view.setExternalAuth(callback, authenticationUseCase.retrieveExternalAuthentication())
} catch (e: Exception) {
Log.e(TAG, "Unable to retrieve external auth", e)
}
}
}

View file

@ -4,7 +4,6 @@ import android.net.Uri
import io.homeassistant.companion.android.domain.authentication.AuthenticationUseCase
import io.mockk.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.newSingleThreadContext
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.spekframework.spek2.Spek
@ -43,7 +42,7 @@ object WebViewPresenterImplSpec : Spek({
}
}
describe("on get external auth") {
describe("on get external auth on success") {
beforeEachTest {
coEvery { authenticationUseCase.retrieveExternalAuthentication() } returns "{\"access_token\":\"ABCDEFGH\",\"expires_in\":1800}"
presenter.onGetExternalAuth("externalAuthSetToken")
@ -53,5 +52,18 @@ object WebViewPresenterImplSpec : Spek({
verify { view.setExternalAuth("externalAuthSetToken", "{\"access_token\":\"ABCDEFGH\",\"expires_in\":1800}") }
}
}
describe("on get external auth on error") {
beforeEachTest {
coEvery { authenticationUseCase.retrieveExternalAuthentication() } throws Exception()
presenter.onGetExternalAuth("externalAuthSetToken")
}
it("should not crash") {
coVerify {
view wasNot Called
}
}
}
}
})

View file

@ -5,12 +5,14 @@ buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.2'
classpath 'io.fabric.tools:gradle:1.31.2'
}
}
@ -18,7 +20,7 @@ allprojects {
repositories {
google()
jcenter()
}
}