From 12a91439e1fc783f87bd432312d00ec7542d6e12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Thu, 21 Mar 2019 22:42:40 +0100 Subject: [PATCH] Revert "Add deleting messages (#14)" (#15) This reverts commit ee999bbe933b9d87fbbaaf6be38950183c029d0f. --- .../kotlin/io/github/wulkanowy/api/Api.kt | 2 -- .../api/messages/DeleteMessageRequest.kt | 13 --------- .../api/repository/MessagesRepository.kt | 17 ----------- .../wulkanowy/api/service/MessagesService.kt | 9 ------ .../io/github/wulkanowy/api/BaseLocalTest.kt | 2 -- .../wulkanowy/api/messages/MessagesTest.kt | 29 +++---------------- .../wulkanowy/api/messages/UsunWiadomosc.json | 10 ------- 7 files changed, 4 insertions(+), 78 deletions(-) delete mode 100644 src/main/kotlin/io/github/wulkanowy/api/messages/DeleteMessageRequest.kt delete mode 100644 src/test/resources/io/github/wulkanowy/api/messages/UsunWiadomosc.json diff --git a/src/main/kotlin/io/github/wulkanowy/api/Api.kt b/src/main/kotlin/io/github/wulkanowy/api/Api.kt index 1bdcdbdb..557a1f9e 100644 --- a/src/main/kotlin/io/github/wulkanowy/api/Api.kt +++ b/src/main/kotlin/io/github/wulkanowy/api/Api.kt @@ -254,8 +254,6 @@ class Api { fun sendMessage(subject: String, content: String, recipients: List) = messages.sendMessage(subject, content, recipients) - fun deleteMessages(messages: List>) = this.messages.deleteMessages(messages) - fun getTimetable(startDate: LocalDate, endDate: LocalDate? = null) = if (useNewStudent) student.getTimetable(startDate, endDate) else snp.getTimetable(startDate, endDate) diff --git a/src/main/kotlin/io/github/wulkanowy/api/messages/DeleteMessageRequest.kt b/src/main/kotlin/io/github/wulkanowy/api/messages/DeleteMessageRequest.kt deleted file mode 100644 index 99fb4bc2..00000000 --- a/src/main/kotlin/io/github/wulkanowy/api/messages/DeleteMessageRequest.kt +++ /dev/null @@ -1,13 +0,0 @@ -package io.github.wulkanowy.api.messages - -import com.google.gson.annotations.SerializedName - -data class DeleteMessageRequest( - - @SerializedName("Id") - val messageId: Int, - - @SerializedName("Folder") - val folderId: Int - -) 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 7496910a..a5252691 100644 --- a/src/main/kotlin/io/github/wulkanowy/api/repository/MessagesRepository.kt +++ b/src/main/kotlin/io/github/wulkanowy/api/repository/MessagesRepository.kt @@ -1,7 +1,6 @@ package io.github.wulkanowy.api.repository import io.github.wulkanowy.api.getScriptParam -import io.github.wulkanowy.api.messages.DeleteMessageRequest import io.github.wulkanowy.api.messages.Message import io.github.wulkanowy.api.messages.Recipient import io.github.wulkanowy.api.messages.ReportingUnit @@ -88,22 +87,6 @@ class MessagesRepository(private val api: MessagesService) { } } - fun deleteMessages(messages: List>): Single { - return api.getStart().flatMap { res -> - api.deleteMessage( - messages.map { (messageId, folderId) -> - DeleteMessageRequest( - messageId = messageId, - folderId = folderId - ) - }, - getScriptParam("antiForgeryToken", res), - getScriptParam("appGuid", res), - getScriptParam("version", res) - ).map { it.success } - } - } - private fun String.normalizeRecipient(): String { return this.substringBeforeLast("-").substringBefore(" [").substringBeforeLast(" (").trim() } diff --git a/src/main/kotlin/io/github/wulkanowy/api/service/MessagesService.kt b/src/main/kotlin/io/github/wulkanowy/api/service/MessagesService.kt index 9da7e823..9a1f1da1 100644 --- a/src/main/kotlin/io/github/wulkanowy/api/service/MessagesService.kt +++ b/src/main/kotlin/io/github/wulkanowy/api/service/MessagesService.kt @@ -1,7 +1,6 @@ package io.github.wulkanowy.api.service import io.github.wulkanowy.api.ApiResponse -import io.github.wulkanowy.api.messages.DeleteMessageRequest import io.github.wulkanowy.api.messages.Message import io.github.wulkanowy.api.messages.Recipient import io.github.wulkanowy.api.messages.ReportingUnit @@ -58,12 +57,4 @@ interface MessagesService { @Header("X-V-AppGuid") appGuid: String, @Header("X-V-AppVersion") appVersion: String ): Single> - - @POST("Wiadomosc.mvc/UsunWiadomosc") - fun deleteMessage( - @Body deleteMessageRequests: List, - @Header("X-V-RequestVerificationToken") token: String, - @Header("X-V-AppGuid") appGuid: String, - @Header("X-V-AppVersion") appVersion: String - ): Single> } diff --git a/src/test/kotlin/io/github/wulkanowy/api/BaseLocalTest.kt b/src/test/kotlin/io/github/wulkanowy/api/BaseLocalTest.kt index 3fbd1109..5118cdd4 100644 --- a/src/test/kotlin/io/github/wulkanowy/api/BaseLocalTest.kt +++ b/src/test/kotlin/io/github/wulkanowy/api/BaseLocalTest.kt @@ -1,7 +1,6 @@ package io.github.wulkanowy.api import com.google.gson.GsonBuilder -import com.google.gson.JsonParser import io.github.wulkanowy.api.grades.DateDeserializer import io.github.wulkanowy.api.grades.GradeDate import io.github.wulkanowy.api.interceptor.ErrorInterceptor @@ -24,7 +23,6 @@ import retrofit2.converter.scalars.ScalarsConverterFactory abstract class BaseLocalTest : BaseTest() { val server = MockWebServer() - val jsonParser = JsonParser() @After fun tearDown() { 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 6478d623..05507aa2 100644 --- a/src/test/kotlin/io/github/wulkanowy/api/messages/MessagesTest.kt +++ b/src/test/kotlin/io/github/wulkanowy/api/messages/MessagesTest.kt @@ -1,5 +1,6 @@ package io.github.wulkanowy.api.messages +import com.google.gson.JsonParser import io.github.wulkanowy.api.BaseLocalTest import io.github.wulkanowy.api.repository.MessagesRepository import io.github.wulkanowy.api.service.MessagesService @@ -156,32 +157,10 @@ class MessagesTest : BaseLocalTest() { server.takeRequest() - val expected = jsonParser.parse(MessagesTest::class.java.getResource("NowaWiadomosc.json").readText()) + val parser = JsonParser() + val expected = parser.parse(MessagesTest::class.java.getResource("NowaWiadomosc.json").readText()) val request = server.takeRequest() - val actual = jsonParser.parse(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() { - server.enqueue(MockResponse().setBody(MessagesTest::class.java.getResource("Start.html").readText())) - server.enqueue(MockResponse().setBody("{\"success\": true}")) - server.start(3000) - - assertEquals(api.deleteMessages(listOf(Pair(74, 1), Pair(69, 2))).blockingGet(), true) - - server.takeRequest() - - val expected = jsonParser.parse(MessagesTest::class.java.getResource("UsunWiadomosc.json").readText()) - val request = server.takeRequest() - val actual = jsonParser.parse(request.body.readUtf8()) + val actual = parser.parse(request.body.readUtf8()) assertEquals(expected, actual) assertEquals( diff --git a/src/test/resources/io/github/wulkanowy/api/messages/UsunWiadomosc.json b/src/test/resources/io/github/wulkanowy/api/messages/UsunWiadomosc.json deleted file mode 100644 index 22e93e4b..00000000 --- a/src/test/resources/io/github/wulkanowy/api/messages/UsunWiadomosc.json +++ /dev/null @@ -1,10 +0,0 @@ -[ - { - "Id": 74, - "Folder": 1 - }, - { - "Id": 69, - "Folder": 2 - } -]