mirror of
https://framagit.org/veretcle/oolatoocs.git
synced 2025-07-21 04:51:17 +02:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
88edb1b2e1 | ||
![]() |
bf9d27df61 | ||
![]() |
496dde60d6 | ||
![]() |
567dfae7ab |
411
Cargo.lock
generated
411
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "oolatoocs"
|
name = "oolatoocs"
|
||||||
version = "2.0.1"
|
version = "2.0.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
@@ -464,7 +464,11 @@ pub fn transform_poll(p: &Poll) -> TweetPoll {
|
|||||||
let diff = poll_end_datetime.signed_duration_since(now);
|
let diff = poll_end_datetime.signed_duration_since(now);
|
||||||
|
|
||||||
TweetPoll {
|
TweetPoll {
|
||||||
options: p.options.iter().map(|i| i.title.clone()).collect(),
|
options: p
|
||||||
|
.options
|
||||||
|
.iter()
|
||||||
|
.map(|i| i.title.chars().take(25).collect::<String>())
|
||||||
|
.collect(),
|
||||||
duration_minutes: diff.num_minutes().try_into().unwrap(), // safe here, number is positive
|
duration_minutes: diff.num_minutes().try_into().unwrap(), // safe here, number is positive
|
||||||
// and can’t be over 21600
|
// and can’t be over 21600
|
||||||
}
|
}
|
||||||
@@ -512,3 +516,41 @@ pub async fn post_tweet(
|
|||||||
|
|
||||||
Ok(res.data.id.parse::<u64>().unwrap())
|
Ok(res.data.id.parse::<u64>().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use megalodon::entities::PollOption;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_transform_poll() {
|
||||||
|
let poll = Poll {
|
||||||
|
id: "youpi".to_string(),
|
||||||
|
expires_at: Some(Utc::now()),
|
||||||
|
expired: false,
|
||||||
|
multiple: false,
|
||||||
|
votes_count: 0,
|
||||||
|
voters_count: None,
|
||||||
|
options: vec![
|
||||||
|
PollOption {
|
||||||
|
title: "Je suis beaucoup trop long comme option, tronque-moi !".to_string(),
|
||||||
|
votes_count: None,
|
||||||
|
},
|
||||||
|
PollOption {
|
||||||
|
title: "nope".to_string(),
|
||||||
|
votes_count: None,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
voted: None,
|
||||||
|
emojis: vec![],
|
||||||
|
};
|
||||||
|
|
||||||
|
let tweet_poll_res = transform_poll(&poll);
|
||||||
|
let tweet_pool_expected = TweetPoll {
|
||||||
|
duration_minutes: 0,
|
||||||
|
options: vec!["Je suis beaucoup trop lon".to_string(), "nope".to_string()],
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(tweet_poll_res.options, tweet_pool_expected.options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user