Add more tests for multipart request serialization

This commit is contained in:
Maybe Waffle 2022-01-13 16:51:42 +03:00
parent 5b4ed3faa9
commit ef33f9f66a

View file

@ -80,22 +80,119 @@ where
Ok(fut)
}
// https://github.com/teloxide/teloxide/issues/473
#[cfg(test)]
#[tokio::test]
async fn issue_473() {
mod tests {
use tokio::fs::File;
use super::to_form_ref;
use crate::{
payloads::{self, SendPhotoSetters},
types::{InputFile, MessageEntity, MessageEntityKind},
payloads::{self, setters::*},
types::{
InputFile, InputMedia, InputMediaAnimation, InputMediaAudio, InputMediaDocument,
InputMediaPhoto, InputMediaVideo, InputSticker, MessageEntity, MessageEntityKind,
ParseMode,
},
};
to_form_ref(
&payloads::SendPhoto::new(0, InputFile::file_id("0")).caption_entities([MessageEntity {
kind: MessageEntityKind::Url,
offset: 0,
length: 0,
}]),
)
.unwrap()
.await;
// https://github.com/teloxide/teloxide/issues/473
#[tokio::test]
async fn issue_473() {
to_form_ref(
&payloads::SendPhoto::new(0, InputFile::file_id("0")).caption_entities([
MessageEntity {
kind: MessageEntityKind::Url,
offset: 0,
length: 0,
},
]),
)
.unwrap()
.await;
}
#[tokio::test]
async fn test_send_media_group() {
const CAPTION: &str = "caption";
to_form_ref(&payloads::SendMediaGroup::new(
0,
[
InputMedia::Photo(
InputMediaPhoto::new(InputFile::file("./media/logo.png"))
.caption(CAPTION)
.parse_mode(ParseMode::MarkdownV2)
.caption_entities(entities()),
),
InputMedia::Video(
InputMediaVideo::new(InputFile::file_id("17")).supports_streaming(true),
),
InputMedia::Animation(
InputMediaAnimation::new(InputFile::read(
File::open("./media/example.gif").await.unwrap(),
))
.thumb(InputFile::read(
File::open("./media/logo.png").await.unwrap(),
))
.duration(17),
),
InputMedia::Audio(
InputMediaAudio::new(InputFile::url("https://example.com".parse().unwrap()))
.performer("a"),
),
InputMedia::Document(InputMediaDocument::new(InputFile::memory(
&b"Hello world!"[..],
))),
],
))
.unwrap()
.await;
}
#[tokio::test]
async fn test_add_sticker_to_set() {
to_form_ref(&payloads::AddStickerToSet::new(
0,
"name",
InputSticker::Png(InputFile::file("./media/logo.png")),
"✈️⚙️",
))
.unwrap()
.await;
}
#[tokio::test]
async fn test_send_animation() {
to_form_ref(
&payloads::SendAnimation::new(0, InputFile::file("./media/logo.png"))
.caption_entities(entities())
.thumb(InputFile::read(
File::open("./media/logo.png").await.unwrap(),
))
.allow_sending_without_reply(true),
)
.unwrap()
.await;
}
fn entities() -> impl Iterator<Item = MessageEntity> {
<_>::into_iter([
MessageEntity::new(MessageEntityKind::Url, 0, 0),
MessageEntity::new(MessageEntityKind::Pre { language: None }, 0, 0),
MessageEntity::new(
MessageEntityKind::Pre {
language: Some(String::new()),
},
0,
0,
),
MessageEntity::new(MessageEntityKind::Url, 0, 0),
MessageEntity::new(
MessageEntityKind::TextLink {
url: "https://example.com".parse().unwrap(),
},
0,
0,
),
])
}
}