Add some more tests

master
Paul Woolcock 6 years ago
parent e57c400c46
commit b4a43dc783
  1. 121
      src/apps.rs
  2. 9
      src/registration.rs
  3. 2
      src/status_builder.rs

@ -5,7 +5,7 @@ use try_from::TryInto;
use errors::{Error, Result}; use errors::{Error, Result};
/// Represents an application that can be registered with a mastodon instance /// Represents an application that can be registered with a mastodon instance
#[derive(Debug, Default, Serialize)] #[derive(Clone, Debug, Default, Serialize, PartialEq)]
pub struct App { pub struct App {
client_name: String, client_name: String,
redirect_uris: String, redirect_uris: String,
@ -167,3 +167,122 @@ impl Default for Scopes {
Scopes::Read Scopes::Read
} }
} }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_app_builder() {
let builder = App::builder();
assert_eq!(builder, AppBuilder::new());
}
#[test]
fn test_app_scopes() {
let mut builder = App::builder();
builder.client_name("test")
.scopes(Scopes::All);
let app = builder.build().expect("Couldn't build App");
assert_eq!(app.scopes(), Scopes::All);
}
#[test]
fn test_app_builder_all_methods() {
let mut builder = AppBuilder::new();
builder.client_name("foo-test");
builder.redirect_uris("http://example.com");
builder.scopes(Scopes::ReadWrite);
builder.website("https://example.com");
let app = builder.build().expect("Couldn't build App");
assert_eq!(app,
App {
client_name: "foo-test".to_string(),
redirect_uris: "http://example.com".to_string(),
scopes: Scopes::ReadWrite,
website: Some("https://example.com".to_string()),
});
}
#[test]
#[should_panic]
fn test_app_builder_build_fails_if_no_client_name_1() {
App::builder().build().expect("no client-name");
}
#[test]
#[should_panic]
fn test_app_builder_build_fails_if_no_client_name_2() {
let mut builder = App::builder();
builder.website("https://example.com")
.redirect_uris("https://example.com")
.scopes(Scopes::All);
builder.build().expect("no client-name");
}
#[test]
fn test_app_try_into_app() {
let app = App {
client_name: "foo-test".to_string(),
redirect_uris: "http://example.com".to_string(),
scopes: Scopes::All,
website: None,
};
let expected = app.clone();
let result = app.try_into().expect("Couldn't make App into App");
assert_eq!(expected, result);
}
#[test]
fn test_app_builder_try_into_app() {
let mut builder = App::builder();
builder.client_name("foo-test")
.redirect_uris("http://example.com")
.scopes(Scopes::All);
let expected = App {
client_name: "foo-test".to_string(),
redirect_uris: "http://example.com".to_string(),
scopes: Scopes::All,
website: None,
};
let result = builder.try_into().expect("Couldn't make AppBuilder into App");
assert_eq!(expected, result);
}
#[test]
fn test_scopes_display() {
let values = [
Scopes::All,
Scopes::Follow,
Scopes::Read,
Scopes::ReadFollow,
Scopes::ReadWrite,
Scopes::Write,
Scopes::WriteFollow,
];
let expecteds = [
"read%20write%20follow".to_string(),
"follow".to_string(),
"read".to_string(),
"read%20follow".to_string(),
"read%20write".to_string(),
"write".to_string(),
"write%20follow".to_string(),
];
let tests = values.into_iter().zip(expecteds.into_iter());
for (value, expected) in tests {
let result = value.to_string();
assert_eq!(&result, expected);
}
}
#[test]
fn test_scopes_default() {
let default: Scopes = Default::default();
assert_eq!(default, Scopes::Read);
}
}

@ -236,6 +236,15 @@ mod tests {
let r = Registration::new("https://example.com"); let r = Registration::new("https://example.com");
assert_eq!(r.base, "https://example.com".to_string()); assert_eq!(r.base, "https://example.com".to_string());
assert_eq!(r.app_builder, AppBuilder::new()); assert_eq!(r.app_builder, AppBuilder::new());
assert_eq!(r.http_sender, HttpSender);
}
#[test]
fn test_registration_with_sender() {
let r = Registration::with_sender("https://example.com", HttpSender);
assert_eq!(r.base, "https://example.com".to_string());
assert_eq!(r.app_builder, AppBuilder::new());
assert_eq!(r.http_sender, HttpSender);
} }
#[test] #[test]

@ -77,7 +77,7 @@ mod tests {
#[test] #[test]
fn test_default_visibility() { fn test_default_visibility() {
let v = Visibility::default(); let v: Visibility = Default::default();
assert_eq!(v, Visibility::Public); assert_eq!(v, Visibility::Public);
} }
} }

Loading…
Cancel
Save