aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/apitests.rs34
1 files changed, 32 insertions, 2 deletions
diff --git a/tests/apitests.rs b/tests/apitests.rs
index efcbfd2..4a74810 100644
--- a/tests/apitests.rs
+++ b/tests/apitests.rs
@@ -18,8 +18,10 @@
use ramaskrik;
use ramaskrik::models::{
+ self,
film::{ Film, NewFilm },
- room::Room
+ room::Room,
+ screening,
};
use lazy_static::lazy_static;
@@ -77,7 +79,7 @@ fn load_default_rooms(db: &ramaskrik::db::Connection) {
}
fn load_fixtures(db: &ramaskrik::db::Connection) {
- diesel::dsl::sql_query("TRUNCATE TABLE rooms, films").execute(&**db).unwrap();
+ diesel::dsl::sql_query("TRUNCATE TABLE rooms, screenings, films").execute(&**db).unwrap();
load_default_rooms(&db);
load_default_films(&db);
}
@@ -119,3 +121,31 @@ fn getting_films_from_api() {
assert!(film_names.contains(&"Skuld"));
});
}
+
+#[test]
+fn getting_screenings_from_api() {
+ server_with_db(|server, db| {
+ let r = models::room::by_name("Main room", &db).unwrap();
+ let f = models::film::by_title("Hellraiser", &db).unwrap();
+ screening::create(&r, &f,
+ chrono::NaiveDate::from_ymd(2019, 10, 21),
+ chrono::NaiveTime::from_hms(18, 00, 00),
+ chrono::NaiveTime::from_hms(19, 34, 00),
+ &db).unwrap();
+
+ use ramaskrik::schema::screenings::dsl::*;
+
+ let client = rocket::local::Client::new(server).unwrap();
+ let mut response = client.get("/screenings").dispatch();
+ assert_eq!(response.content_type(), Some(ContentType::JSON));
+
+ let fetched_screenings: Vec<(screening::Screening, Option<Film>, Option<Room>)> =
+ serde_json::from_str(&response.body_string().unwrap()).unwrap();
+
+ assert_eq!(fetched_screenings.len(), 1);
+
+ let (scr, ff, rr) = &fetched_screenings[0];
+ assert_eq!(ff.as_ref().unwrap().title, "Hellraiser");
+ assert_eq!(rr.as_ref().unwrap().name, "Main room");
+ });
+}