-
Notifications
You must be signed in to change notification settings - Fork 4
/
queue_e2e.rs
49 lines (40 loc) · 1.49 KB
/
queue_e2e.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use actix_web::{
test::{self, read_body_json},
web::Data,
};
mod helpers;
use helpers::build_test_app_state;
use once_cell::sync::Lazy;
use pickup::{app_state::AppState, build_app};
use serde_json::{self, json};
// Make a shared app state for use in all tests, because Sled won't let us open multiple instances of the DB file
// from differet threads.
static APP_STATE: Lazy<Data<AppState>> = Lazy::new(build_test_app_state);
#[actix_web::test]
async fn test_not_found() {
let app = test::init_service(build_app((*APP_STATE).clone())).await;
let req = test::TestRequest::post()
.uri("/queue/add")
.set_json(json!({"category": "DoesNotExist"}))
.to_request();
let resp = test::call_service(&app, req).await;
assert_eq!(resp.status(), actix_web::http::StatusCode::NOT_FOUND);
let resp_json: serde_json::Value = read_body_json(resp).await;
assert_eq!(
resp_json,
json!({ "error": "No matching music found in the collection" })
);
}
#[actix_web::test]
async fn test_add_artist() {
let app = test::init_service(build_app((*APP_STATE).clone())).await;
let req = test::TestRequest::post()
.uri("/queue/add")
.set_json(json!({
"category": "Music",
}))
.to_request();
let resp: serde_json::Value = test::call_and_read_body_json(&app, req).await;
assert_eq!(resp.get("position").unwrap().as_u64().unwrap(), 0);
assert_eq!(resp.get("tracks").unwrap().as_array().unwrap().len(), 5);
}