Add test on DefaultTestPush
This commit is contained in:
parent
f95af132cb
commit
be9e57cf43
4 changed files with 98 additions and 8 deletions
|
|
@ -15,14 +15,14 @@
|
||||||
*/
|
*/
|
||||||
package io.element.android.libraries.push.impl.pushgateway
|
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.EventId
|
||||||
import io.element.android.libraries.matrix.api.core.RoomId
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
import io.element.android.libraries.push.api.gateway.PushGatewayFailure
|
import io.element.android.libraries.push.api.gateway.PushGatewayFailure
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class PushGatewayNotifyRequest @Inject constructor(
|
interface PushGatewayNotifyRequest {
|
||||||
private val pushGatewayApiFactory: PushGatewayApiFactory,
|
|
||||||
) {
|
|
||||||
data class Params(
|
data class Params(
|
||||||
val url: String,
|
val url: String,
|
||||||
val appId: String,
|
val appId: String,
|
||||||
|
|
@ -31,7 +31,15 @@ class PushGatewayNotifyRequest @Inject constructor(
|
||||||
val roomId: RoomId,
|
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(
|
val pushGatewayApi = pushGatewayApiFactory.create(
|
||||||
params.url.substringBefore(PushGatewayConfig.URI_PUSH_GATEWAY_PREFIX_PATH)
|
params.url.substringBefore(PushGatewayConfig.URI_PUSH_GATEWAY_PREFIX_PATH)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Assert.assertThrows
|
import org.junit.Assert.assertThrows
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
class PushGatewayNotifyRequestTest {
|
class DefaultPushGatewayNotifyRequestTest {
|
||||||
@Test
|
@Test
|
||||||
fun `notify success`() = runTest {
|
fun `notify success`() = runTest {
|
||||||
val factory = FakePushGatewayApiFactory(
|
val factory = FakePushGatewayApiFactory(
|
||||||
|
|
@ -33,7 +33,7 @@ class PushGatewayNotifyRequestTest {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
val pushGatewayNotifyRequest = PushGatewayNotifyRequest(
|
val pushGatewayNotifyRequest = DefaultPushGatewayNotifyRequest(
|
||||||
pushGatewayApiFactory = factory,
|
pushGatewayApiFactory = factory,
|
||||||
)
|
)
|
||||||
pushGatewayNotifyRequest.execute(
|
pushGatewayNotifyRequest.execute(
|
||||||
|
|
@ -57,7 +57,7 @@ class PushGatewayNotifyRequestTest {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
val pushGatewayNotifyRequest = PushGatewayNotifyRequest(
|
val pushGatewayNotifyRequest = DefaultPushGatewayNotifyRequest(
|
||||||
pushGatewayApiFactory = factory,
|
pushGatewayApiFactory = factory,
|
||||||
)
|
)
|
||||||
pushGatewayNotifyRequest.execute(
|
pushGatewayNotifyRequest.execute(
|
||||||
|
|
@ -81,7 +81,7 @@ class PushGatewayNotifyRequestTest {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
val pushGatewayNotifyRequest = PushGatewayNotifyRequest(
|
val pushGatewayNotifyRequest = DefaultPushGatewayNotifyRequest(
|
||||||
pushGatewayApiFactory = factory,
|
pushGatewayApiFactory = factory,
|
||||||
)
|
)
|
||||||
assertThrows(PushGatewayFailure.PusherRejected::class.java) {
|
assertThrows(PushGatewayFailure.PusherRejected::class.java) {
|
||||||
|
|
@ -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,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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…
Add table
Add a link
Reference in a new issue