From 1bce1e6d42a31d64b28bc738dabf69e04d3eaf0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Sun, 13 Jan 2019 21:53:45 +0100 Subject: [PATCH] Fix incorrectly splitted recipient name --- .../api/repository/MessagesRepository.kt | 2 +- .../wulkanowy/api/messages/MessagesTest.kt | 34 ++++++++++++++++--- .../wulkanowy/api/messages/Adresaci.json | 11 +++++- .../api/messages/WiadomosciWyslane.json | 10 +++++- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/io/github/wulkanowy/api/repository/MessagesRepository.kt b/src/main/kotlin/io/github/wulkanowy/api/repository/MessagesRepository.kt index eddd119e..1b2e6df1 100644 --- a/src/main/kotlin/io/github/wulkanowy/api/repository/MessagesRepository.kt +++ b/src/main/kotlin/io/github/wulkanowy/api/repository/MessagesRepository.kt @@ -57,7 +57,7 @@ class MessagesRepository(private val api: MessagesService) { listOf(Recipient("0", message.recipient ?: "unknown", 0, 0, 2, "unknown")) }) }.map { - message.copy(recipient = it.name.split(" -").first(), messageId = message.id).apply { + message.copy(recipient = it.name.substringBeforeLast(" -"), messageId = message.id).apply { recipientId = it.loginId } } diff --git a/src/test/kotlin/io/github/wulkanowy/api/messages/MessagesTest.kt b/src/test/kotlin/io/github/wulkanowy/api/messages/MessagesTest.kt index 179e4765..18e1aad4 100644 --- a/src/test/kotlin/io/github/wulkanowy/api/messages/MessagesTest.kt +++ b/src/test/kotlin/io/github/wulkanowy/api/messages/MessagesTest.kt @@ -1,6 +1,5 @@ package io.github.wulkanowy.api.messages -import com.google.gson.Gson import com.google.gson.JsonParser import io.github.wulkanowy.api.BaseLocalTest import io.github.wulkanowy.api.repository.MessagesRepository @@ -38,7 +37,7 @@ class MessagesTest : BaseLocalTest() { server.enqueue(MockResponse().setBody(MessagesTest::class.java.getResource("Adresaci.json").readText())) server.start(3000) - assertEquals(1, api.getSentMessages(null, null).blockingGet().size) + assertEquals(2, api.getSentMessages(null, null).blockingGet().size) } @Test @@ -48,7 +47,33 @@ class MessagesTest : BaseLocalTest() { // server.enqueue(MockResponse().setBody(MessagesTest::class.java.getResource("Adresaci.json").readText())) server.start(3000) - assertEquals(1, api.getSentMessages(null, null).blockingGet().size) + assertEquals(2, api.getSentMessages(null, null).blockingGet().size) + } + + @Test + fun getMessagesSent_recipientWithDashInName() { + server.enqueue(MockResponse().setBody(MessagesTest::class.java.getResource("WiadomosciWyslane.json").readText())) + server.enqueue(MockResponse().setBody(MessagesTest::class.java.getResource("JednostkiUzytkownika.json").readText())) + server.enqueue(MockResponse().setBody(MessagesTest::class.java.getResource("Adresaci.json").readText())) + server.start(3000) + + val recipients = api.getSentMessages(null, null).blockingGet() + + assertEquals("Czerwieńska - Kowalska Joanna [CJ]", recipients[1].recipient) + assertEquals(95, recipients[1].recipientId) + } + + @Test + fun getMessagesSent_recipientWithDashInNameAndEmptyUnits() { + server.enqueue(MockResponse().setBody(MessagesTest::class.java.getResource("WiadomosciWyslane.json").readText())) + server.enqueue(MockResponse().setBody(MessagesTest::class.java.getResource("JednostkiUzytkownika-empty.json").readText())) +// server.enqueue(MockResponse().setBody(MessagesTest::class.java.getResource("Adresaci.json").readText())) + server.start(3000) + + val recipients = api.getSentMessages(null, null).blockingGet() + + assertEquals("Czerwieńska - Kowalska Joanna [CJ]", recipients[1].recipient) + assertEquals(0, recipients[1].recipientId) } @Test @@ -65,7 +90,8 @@ class MessagesTest : BaseLocalTest() { server.start(3000) 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"))).blockingGet() + listOf(Recipient("0", "Kowalski Jan", 0, 0, 2, "hash")) + ).blockingGet() val parser = JsonParser() val expected = parser.parse(MessagesTest::class.java.getResource("NowaWiadomosc.json").readText()) diff --git a/src/test/resources/io/github/wulkanowy/api/messages/Adresaci.json b/src/test/resources/io/github/wulkanowy/api/messages/Adresaci.json index b8cf1313..fd0fa116 100644 --- a/src/test/resources/io/github/wulkanowy/api/messages/Adresaci.json +++ b/src/test/resources/io/github/wulkanowy/api/messages/Adresaci.json @@ -3,7 +3,7 @@ "data": [ { "Id": "18rPracownik", - "Nazwa": "Janusz Tracz [TJ] - pracownik (Fake123456)", + "Nazwa": "Tracz Janusz [TJ] - pracownik (Fake123456)", "IdLogin": 18, "IdJednostkaSprawozdawcza": 6, "RolaEnum": null, @@ -18,6 +18,15 @@ "RolaEnum": null, "Rola": 2, "PushWiadomosc": null + }, + { + "Id": "95rPracownik", + "Nazwa": "Czerwieńska - Kowalska Joanna [CJ] - pracownik (Fake123456)", + "IdLogin": 95, + "IdJednostkaSprawozdawcza": 6, + "RolaEnum": null, + "Rola": 2, + "PushWiadomosc": null } ] } diff --git a/src/test/resources/io/github/wulkanowy/api/messages/WiadomosciWyslane.json b/src/test/resources/io/github/wulkanowy/api/messages/WiadomosciWyslane.json index 66db5ff9..5e4c8739 100644 --- a/src/test/resources/io/github/wulkanowy/api/messages/WiadomosciWyslane.json +++ b/src/test/resources/io/github/wulkanowy/api/messages/WiadomosciWyslane.json @@ -4,10 +4,18 @@ { "Data": "2018-06-11T07:38:35.000Z", "Temat": "Usprawiedliwienie nieobecności", - "Adresaci": "Janusz Tracz [TJ] - pracownik (Fake123456)", + "Adresaci": "Tracz Janusz [TJ] - pracownik (Fake123456)", "Nieprzeczytane": "1", "Przeczytane": "0", "Id": 32798 + }, + { + "Data": "2018-06-11T09:38:35.000Z", + "Temat": "Wiadomość testowa", + "Adresaci": "Czerwieńska - Kowalska Joanna [CJ] - pracownik (Fake123456)", + "Nieprzeczytane": "1", + "Przeczytane": "0", + "Id": 32799 } ] }