From cc17c6db97fabcb18d728cdd50140fd5c9f20a90 Mon Sep 17 00:00:00 2001 From: Antoine Gersant Date: Mon, 12 Nov 2018 20:20:56 -0800 Subject: [PATCH] Added unit test for /api/search --- src/api_tests.rs | 16 +++++++++++++++- src/index.rs | 10 +++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/api_tests.rs b/src/api_tests.rs index 2c08edf..8f46cc4 100644 --- a/src/api_tests.rs +++ b/src/api_tests.rs @@ -359,7 +359,21 @@ fn recent() { #[test] fn search() { - // TODO + let env = get_test_environment("api_search.sqlite"); + let client = &env.client; + complete_initial_setup(client); + do_auth(client); + env.update_index(); + + let mut response = client.get("/api/search/door").dispatch(); + assert_eq!(response.status(), Status::Ok); + let response_body = response.body_string().unwrap(); + let response_json: Vec = serde_json::from_str(&response_body).unwrap(); + assert_eq!(response_json.len(), 1); + match response_json[0] { + index::CollectionFile::Song(ref s) => assert_eq!(s.title, Some("Beyond The Door".into())), + _ => panic!() + } } #[test] diff --git a/src/index.rs b/src/index.rs index 5651962..8334136 100644 --- a/src/index.rs +++ b/src/index.rs @@ -90,13 +90,13 @@ pub fn init(db: Arc) -> Arc { command_sender } -#[derive(Debug, Queryable, QueryableByName, Serialize)] +#[derive(Debug, PartialEq, Queryable, QueryableByName, Serialize, Deserialize)] #[table_name = "songs"] pub struct Song { - #[serde(skip_serializing)] + #[serde(skip_serializing, skip_deserializing)] id: i32, pub path: String, - #[serde(skip_serializing)] + #[serde(skip_serializing, skip_deserializing)] pub parent: String, pub track_number: Option, pub disc_number: Option, @@ -109,7 +109,7 @@ pub struct Song { pub duration: Option, } -#[derive(Debug, Queryable, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Queryable, Serialize, Deserialize)] pub struct Directory { #[serde(skip_serializing, skip_deserializing)] id: i32, @@ -123,7 +123,7 @@ pub struct Directory { pub date_added: i32, } -#[derive(Debug, Serialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] pub enum CollectionFile { Directory(Directory), Song(Song),