Browse Source

Add test on DefaultTestPush

pull/2899/head
Benoit Marty 4 months ago
parent
commit
3bde744d76
  1. 16
      libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/pushgateway/PushGatewayNotifyRequest.kt
  2. 8
      libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/pushgateway/DefaultPushGatewayNotifyRequestTest.kt
  3. 55
      libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/test/DefaultTestPushTest.kt
  4. 27
      libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/test/FakePushGatewayNotifyRequest.kt

16
libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/pushgateway/PushGatewayNotifyRequest.kt

@ -15,14 +15,14 @@ @@ -15,14 +15,14 @@
*/
package io.element.android.libraries.push.impl.pushgateway
import com.squareup.anvil.annotations.ContributesBinding
import io.element.android.libraries.di.AppScope
import io.element.android.libraries.matrix.api.core.EventId
import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.push.api.gateway.PushGatewayFailure
import javax.inject.Inject
class PushGatewayNotifyRequest @Inject constructor(
private val pushGatewayApiFactory: PushGatewayApiFactory,
) {
interface PushGatewayNotifyRequest {
data class Params(
val url: String,
val appId: String,
@ -31,7 +31,15 @@ class PushGatewayNotifyRequest @Inject constructor( @@ -31,7 +31,15 @@ class PushGatewayNotifyRequest @Inject constructor(
val roomId: RoomId,
)
suspend fun execute(params: Params) {
suspend fun execute(params: Params)
}
@ContributesBinding(AppScope::class)
class DefaultPushGatewayNotifyRequest @Inject constructor(
private val pushGatewayApiFactory: PushGatewayApiFactory,
) : PushGatewayNotifyRequest {
override suspend fun execute(params: PushGatewayNotifyRequest.Params) {
val pushGatewayApi = pushGatewayApiFactory.create(
params.url.substringBefore(PushGatewayConfig.URI_PUSH_GATEWAY_PREFIX_PATH)
)

8
libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/pushgateway/PushGatewayNotifyRequestTest.kt → libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/pushgateway/DefaultPushGatewayNotifyRequestTest.kt

@ -23,7 +23,7 @@ import kotlinx.coroutines.test.runTest @@ -23,7 +23,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertThrows
import org.junit.Test
class PushGatewayNotifyRequestTest {
class DefaultPushGatewayNotifyRequestTest {
@Test
fun `notify success`() = runTest {
val factory = FakePushGatewayApiFactory(
@ -33,7 +33,7 @@ class PushGatewayNotifyRequestTest { @@ -33,7 +33,7 @@ class PushGatewayNotifyRequestTest {
)
}
)
val pushGatewayNotifyRequest = PushGatewayNotifyRequest(
val pushGatewayNotifyRequest = DefaultPushGatewayNotifyRequest(
pushGatewayApiFactory = factory,
)
pushGatewayNotifyRequest.execute(
@ -57,7 +57,7 @@ class PushGatewayNotifyRequestTest { @@ -57,7 +57,7 @@ class PushGatewayNotifyRequestTest {
)
}
)
val pushGatewayNotifyRequest = PushGatewayNotifyRequest(
val pushGatewayNotifyRequest = DefaultPushGatewayNotifyRequest(
pushGatewayApiFactory = factory,
)
pushGatewayNotifyRequest.execute(
@ -81,7 +81,7 @@ class PushGatewayNotifyRequestTest { @@ -81,7 +81,7 @@ class PushGatewayNotifyRequestTest {
)
}
)
val pushGatewayNotifyRequest = PushGatewayNotifyRequest(
val pushGatewayNotifyRequest = DefaultPushGatewayNotifyRequest(
pushGatewayApiFactory = factory,
)
assertThrows(PushGatewayFailure.PusherRejected::class.java) {

55
libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/test/DefaultTestPushTest.kt

@ -0,0 +1,55 @@ @@ -0,0 +1,55 @@
/*
* Copyright (c) 2024 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 io.element.android.libraries.push.impl.test
import io.element.android.appconfig.PushConfig
import io.element.android.libraries.push.impl.pushgateway.PushGatewayNotifyRequest
import io.element.android.libraries.pushproviders.api.CurrentUserPushConfig
import io.element.android.tests.testutils.lambda.lambdaRecorder
import io.element.android.tests.testutils.lambda.value
import kotlinx.coroutines.test.runTest
import org.junit.Test
class DefaultTestPushTest {
@Test
fun `test DefaultTestPush`() = runTest {
val executeResult = lambdaRecorder<PushGatewayNotifyRequest.Params, Unit> { }
val defaultTestPush = DefaultTestPush(
pushGatewayNotifyRequest = FakePushGatewayNotifyRequest(
executeResult = executeResult,
)
)
val aConfig = CurrentUserPushConfig(
url = "aUrl",
pushKey = "aPushKey",
)
defaultTestPush.execute(aConfig)
executeResult.assertions()
.isCalledOnce()
.with(
value(
PushGatewayNotifyRequest.Params(
url = aConfig.url,
appId = PushConfig.PUSHER_APP_ID,
pushKey = aConfig.pushKey,
eventId = DefaultTestPush.TEST_EVENT_ID,
roomId = DefaultTestPush.TEST_ROOM_ID,
)
)
)
}
}

27
libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/test/FakePushGatewayNotifyRequest.kt

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
/*
* Copyright (c) 2024 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 io.element.android.libraries.push.impl.test
import io.element.android.libraries.push.impl.pushgateway.PushGatewayNotifyRequest
class FakePushGatewayNotifyRequest(
private val executeResult: (PushGatewayNotifyRequest.Params) -> Unit = { TODO() }
) : PushGatewayNotifyRequest {
override suspend fun execute(params: PushGatewayNotifyRequest.Params) {
executeResult(params)
}
}
Loading…
Cancel
Save