mirror of
https://framagit.org/veretcle/oolatoocs.git
synced 2025-07-20 20:41:17 +02:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f7e2aafa7b | ||
![]() |
6e9bb6b42c | ||
![]() |
88edb1b2e1 | ||
![]() |
bf9d27df61 | ||
![]() |
496dde60d6 | ||
![]() |
567dfae7ab |
808
Cargo.lock
generated
808
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,12 @@
|
||||
[package]
|
||||
name = "oolatoocs"
|
||||
version = "2.0.1"
|
||||
version = "2.0.4"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4.31"
|
||||
chrono = "^0.4"
|
||||
clap = "^4"
|
||||
env_logger = "^0.10"
|
||||
futures = "^0.3"
|
||||
|
@@ -464,7 +464,11 @@ pub fn transform_poll(p: &Poll) -> TweetPoll {
|
||||
let diff = poll_end_datetime.signed_duration_since(now);
|
||||
|
||||
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
|
||||
// and can’t be over 21600
|
||||
}
|
||||
@@ -512,3 +516,41 @@ pub async fn post_tweet(
|
||||
|
||||
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