2020-10-04 11:06:30 +00:00
|
|
|
package dev.inmo.tgbotapi
|
2020-08-23 17:42:50 +00:00
|
|
|
|
2020-10-04 11:06:30 +00:00
|
|
|
import dev.inmo.tgbotapi.requests.abstracts.toInputFile
|
2022-04-22 07:54:06 +00:00
|
|
|
import dev.inmo.tgbotapi.types.media.MediaGroupMemberTelegramMediaSerializer
|
2020-10-04 11:06:30 +00:00
|
|
|
import dev.inmo.tgbotapi.types.files.PhotoSize
|
2022-05-01 05:52:02 +00:00
|
|
|
import dev.inmo.tgbotapi.types.message.content.PhotoContent
|
2020-08-23 18:34:30 +00:00
|
|
|
import kotlinx.serialization.json.Json
|
2020-08-23 17:42:50 +00:00
|
|
|
import kotlin.test.Test
|
2020-08-29 13:51:10 +00:00
|
|
|
import kotlin.test.assertEquals
|
2020-08-23 17:42:50 +00:00
|
|
|
|
2020-08-23 18:34:30 +00:00
|
|
|
private val nonstrictJsonFormat = Json {
|
|
|
|
isLenient = true
|
|
|
|
ignoreUnknownKeys = true
|
|
|
|
allowSpecialFloatingPointValues = true
|
|
|
|
useArrayPolymorphism = true
|
2020-09-22 05:33:47 +00:00
|
|
|
encodeDefaults = true
|
2020-08-23 18:34:30 +00:00
|
|
|
}
|
|
|
|
|
2020-08-23 17:42:50 +00:00
|
|
|
class SimpleInputFilesTest {
|
|
|
|
@Test
|
|
|
|
fun test_that_creating_of_photo_and_converting_to_input_media_working_correctly() {
|
|
|
|
val photoContent = PhotoContent(
|
|
|
|
listOf(
|
|
|
|
PhotoSize("example_file_id".toInputFile(), "example_unique_file_id", 100, 100, 100)
|
|
|
|
)
|
|
|
|
)
|
2022-04-22 07:54:06 +00:00
|
|
|
val inputMedia = photoContent.toMediaGroupMemberTelegramMedia()
|
2020-08-29 13:52:46 +00:00
|
|
|
assertEquals(photoContent.media.fileId, inputMedia.file)
|
2020-08-29 13:51:10 +00:00
|
|
|
val encoded = nonstrictJsonFormat.encodeToString(
|
2022-04-22 07:54:06 +00:00
|
|
|
MediaGroupMemberTelegramMediaSerializer,
|
2020-08-29 13:51:10 +00:00
|
|
|
inputMedia
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
inputMedia,
|
|
|
|
nonstrictJsonFormat.decodeFromString(
|
2022-04-22 07:54:06 +00:00
|
|
|
MediaGroupMemberTelegramMediaSerializer,
|
2020-08-29 13:51:10 +00:00
|
|
|
encoded
|
|
|
|
)
|
2020-08-23 18:34:30 +00:00
|
|
|
)
|
2020-08-23 17:42:50 +00:00
|
|
|
}
|
|
|
|
}
|