Adds PushersMapperTest
This commit is contained in:
parent
f724751c86
commit
1f28a2acae
@ -38,6 +38,7 @@ internal class DefaultAddPusherTask @Inject constructor(
|
|||||||
private val requestExecutor: RequestExecutor,
|
private val requestExecutor: RequestExecutor,
|
||||||
private val globalErrorReceiver: GlobalErrorReceiver
|
private val globalErrorReceiver: GlobalErrorReceiver
|
||||||
) : AddPusherTask {
|
) : AddPusherTask {
|
||||||
|
|
||||||
override suspend fun execute(params: AddPusherTask.Params) {
|
override suspend fun execute(params: AddPusherTask.Params) {
|
||||||
val pusher = params.pusher
|
val pusher = params.pusher
|
||||||
try {
|
try {
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.matrix.android.sdk.internal.database.mapper
|
||||||
|
|
||||||
|
import org.amshove.kluent.shouldBeEqualTo
|
||||||
|
import org.junit.Test
|
||||||
|
import org.matrix.android.sdk.test.fixtures.JsonPusherFixture.aJsonPusher
|
||||||
|
import org.matrix.android.sdk.test.fixtures.PusherEntityFixture.aPusherEntity
|
||||||
|
|
||||||
|
class PushersMapperTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when mapping PusherEntity, then it is mapped into Pusher successfully`() {
|
||||||
|
val pusherEntity = aPusherEntity()
|
||||||
|
|
||||||
|
val mappedPusher = PushersMapper.map(pusherEntity)
|
||||||
|
|
||||||
|
mappedPusher.pushKey shouldBeEqualTo pusherEntity.pushKey
|
||||||
|
mappedPusher.kind shouldBeEqualTo pusherEntity.kind.orEmpty()
|
||||||
|
mappedPusher.appId shouldBeEqualTo pusherEntity.appId
|
||||||
|
mappedPusher.appDisplayName shouldBeEqualTo pusherEntity.appDisplayName
|
||||||
|
mappedPusher.deviceDisplayName shouldBeEqualTo pusherEntity.deviceDisplayName
|
||||||
|
mappedPusher.profileTag shouldBeEqualTo pusherEntity.profileTag
|
||||||
|
mappedPusher.lang shouldBeEqualTo pusherEntity.lang
|
||||||
|
mappedPusher.data.url shouldBeEqualTo pusherEntity.data?.url
|
||||||
|
mappedPusher.data.format shouldBeEqualTo pusherEntity.data?.format
|
||||||
|
mappedPusher.enabled shouldBeEqualTo pusherEntity.enabled
|
||||||
|
mappedPusher.deviceId shouldBeEqualTo pusherEntity.deviceId
|
||||||
|
mappedPusher.state shouldBeEqualTo pusherEntity.state
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when mapping JsonPusher, then it is mapped into Pusher successfully`() {
|
||||||
|
val jsonPusher = aJsonPusher()
|
||||||
|
|
||||||
|
val mappedPusherEntity = PushersMapper.map(jsonPusher)
|
||||||
|
|
||||||
|
mappedPusherEntity.pushKey shouldBeEqualTo jsonPusher.pushKey
|
||||||
|
mappedPusherEntity.kind shouldBeEqualTo jsonPusher.kind
|
||||||
|
mappedPusherEntity.appId shouldBeEqualTo jsonPusher.appId
|
||||||
|
mappedPusherEntity.appDisplayName shouldBeEqualTo jsonPusher.appDisplayName
|
||||||
|
mappedPusherEntity.deviceDisplayName shouldBeEqualTo jsonPusher.deviceDisplayName
|
||||||
|
mappedPusherEntity.profileTag shouldBeEqualTo jsonPusher.profileTag
|
||||||
|
mappedPusherEntity.lang shouldBeEqualTo jsonPusher.lang
|
||||||
|
mappedPusherEntity.data?.url shouldBeEqualTo jsonPusher.data?.url
|
||||||
|
mappedPusherEntity.data?.format shouldBeEqualTo jsonPusher.data?.format
|
||||||
|
mappedPusherEntity.enabled shouldBeEqualTo jsonPusher.enabled
|
||||||
|
mappedPusherEntity.deviceId shouldBeEqualTo jsonPusher.deviceId
|
||||||
|
}
|
||||||
|
}
|
@ -71,7 +71,7 @@ class DefaultAddPusherTaskTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given a persisted pusher when adding Pusher then updates api and mutates persisted result with Registered state`() {
|
fun `given a persisted pusher, when adding Pusher, then updates api and mutates persisted result with Registered state`() {
|
||||||
val realmResult = PusherEntity(appDisplayName = null)
|
val realmResult = PusherEntity(appDisplayName = null)
|
||||||
monarchy.givenWhereReturns(result = realmResult)
|
monarchy.givenWhereReturns(result = realmResult)
|
||||||
.givenEqualTo(PusherEntityFields.PUSH_KEY, A_JSON_PUSHER.pushKey)
|
.givenEqualTo(PusherEntityFields.PUSH_KEY, A_JSON_PUSHER.pushKey)
|
||||||
@ -85,7 +85,7 @@ class DefaultAddPusherTaskTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given a persisted push entity and SetPush API fails when adding Pusher then mutates persisted result with Failed registration state and rethrows`() {
|
fun `given a persisted push entity and SetPush API fails, when adding Pusher, then mutates persisted result with Failed registration state and rethrows`() {
|
||||||
val realmResult = PusherEntity()
|
val realmResult = PusherEntity()
|
||||||
monarchy.givenWhereReturns(result = realmResult)
|
monarchy.givenWhereReturns(result = realmResult)
|
||||||
.givenEqualTo(PusherEntityFields.PUSH_KEY, A_JSON_PUSHER.pushKey)
|
.givenEqualTo(PusherEntityFields.PUSH_KEY, A_JSON_PUSHER.pushKey)
|
||||||
@ -99,7 +99,7 @@ class DefaultAddPusherTaskTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given no persisted push entity and SetPush API fails when adding Pusher then rethrows error`() {
|
fun `given no persisted push entity and SetPush API fails, when adding Pusher, then rethrows error`() {
|
||||||
monarchy.givenWhereReturns<PusherEntity>(result = null)
|
monarchy.givenWhereReturns<PusherEntity>(result = null)
|
||||||
.givenEqualTo(PusherEntityFields.PUSH_KEY, A_JSON_PUSHER.pushKey)
|
.givenEqualTo(PusherEntityFields.PUSH_KEY, A_JSON_PUSHER.pushKey)
|
||||||
pushersAPI.givenSetPusherErrors(SocketException())
|
pushersAPI.givenSetPusherErrors(SocketException())
|
||||||
|
49
matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fixtures/JsonPusherFixture.kt
vendored
Normal file
49
matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fixtures/JsonPusherFixture.kt
vendored
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.matrix.android.sdk.test.fixtures
|
||||||
|
|
||||||
|
import org.matrix.android.sdk.internal.session.pushers.JsonPusher
|
||||||
|
import org.matrix.android.sdk.internal.session.pushers.JsonPusherData
|
||||||
|
|
||||||
|
internal object JsonPusherFixture {
|
||||||
|
|
||||||
|
fun aJsonPusher(
|
||||||
|
pushKey: String = "",
|
||||||
|
kind: String? = null,
|
||||||
|
appId: String = "",
|
||||||
|
appDisplayName: String? = null,
|
||||||
|
deviceDisplayName: String? = null,
|
||||||
|
profileTag: String? = null,
|
||||||
|
lang: String? = null,
|
||||||
|
data: JsonPusherData? = null,
|
||||||
|
append: Boolean? = false,
|
||||||
|
enabled: Boolean = true,
|
||||||
|
deviceId: String? = null,
|
||||||
|
) = JsonPusher(
|
||||||
|
pushKey,
|
||||||
|
kind,
|
||||||
|
appId,
|
||||||
|
appDisplayName,
|
||||||
|
deviceDisplayName,
|
||||||
|
profileTag,
|
||||||
|
lang,
|
||||||
|
data,
|
||||||
|
append,
|
||||||
|
enabled,
|
||||||
|
deviceId,
|
||||||
|
)
|
||||||
|
}
|
47
matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fixtures/PusherEntityFixture.kt
vendored
Normal file
47
matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fixtures/PusherEntityFixture.kt
vendored
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.matrix.android.sdk.test.fixtures
|
||||||
|
|
||||||
|
import org.matrix.android.sdk.internal.database.model.PusherDataEntity
|
||||||
|
import org.matrix.android.sdk.internal.database.model.PusherEntity
|
||||||
|
|
||||||
|
internal object PusherEntityFixture {
|
||||||
|
|
||||||
|
fun aPusherEntity(
|
||||||
|
pushKey: String = "",
|
||||||
|
kind: String? = null,
|
||||||
|
appId: String = "",
|
||||||
|
appDisplayName: String? = null,
|
||||||
|
deviceDisplayName: String? = null,
|
||||||
|
profileTag: String? = null,
|
||||||
|
lang: String? = null,
|
||||||
|
data: PusherDataEntity? = null,
|
||||||
|
enabled: Boolean = true,
|
||||||
|
deviceId: String? = null,
|
||||||
|
) = PusherEntity(
|
||||||
|
pushKey,
|
||||||
|
kind,
|
||||||
|
appId,
|
||||||
|
appDisplayName,
|
||||||
|
deviceDisplayName,
|
||||||
|
profileTag,
|
||||||
|
lang,
|
||||||
|
data,
|
||||||
|
enabled,
|
||||||
|
deviceId,
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user