mirror of
https://github.com/agersant/polaris
synced 2024-12-12 06:12:56 +00:00
Added unit test for /api/search
This commit is contained in:
parent
3f5a84ba8a
commit
cc17c6db97
2 changed files with 20 additions and 6 deletions
|
@ -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<index::CollectionFile> = 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]
|
||||
|
|
10
src/index.rs
10
src/index.rs
|
@ -90,13 +90,13 @@ pub fn init(db: Arc<DB>) -> Arc<CommandSender> {
|
|||
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<i32>,
|
||||
pub disc_number: Option<i32>,
|
||||
|
@ -109,7 +109,7 @@ pub struct Song {
|
|||
pub duration: Option<i32>,
|
||||
}
|
||||
|
||||
#[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),
|
||||
|
|
Loading…
Reference in a new issue