mirror of
https://github.com/agersant/polaris
synced 2025-03-04 07:07:18 +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]
|
#[test]
|
||||||
fn search() {
|
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]
|
#[test]
|
||||||
|
|
10
src/index.rs
10
src/index.rs
|
@ -90,13 +90,13 @@ pub fn init(db: Arc<DB>) -> Arc<CommandSender> {
|
||||||
command_sender
|
command_sender
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Queryable, QueryableByName, Serialize)]
|
#[derive(Debug, PartialEq, Queryable, QueryableByName, Serialize, Deserialize)]
|
||||||
#[table_name = "songs"]
|
#[table_name = "songs"]
|
||||||
pub struct Song {
|
pub struct Song {
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip_serializing, skip_deserializing)]
|
||||||
id: i32,
|
id: i32,
|
||||||
pub path: String,
|
pub path: String,
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip_serializing, skip_deserializing)]
|
||||||
pub parent: String,
|
pub parent: String,
|
||||||
pub track_number: Option<i32>,
|
pub track_number: Option<i32>,
|
||||||
pub disc_number: Option<i32>,
|
pub disc_number: Option<i32>,
|
||||||
|
@ -109,7 +109,7 @@ pub struct Song {
|
||||||
pub duration: Option<i32>,
|
pub duration: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Queryable, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Queryable, Serialize, Deserialize)]
|
||||||
pub struct Directory {
|
pub struct Directory {
|
||||||
#[serde(skip_serializing, skip_deserializing)]
|
#[serde(skip_serializing, skip_deserializing)]
|
||||||
id: i32,
|
id: i32,
|
||||||
|
@ -123,7 +123,7 @@ pub struct Directory {
|
||||||
pub date_added: i32,
|
pub date_added: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
pub enum CollectionFile {
|
pub enum CollectionFile {
|
||||||
Directory(Directory),
|
Directory(Directory),
|
||||||
Song(Song),
|
Song(Song),
|
||||||
|
|
Loading…
Add table
Reference in a new issue