Fix tests.
This commit is contained in:
parent
44a70729f8
commit
ff205042ec
2 changed files with 15 additions and 7 deletions
|
|
@ -12,6 +12,7 @@ import io.element.android.libraries.matrix.test.AN_EVENT_ID
|
||||||
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
||||||
import io.element.android.libraries.pushproviders.api.PushData
|
import io.element.android.libraries.pushproviders.api.PushData
|
||||||
import io.element.android.tests.testutils.assertThrowsInDebug
|
import io.element.android.tests.testutils.assertThrowsInDebug
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
class UnifiedPushParserTest {
|
class UnifiedPushParserTest {
|
||||||
|
|
@ -25,7 +26,7 @@ class UnifiedPushParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test edge cases UnifiedPush`() {
|
fun `test edge cases UnifiedPush`() {
|
||||||
val pushParser = UnifiedPushParser()
|
val pushParser = createUnifiedPushParser()
|
||||||
// Empty string
|
// Empty string
|
||||||
assertThat(pushParser.parse("".toByteArray(), aClientSecret)).isNull()
|
assertThat(pushParser.parse("".toByteArray(), aClientSecret)).isNull()
|
||||||
// Empty Json
|
// Empty Json
|
||||||
|
|
@ -36,13 +37,13 @@ class UnifiedPushParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test UnifiedPush format`() {
|
fun `test UnifiedPush format`() {
|
||||||
val pushParser = UnifiedPushParser()
|
val pushParser = createUnifiedPushParser()
|
||||||
assertThat(pushParser.parse(UNIFIED_PUSH_DATA.toByteArray(), aClientSecret)).isEqualTo(validData)
|
assertThat(pushParser.parse(UNIFIED_PUSH_DATA.toByteArray(), aClientSecret)).isEqualTo(validData)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test empty roomId`() {
|
fun `test empty roomId`() {
|
||||||
val pushParser = UnifiedPushParser()
|
val pushParser = createUnifiedPushParser()
|
||||||
assertThrowsInDebug {
|
assertThrowsInDebug {
|
||||||
pushParser.parse(UNIFIED_PUSH_DATA.replace(A_ROOM_ID.value, "").toByteArray(), aClientSecret)
|
pushParser.parse(UNIFIED_PUSH_DATA.replace(A_ROOM_ID.value, "").toByteArray(), aClientSecret)
|
||||||
}
|
}
|
||||||
|
|
@ -50,7 +51,7 @@ class UnifiedPushParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test invalid roomId`() {
|
fun `test invalid roomId`() {
|
||||||
val pushParser = UnifiedPushParser()
|
val pushParser = createUnifiedPushParser()
|
||||||
assertThrowsInDebug {
|
assertThrowsInDebug {
|
||||||
pushParser.parse(UNIFIED_PUSH_DATA.mutate(A_ROOM_ID.value, "aRoomId:domain"), aClientSecret)
|
pushParser.parse(UNIFIED_PUSH_DATA.mutate(A_ROOM_ID.value, "aRoomId:domain"), aClientSecret)
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +59,7 @@ class UnifiedPushParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test empty eventId`() {
|
fun `test empty eventId`() {
|
||||||
val pushParser = UnifiedPushParser()
|
val pushParser = createUnifiedPushParser()
|
||||||
assertThrowsInDebug {
|
assertThrowsInDebug {
|
||||||
pushParser.parse(UNIFIED_PUSH_DATA.mutate(AN_EVENT_ID.value, ""), aClientSecret)
|
pushParser.parse(UNIFIED_PUSH_DATA.mutate(AN_EVENT_ID.value, ""), aClientSecret)
|
||||||
}
|
}
|
||||||
|
|
@ -66,7 +67,7 @@ class UnifiedPushParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test invalid eventId`() {
|
fun `test invalid eventId`() {
|
||||||
val pushParser = UnifiedPushParser()
|
val pushParser = createUnifiedPushParser()
|
||||||
assertThrowsInDebug {
|
assertThrowsInDebug {
|
||||||
pushParser.parse(UNIFIED_PUSH_DATA.mutate(AN_EVENT_ID.value, "anEventId"), aClientSecret)
|
pushParser.parse(UNIFIED_PUSH_DATA.mutate(AN_EVENT_ID.value, "anEventId"), aClientSecret)
|
||||||
}
|
}
|
||||||
|
|
@ -81,3 +82,9 @@ class UnifiedPushParserTest {
|
||||||
private fun String.mutate(oldValue: String, newValue: String): ByteArray {
|
private fun String.mutate(oldValue: String, newValue: String): ByteArray {
|
||||||
return replace(oldValue, newValue).toByteArray()
|
return replace(oldValue, newValue).toByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun createUnifiedPushParser(
|
||||||
|
json: Json = Json { ignoreUnknownKeys = true },
|
||||||
|
) = UnifiedPushParser(
|
||||||
|
json = json,
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -191,6 +191,7 @@ class VectorUnifiedPushMessagingReceiverTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun TestScope.createVectorUnifiedPushMessagingReceiver(
|
private fun TestScope.createVectorUnifiedPushMessagingReceiver(
|
||||||
|
unifiedPushParser: UnifiedPushParser = createUnifiedPushParser(),
|
||||||
pushHandler: PushHandler = FakePushHandler(),
|
pushHandler: PushHandler = FakePushHandler(),
|
||||||
unifiedPushStore: UnifiedPushStore = FakeUnifiedPushStore(),
|
unifiedPushStore: UnifiedPushStore = FakeUnifiedPushStore(),
|
||||||
unifiedPushGatewayResolver: UnifiedPushGatewayResolver = FakeUnifiedPushGatewayResolver(),
|
unifiedPushGatewayResolver: UnifiedPushGatewayResolver = FakeUnifiedPushGatewayResolver(),
|
||||||
|
|
@ -199,7 +200,7 @@ class VectorUnifiedPushMessagingReceiverTest {
|
||||||
endpointRegistrationHandler: EndpointRegistrationHandler = EndpointRegistrationHandler(),
|
endpointRegistrationHandler: EndpointRegistrationHandler = EndpointRegistrationHandler(),
|
||||||
): VectorUnifiedPushMessagingReceiver {
|
): VectorUnifiedPushMessagingReceiver {
|
||||||
return VectorUnifiedPushMessagingReceiver().apply {
|
return VectorUnifiedPushMessagingReceiver().apply {
|
||||||
this.pushParser = UnifiedPushParser()
|
this.pushParser = unifiedPushParser
|
||||||
this.pushHandler = pushHandler
|
this.pushHandler = pushHandler
|
||||||
this.guardServiceStarter = NoopGuardServiceStarter()
|
this.guardServiceStarter = NoopGuardServiceStarter()
|
||||||
this.unifiedPushStore = unifiedPushStore
|
this.unifiedPushStore = unifiedPushStore
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue