aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2019-04-08 12:31:26 +0200
committerHarald Eilertsen <haraldei@anduin.net>2019-04-08 12:31:26 +0200
commita7c734d39512385177426bcb2131726906ce2fff (patch)
tree9a42886afebda28ce712ea88f2250dd8b5e79134 /tests
parent9c8b8a254a5223cd359df150279f78e644b58abb (diff)
downloadramaskrik-social-a7c734d39512385177426bcb2131726906ce2fff.tar.gz
ramaskrik-social-a7c734d39512385177426bcb2131726906ce2fff.tar.bz2
ramaskrik-social-a7c734d39512385177426bcb2131726906ce2fff.zip
Add endpoint to fetch screenings from the database.
Not entirely happy about the way this turned out for now. A more ergonomic return type from the models::screenings::get_all() function will be investigated.
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");
+ });
+}