From d90ba40e555d354c6a9fb5b3c4e05ea92311659b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Sat, 20 Aug 2022 13:36:04 +0200 Subject: [PATCH] Update send message test --- sdk-scrapper/build.gradle | 2 + .../sdk/scrapper/messages/MessagesTest.kt | 70 +++++++++++-------- .../sdk/scrapper/messages/WiadomoscNowa.json | 11 +++ .../scrapper/messages/WyslanaWiadomosc.json | 29 -------- 4 files changed, 54 insertions(+), 58 deletions(-) create mode 100644 sdk-scrapper/src/test/resources/io/github/wulkanowy/sdk/scrapper/messages/WiadomoscNowa.json delete mode 100644 sdk-scrapper/src/test/resources/io/github/wulkanowy/sdk/scrapper/messages/WyslanaWiadomosc.json diff --git a/sdk-scrapper/build.gradle b/sdk-scrapper/build.gradle index 22286b19..57037fa4 100644 --- a/sdk-scrapper/build.gradle +++ b/sdk-scrapper/build.gradle @@ -16,4 +16,6 @@ dependencies { implementation "com.brsanthu:migbase64:2.2" implementation "com.squareup.okhttp3:okhttp-urlconnection" + + testImplementation "io.mockk:mockk:1.12.5" } diff --git a/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/messages/MessagesTest.kt b/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/messages/MessagesTest.kt index 7eff7922..8ca144e4 100644 --- a/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/messages/MessagesTest.kt +++ b/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/messages/MessagesTest.kt @@ -3,6 +3,9 @@ package io.github.wulkanowy.sdk.scrapper.messages import io.github.wulkanowy.sdk.scrapper.BaseLocalTest import io.github.wulkanowy.sdk.scrapper.repository.MessagesRepository import io.github.wulkanowy.sdk.scrapper.service.MessagesService +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkStatic import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.runTest @@ -13,6 +16,7 @@ import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test +import java.util.UUID @OptIn(ExperimentalCoroutinesApi::class) class MessagesTest : BaseLocalTest() { @@ -190,35 +194,43 @@ class MessagesTest : BaseLocalTest() { assertEquals(125, res.content.length) } - // @Test - // fun sendMessageTest() { - // with(server) { - // enqueue("Start.html") - // enqueue("WyslanaWiadomosc.json") - // start(3000) - // } - // - // runBlocking { - // api.sendMessage( - // "Temat wiadomości", "Tak wygląda zawartość wiadomości.\nZazwyczaj ma wiele linijek.\n\nZ poważaniem,\nNazwisko Imię", - // listOf(Recipient("0", "Kowalski Jan", 0, 0, 2, "hash")) - // ) - // } - // - // server.takeRequest() - // - // val expected = Json.decodeFromString(MessagesTest::class.java.getResource("NowaWiadomosc.json")!!.readText()) - // val request = server.takeRequest() - // val actual = Json.decodeFromString(request.body.readUtf8()) - // - // assertEquals(expected, actual) - // assertEquals( - // "lX9xvk-OBA0VmHrNIFcQp2xVBZhza9tJ1QbYVKXGM3lFUr0a-OTDo5xUSQ70ROYKf6ICZ1LSXCfDAURoCmDZ-OEedW8IKtyF1s63HyWKxbmHaP-vsVCsGlN6zRHwx1r4h", - // request.getHeader("X-V-RequestVerificationToken") - // ) - // assertEquals("877c4a726ad61667f4e2237f0cf6307a", request.getHeader("X-V-AppGuid")) - // assertEquals("19.02.0001.32324", request.getHeader("X-V-AppVersion")) - // } + @Test + fun sendMessageTest() = runBlocking { + with(server) { + enqueue("Start.html") + enqueue("WiadomoscNowa.json") + start(3000) + } + + mockkStatic(UUID::randomUUID) + every { UUID.randomUUID() } returns mockk { + every { this@mockk.toString() } returnsMany listOf( + "1dc8c7a9-983f-4ea7-a4f1-d918beeed389", + "bfa544fb-0588-4aa0-afd0-1b9db31ce3ea", + ) + } + + api.sendMessage( + subject = "Temat wiadomości", + content = "Tak wygląda zawartość wiadomości.\nZazwyczaj ma wiele linijek.\n\nZ poważaniem,\nNazwisko Imię", + senderMailboxId = "05e5be82-b894-4864-823b-e79e4f91ce2d", + recipients = listOf("41c81103-a648-42b1-8519-ae3b2db6ea9b") + ) + + server.takeRequest() + + val expected = Json.decodeFromString(MessagesTest::class.java.getResource("WiadomoscNowa.json")!!.readText()) + val request = server.takeRequest() + val actual = Json.decodeFromString(request.body.readUtf8()) + + assertEquals(expected, actual) + assertEquals( + "lX9xvk-OBA0VmHrNIFcQp2xVBZhza9tJ1QbYVKXGM3lFUr0a-OTDo5xUSQ70ROYKf6ICZ1LSXCfDAURoCmDZ-OEedW8IKtyF1s63HyWKxbmHaP-vsVCsGlN6zRHwx1r4h", + request.getHeader("X-V-RequestVerificationToken") + ) + assertEquals("877c4a726ad61667f4e2237f0cf6307a", request.getHeader("X-V-AppGuid")) + assertEquals("19.02.0001.32324", request.getHeader("X-V-AppVersion")) + } @Test fun deleteMessageTest() = runBlocking { diff --git a/sdk-scrapper/src/test/resources/io/github/wulkanowy/sdk/scrapper/messages/WiadomoscNowa.json b/sdk-scrapper/src/test/resources/io/github/wulkanowy/sdk/scrapper/messages/WiadomoscNowa.json new file mode 100644 index 00000000..ff550dc2 --- /dev/null +++ b/sdk-scrapper/src/test/resources/io/github/wulkanowy/sdk/scrapper/messages/WiadomoscNowa.json @@ -0,0 +1,11 @@ +{ + "globalKey": "1dc8c7a9-983f-4ea7-a4f1-d918beeed389", + "watekGlobalKey": "bfa544fb-0588-4aa0-afd0-1b9db31ce3ea", + "nadawcaSkrzynkaGlobalKey": "05e5be82-b894-4864-823b-e79e4f91ce2d", + "adresaciSkrzynkiGlobalKeys": [ + "41c81103-a648-42b1-8519-ae3b2db6ea9b" + ], + "tytul": "Temat wiadomości", + "tresc": "Tak wygląda zawartość wiadomości.\nZazwyczaj ma wiele linijek.\n\nZ poważaniem,\nNazwisko Imię", + "zalaczniki": [] +} diff --git a/sdk-scrapper/src/test/resources/io/github/wulkanowy/sdk/scrapper/messages/WyslanaWiadomosc.json b/sdk-scrapper/src/test/resources/io/github/wulkanowy/sdk/scrapper/messages/WyslanaWiadomosc.json deleted file mode 100644 index 861fe08d..00000000 --- a/sdk-scrapper/src/test/resources/io/github/wulkanowy/sdk/scrapper/messages/WyslanaWiadomosc.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "success": true, - "data": { - "Adresaci": [ - { - "Id": "0", - "Name": "Kowalski Jan", - "IdLogin": 0, - "UnitId": null, - "Role": 2, - "PushMessage": false, - "Hash": "hash" - } - ], - "Temat": "Temat wiadomości", - "Tresc": "Tak wygląda zawartość wiadomości.\nZazwyczaj ma wiele linijek.\n\nZ poważaniem,\nNazwisko Imię", - "Nadawca": { - "Id": null, - "Name": "Kowalski Jan", - "IdLogin": 621, - "UnitId": null, - "Role": 0, - "PushMessage": null, - "Hash": "hash" - }, - "WiadomoscPowitalna": false, - "Id": 0 - } -}