mirror of
https://github.com/agersant/polaris
synced 2024-12-04 18:49:10 +00:00
Added unit tests for playlists API
This commit is contained in:
parent
43538853a4
commit
0185634071
2 changed files with 64 additions and 7 deletions
12
src/api.rs
12
src/api.rs
|
@ -332,9 +332,9 @@ fn serve(
|
||||||
Ok(serve::RangeResponder::new(file))
|
Ok(serve::RangeResponder::new(file))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
struct ListPlaylistsEntry {
|
pub struct ListPlaylistsEntry {
|
||||||
name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/playlists")]
|
#[get("/playlists")]
|
||||||
|
@ -351,9 +351,9 @@ fn list_playlists(
|
||||||
Ok(Json(playlists))
|
Ok(Json(playlists))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct SavePlaylistInput {
|
pub struct SavePlaylistInput {
|
||||||
tracks: Vec<String>,
|
pub tracks: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put("/playlist/<name>", data = "<playlist>")]
|
#[put("/playlist/<name>", data = "<playlist>")]
|
||||||
|
|
|
@ -458,7 +458,64 @@ fn serve() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn playlists() {
|
fn playlists() {
|
||||||
// TODO
|
let env = get_test_environment("api_playlists.sqlite");
|
||||||
|
let client = &env.client;
|
||||||
|
complete_initial_setup(client);
|
||||||
|
do_auth(client);
|
||||||
|
env.update_index();
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut response = client.get("/api/playlists").dispatch();
|
||||||
|
assert_eq!(response.status(), Status::Ok);
|
||||||
|
let response_body = response.body_string().unwrap();
|
||||||
|
let response_json: Vec<api::ListPlaylistsEntry> = serde_json::from_str(&response_body).unwrap();
|
||||||
|
assert_eq!(response_json.len(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let songs: Vec<index::Song>;
|
||||||
|
{
|
||||||
|
let mut response = client.get("/api/flatten").dispatch();
|
||||||
|
let response_body = response.body_string().unwrap();
|
||||||
|
songs = serde_json::from_str(&response_body).unwrap();
|
||||||
|
}
|
||||||
|
let my_playlist = api::SavePlaylistInput{
|
||||||
|
tracks: songs[2..6].into_iter().map(|s| s.path.clone()).collect(),
|
||||||
|
};
|
||||||
|
let response = client.put("/api/playlist/my_playlist")
|
||||||
|
.body(serde_json::to_string(&my_playlist).unwrap())
|
||||||
|
.dispatch();
|
||||||
|
assert_eq!(response.status(), Status::Ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut response = client.get("/api/playlists").dispatch();
|
||||||
|
assert_eq!(response.status(), Status::Ok);
|
||||||
|
let response_body = response.body_string().unwrap();
|
||||||
|
let response_json: Vec<api::ListPlaylistsEntry> = serde_json::from_str(&response_body).unwrap();
|
||||||
|
assert_eq!(response_json, vec![api::ListPlaylistsEntry{ name: "my_playlist".into() }]);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut response = client.get("/api/playlist/my_playlist").dispatch();
|
||||||
|
assert_eq!(response.status(), Status::Ok);
|
||||||
|
let response_body = response.body_string().unwrap();
|
||||||
|
let response_json: Vec<index::Song> = serde_json::from_str(&response_body).unwrap();
|
||||||
|
assert_eq!(response_json.len(), 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let response = client.delete("/api/playlist/my_playlist").dispatch();
|
||||||
|
assert_eq!(response.status(), Status::Ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut response = client.get("/api/playlists").dispatch();
|
||||||
|
assert_eq!(response.status(), Status::Ok);
|
||||||
|
let response_body = response.body_string().unwrap();
|
||||||
|
let response_json: Vec<api::ListPlaylistsEntry> = serde_json::from_str(&response_body).unwrap();
|
||||||
|
assert_eq!(response_json.len(), 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue