Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
vendelieu committed Feb 13, 2025
1 parent 85a00cb commit 90fddbc
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 108 deletions.
85 changes: 41 additions & 44 deletions telegram-bot/api/telegram-bot.api

Large diffs are not rendered by default.

60 changes: 31 additions & 29 deletions telegram-bot/api/telegram-bot.klib.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package eu.vendeli.tgbot.types.internal.options

import eu.vendeli.tgbot.types.ParseMode
import eu.vendeli.tgbot.types.ReplyParameters
import eu.vendeli.tgbot.utils.serde.InstantSerializer
import kotlinx.datetime.Instant
import eu.vendeli.tgbot.utils.serde.DurationSerializer
import kotlinx.serialization.Serializable
import kotlin.time.Duration

@Serializable
data class CopyMessageOptions(
@Serializable(InstantSerializer::class)
var videoStartTimestamp: Instant? = null,
@Serializable(DurationSerializer::class)
var videoStartTimestamp: Duration? = null,
override var showCaptionAboveMedia: Boolean? = null,
override var disableNotification: Boolean? = null,
override var protectContent: Boolean? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package eu.vendeli.tgbot.types.internal.options

import eu.vendeli.tgbot.utils.serde.InstantSerializer
import kotlinx.datetime.Instant
import eu.vendeli.tgbot.utils.serde.DurationSerializer
import kotlinx.serialization.Serializable
import kotlin.time.Duration

@Serializable
data class ForwardMessageOptions(
@Serializable(InstantSerializer::class)
var videoStartTimestamp: Instant? = null,
@Serializable(DurationSerializer::class)
var videoStartTimestamp: Duration? = null,
var disableNotification: Boolean? = null,
var protectContent: Boolean? = null,
var messageThreadId: Int? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package eu.vendeli.tgbot.types.internal.options
import eu.vendeli.tgbot.types.ParseMode
import eu.vendeli.tgbot.types.ReplyParameters
import eu.vendeli.tgbot.types.internal.ImplicitFile
import eu.vendeli.tgbot.utils.serde.InstantSerializer
import kotlinx.datetime.Instant
import eu.vendeli.tgbot.utils.serde.DurationSerializer
import kotlinx.serialization.Serializable
import kotlin.time.Duration

@Serializable
data class VideoOptions(
Expand All @@ -14,8 +14,8 @@ data class VideoOptions(
var width: Int? = null,
var supportsStreaming: Boolean? = null,
var cover: ImplicitFile? = null,
@Serializable(InstantSerializer::class)
var startTimestamp: Instant? = null,
@Serializable(DurationSerializer::class)
var startTimestamp: Duration? = null,
override var thumbnail: ImplicitFile? = null,
override var showCaptionAboveMedia: Boolean? = null,
override var parseMode: ParseMode? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import eu.vendeli.tgbot.interfaces.helper.ImplicitMediaData
import eu.vendeli.tgbot.types.ParseMode
import eu.vendeli.tgbot.types.internal.ImplicitFile
import eu.vendeli.tgbot.types.msg.MessageEntity
import eu.vendeli.tgbot.utils.serde.InstantSerializer
import kotlinx.datetime.Instant
import eu.vendeli.tgbot.utils.serde.DurationSerializer
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.InternalSerializationApi
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.serializer
import kotlin.time.Duration

/**
* This object represents the content of a media message to be sent. It should be one of
Expand Down Expand Up @@ -72,8 +72,8 @@ sealed class InputMedia : ImplicitMediaData {
override var media: ImplicitFile,
override var thumbnail: ImplicitFile? = null,
val cover: ImplicitFile? = null,
@Serializable(InstantSerializer::class)
val startTimestamp: Instant? = null,
@Serializable(DurationSerializer::class)
val startTimestamp: Duration? = null,
val caption: String? = null,
val parseMode: ParseMode? = null,
val captionEntities: List<MessageEntity>? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package eu.vendeli.tgbot.types.media
import eu.vendeli.tgbot.interfaces.helper.ImplicitMediaData
import eu.vendeli.tgbot.types.internal.ImplicitFile
import eu.vendeli.tgbot.types.internal.InputFile
import eu.vendeli.tgbot.utils.serde.InstantSerializer
import eu.vendeli.tgbot.utils.serde.DurationSerializer
import eu.vendeli.tgbot.utils.toImplicitFile
import kotlinx.datetime.Instant
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.InternalSerializationApi
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.serializer
import kotlin.time.Duration

@Serializable
@Suppress("OVERRIDE_DEPRECATION")
Expand All @@ -35,8 +35,8 @@ sealed class InputPaidMedia : ImplicitMediaData {
override var media: ImplicitFile,
override var thumbnail: ImplicitFile? = null,
val cover: ImplicitFile? = null,
@Serializable(InstantSerializer::class)
val startTimestamp: Instant? = null,
@Serializable(DurationSerializer::class)
val startTimestamp: Duration? = null,
val width: Int? = null,
val height: Int? = null,
val duration: Int? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package eu.vendeli.tgbot.types.media

import eu.vendeli.tgbot.types.internal.ImplicitFile
import eu.vendeli.tgbot.utils.serde.InstantSerializer
import kotlinx.datetime.Instant
import eu.vendeli.tgbot.utils.serde.DurationSerializer
import kotlinx.serialization.Serializable
import kotlin.time.Duration

/**
* This object represents a video file.
Expand All @@ -29,9 +28,9 @@ data class Video(
val height: Int,
val duration: Int,
val thumbnail: PhotoSize? = null,
val cover: ImplicitFile? = null,
@Serializable(InstantSerializer::class)
val startTimestamp: Instant? = null,
val cover: List<PhotoSize>? = null,
@Serializable(DurationSerializer::class)
val startTimestamp: Duration? = null,
val fileName: String? = null,
val mimeType: String? = null,
val fileSize: Long? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class MediaRequestTesting : BotTestContext() {
parseMode = ParseMode.HTML,
),
InputMedia.Photo(imageBytes.toImplicitFile()),
InputMedia.Photo(RandomPicResource.RANDOM_PIC_URL),
InputMedia.Photo(RandomPicResource.RANDOM_PIC_URL.toImplicitFile()),
).sendReq().getOrNull()

mediaRequest.shouldNotBeNull()
Expand All @@ -89,8 +89,8 @@ class MediaRequestTesting : BotTestContext() {
assertThrows<IllegalArgumentException>("All elements must be of the same specific type") {
SendMediaGroupAction(
listOf(
InputMedia.Photo(""),
InputMedia.Audio(""),
InputMedia.Photo("".toImplicitFile()),
InputMedia.Audio("".toImplicitFile()),
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import eu.vendeli.tgbot.types.internal.getOrNull
import eu.vendeli.tgbot.types.keyboard.InlineKeyboardButton
import eu.vendeli.tgbot.types.media.InputMedia
import eu.vendeli.tgbot.utils.builders.inlineKeyboardMarkup
import eu.vendeli.tgbot.utils.toImplicitFile
import io.kotest.matchers.nulls.shouldBeNull
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.shouldBe
Expand Down Expand Up @@ -59,13 +60,13 @@ class EditActionsTest : BotTestContext() {

val result = editMessageMedia(
msg.messageId,
InputMedia.Photo(RandomPicResource.RANDOM_PIC_URL),
InputMedia.Photo(RandomPicResource.RANDOM_PIC_URL.toImplicitFile()),
).sendReq().shouldSuccess()

with(result) {
text.shouldBeNull()
photo.shouldNotBeNull()
photo?.first()?.fileUniqueId shouldNotBe msg.photo?.first()?.fileUniqueId
photo.first().fileUniqueId shouldNotBe msg.photo?.first()?.fileUniqueId
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GiftTest : BotTestContext() {
@Test
suspend fun `send gift test`() {
val available = getAvailableGifts().sendReturning(bot).shouldSuccess()
val result = sendGift(TG_ID, available.gifts.first().id) {
sendGift(available.gifts.first().id, TG_ID) {
"test"
}.sendReturning(bot).shouldFailure() shouldContainInDescription "BALANCE_TOO_LOW"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class MediaTest : BotTestContext() {
shouldNotBeNull()
text.shouldBeNull()
animation.shouldNotBeNull()
animation?.fileName.shouldNotBeNull().shouldNotBeBlank()
animation.fileName.shouldNotBeNull().shouldNotBeBlank()
}
}
}
Expand All @@ -113,7 +113,7 @@ class MediaTest : BotTestContext() {
shouldNotBeNull()
text.shouldBeNull()
document.shouldNotBeNull()
document!!.fileName.shouldNotBeNull().shouldNotBeBlank()
document.fileName.shouldNotBeNull().shouldNotBeBlank()
}
}
}
Expand All @@ -131,7 +131,7 @@ class MediaTest : BotTestContext() {
shouldNotBeNull()
text.shouldBeNull()
video.shouldNotBeNull()
video?.fileName.shouldNotBeNull().shouldNotBeBlank()
video.fileName.shouldNotBeNull().shouldNotBeBlank()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package eu.vendeli.api.media

import BotTestContext
import eu.vendeli.tgbot.api.media.video
import eu.vendeli.tgbot.utils.toImplicitFile
import eu.vendeli.utils.LOREM
import io.kotest.matchers.collections.shouldHaveSize
import io.kotest.matchers.nulls.shouldBeNull
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldNotBeBlank
import kotlin.time.Duration.Companion.seconds

class SendVideoAdditionalTest : BotTestContext() {
@Test
@Suppress("ktlint:standard:function-naming")
suspend fun `send video with cover and start parameter`() {
val lorem = LOREM.VIDEO
val coverImage = RANDOM_PIC ?: return

val result = video(lorem.bytes)
.options {
cover = coverImage.toImplicitFile("image.png", "image/png")
startTimestamp = 2.seconds
}.sendReq()
.shouldSuccess()

with(result) {
text.shouldBeNull()
video.shouldNotBeNull()
video.fileName.shouldNotBeNull().shouldNotBeBlank()
video.cover.shouldNotBeNull() shouldHaveSize 1
video.startTimestamp.shouldNotBeNull() shouldBe 2.seconds
}
}
}

0 comments on commit 90fddbc

Please sign in to comment.