commonTest.FunctionsTest.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of flare Show documentation
Show all versions of flare Show documentation
Light the way for your app's backend with functional and testable Firebase components
import enchant.flare.FirebaseFunctions
import enchant.flare.FunctionsException
import enchant.flare.LocalFunctions
import kotlin.test.Test
import kotlin.test.assertEquals
class FunctionsTest : FlareTest() {
@Test
fun callFunction() = runTest {
val functions: FirebaseFunctions = if (useLocal) MyLocalFunctions()
else FirebaseFunctions.instance
val response = functions.call("increment",1)
assertEquals(2, response, "Ensure function incremented value")
}
}
private class MyLocalFunctions : LocalFunctions() {
override suspend fun callFunction(name: String, data: Any?): Any? {
if (name == "increment") {
return (data as Int) + 1
} else {
throw FunctionsException(FunctionsException.Code.NotFound, "Function not found")
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy