1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-02 16:05:28 +00:00
tgbotapi/TelegramBotAPI/src/commonTest/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/BotActionTests.kt

63 lines
2.3 KiB
Kotlin
Raw Normal View History

2019-12-02 07:21:31 +00:00
package com.github.insanusmokrassar.TelegramBotAPI.types
2020-03-22 09:15:01 +00:00
import com.github.insanusmokrassar.TelegramBotAPI.TestsJsonFormat
2019-12-02 07:21:31 +00:00
import com.github.insanusmokrassar.TelegramBotAPI.types.actions.*
import kotlinx.serialization.Serializable
import kotlin.test.Test
import kotlin.test.assertEquals
class BotActionTests {
@Serializable
data class Example(
val botAction: BotAction
)
private fun checkBotAction(example: Example, sourceAction: BotAction) {
assertEquals(
sourceAction.actionName,
when (example.botAction) {
TypingAction -> example.botAction.actionName
UploadPhotoAction -> example.botAction.actionName
RecordVideoAction -> example.botAction.actionName
UploadVideoAction -> example.botAction.actionName
RecordAudioAction -> example.botAction.actionName
UploadAudioAction -> example.botAction.actionName
UploadDocumentAction -> example.botAction.actionName
FindLocationAction -> example.botAction.actionName
2020-02-07 04:49:16 +00:00
RecordVideoNoteAction -> example.botAction.actionName
UploadVideoNoteAction -> example.botAction.actionName
2019-12-02 07:21:31 +00:00
}
)
}
private fun checkBotActionSerializeDeserialize(example: Example) {
2020-08-18 06:50:11 +00:00
val stringified = TestsJsonFormat.encodeToString(Example.serializer(), example)
2019-12-02 07:21:31 +00:00
assertEquals("{\"botAction\":\"${example.botAction.actionName}\"}", stringified)
2020-08-18 06:50:11 +00:00
val deserialized = TestsJsonFormat.decodeFromString(Example.serializer(), stringified)
2019-12-02 07:21:31 +00:00
assertEquals(example, deserialized)
checkBotAction(deserialized, example.botAction)
}
@Test
2020-08-18 06:50:11 +00:00
fun `BotAction_correctly_serialized_and_deserialized`() {
2019-12-02 07:21:31 +00:00
fun BotAction.example() = Example(this)
listOf(
TypingAction.example(),
UploadPhotoAction.example(),
RecordVideoAction.example(),
UploadVideoAction.example(),
RecordAudioAction.example(),
UploadAudioAction.example(),
UploadDocumentAction.example(),
2020-02-07 04:49:16 +00:00
FindLocationAction.example(),
RecordVideoNoteAction.example(),
UploadVideoNoteAction.example()
2019-12-02 07:21:31 +00:00
).forEach {
checkBotActionSerializeDeserialize(it)
}
}
}