Test Expiring::from_response

This commit is contained in:
Curtis McEnroe 2015-12-24 00:22:12 -05:00
parent 02a764720b
commit 552507478f
1 changed files with 31 additions and 0 deletions

View File

@ -53,3 +53,34 @@ impl FromResponse for Expiring {
})
}
}
#[cfg(test)]
mod tests {
use chrono::{UTC, Duration};
use rustc_serialize::json::Json;
use client::response::FromResponse;
use super::Expiring;
#[test]
fn from_response() {
let json = Json::from_str(r#"{"refresh_token":"aaaaaaaa","expires_in":3600}"#).unwrap();
let expiring = Expiring::from_response(&json).unwrap();
assert_eq!("aaaaaaaa", expiring.refresh_token);
assert!(expiring.expires > UTC::now());
assert!(expiring.expires <= UTC::now() + Duration::seconds(3600));
}
#[test]
fn from_response_inherit() {
let json = Json::from_str(r#"{"expires_in":3600}"#).unwrap();
let prev = Expiring {
refresh_token: String::from("aaaaaaaa"),
expires: UTC::now(),
};
let expiring = Expiring::from_response_inherit(&json, &prev).unwrap();
assert_eq!("aaaaaaaa", expiring.refresh_token);
assert!(expiring.expires > UTC::now());
assert!(expiring.expires <= UTC::now() + Duration::seconds(3600));
}
}