actions-on-google / actions-on-google-java

Java/Kotlin library for Actions on Google
Apache License 2.0
287 stars 39 forks source link

UserStorage is not filled in the internal constructor of AogRequest #33

Open zonder129 opened 5 years ago

zonder129 commented 5 years ago

For example in MockRequestBuilder a build() method sets user field of appRequest and creates aogRequest out of it:

...
if (userStorage != null) {
    user.userStorage = gson.toJson(userStorage)
}
appRequest.user = user
...
val aogRequest = AogRequest(appRequest)
...

But inside internal constructor of AogRequest userStorage field is not set at all, only user.userStorage does:

internal class AogRequest internal constructor(
        override val appRequest: AppRequest) : ActionRequest {
    ...
    override var userStorage: MutableMap<String, Any> = HashMap()
    ...
    override val user: User? get() = appRequest.user
    ...
}

So, if we try in a test to set this userStorage, the field will be empty:

@Test
fun userStorageTest() {
    val actionRequest = MockRequestBuilder()
        .setUserStorage(mapOf(Pair("userId", "someId")))
        .build()
    println("userStorage = ${actionRequest.userStorage}")
    println("user.userStorage = ${actionRequest.user?.userStorage}")
}

the output will be:

userStorage = {}
user.userStorage = {"userId":"someId"}