aboutsummaryrefslogtreecommitdiff
path: root/src/tw/mod.rs
diff options
context:
space:
mode:
authorAndy Wortman <ixineeringeverywhere@gmail.com>2017-12-12 00:14:28 -0800
committerAndy Wortman <ixineeringeverywhere@gmail.com>2017-12-12 00:35:55 -0800
commitc3e8e0b3cac6e0c9a3a37b33ca88a028c3421622 (patch)
tree9e9b9703e685af928aab5a62fd832a45aaeb1859 /src/tw/mod.rs
parent402e45f1e1c173643e485f692984bf49ad278f23 (diff)
tweak tests for tweet retrieval, add display_id tests
tweet retrieval was brittle, would fail if UTC calendar day != Local TZ calendar day display_id tests expose the bug in tweet ids being Bare id rather than Today id due to timezone mismatch in looking up tweets
Diffstat (limited to 'src/tw/mod.rs')
-rw-r--r--src/tw/mod.rs48
1 files changed, 46 insertions, 2 deletions
diff --git a/src/tw/mod.rs b/src/tw/mod.rs
index 0a073c9..0e5ec37 100644
--- a/src/tw/mod.rs
+++ b/src/tw/mod.rs
@@ -230,8 +230,48 @@ mod tests {
}
#[test]
- fn test_tweet_retrieval() {
+ fn test_display_id() {
+ /*
+ * ... I think this test only works if Local is -0800 or further from UTC.
+ * I'm not even sure how to make any of this work in a TZ-invariant way.
+ */
+ // THIS NOW ONLY WORKS FOR DAYS OTHER THAN THE LAST OF A MONTH. FML
let today = Local::now();
+ let pst_1630_but_utc: DateTime<Utc> = DateTime::parse_from_rfc3339(
+ &format!("{:04}-{:02}-{:02}T00:30:00Z", today.year(), today.month(), today.day() + 1)).unwrap().with_timezone(&Utc);
+ let local_pst_1630: DateTime<Local> = DateTime::parse_from_rfc3339(
+ &format!("{:04}-{:02}-{:02}T16:30:00-08:00", today.year(), today.month(), today.day())).unwrap().with_timezone(&Local);
+ let tweet = Tweet {
+ id: "manual_tweet_1".to_owned(),
+ author_id: "you, dummy".to_owned(),
+ text: "test tweet please ignore".to_owned(),
+ created_at: "1234 not real".to_owned(),
+ recieved_at: pst_1630_but_utc,
+ urls: HashMap::new(),
+ quoted_tweet_id: None,
+ rt_tweet: None,
+ reply_to_tweet: None,
+ internal_id: 0
+ };
+
+ let mut tweeter = TwitterCache::new();
+
+ tweeter.number_and_insert_tweet(tweet.clone());
+
+ let retrieved = tweeter.retrieve_tweet(&TweetId::Bare(1));
+ assert_eq!(retrieved.is_some(), true);
+
+ let retrieved = tweeter.retrieve_tweet(&TweetId::Dated(format!("{:04}{:02}{:02}", today.year(), today.month(), today.day()), 0));
+ assert_eq!(retrieved.is_some(), true);
+
+ let display_id = tweeter.display_id_for_tweet(&retrieved.unwrap());
+
+ assert_eq!(display_id, TweetId::Today(0));
+ }
+
+ #[test]
+ fn test_tweet_retrieval() {
+ let today = Utc::now();
let yesterday = today - chrono::Duration::days(1);
let tweets = vec![
Tweet {
@@ -274,8 +314,12 @@ mod tests {
tweeter.retrieve_tweet(&TweetId::Today(0)).map(|x| x.id.to_owned()),
Some(tweets[1].clone()).map(|x| x.id)
);
+
+ let local_yesterday = yesterday.with_timezone(&Local);
+ let date = format!("{:04}{:02}{:02}", local_yesterday.year(), local_yesterday.month(), local_yesterday.day());
+
assert_eq!(
- tweeter.retrieve_tweet(&TweetId::Dated(format!("{:04}{:02}{:02}", yesterday.year(), yesterday.month(), yesterday.day()), 0)).map(|x| x.id.to_owned()),
+ tweeter.retrieve_tweet(&TweetId::Dated(date, 0)).map(|x| x.id.to_owned()),
Some(tweets[0].clone()).map(|x| x.id)
);
}