Skip to content

Commit

Permalink
Use reqwest in web API tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flosse committed Sep 17, 2023
1 parent 74ea69f commit 493dfdc
Show file tree
Hide file tree
Showing 8 changed files with 298 additions and 83 deletions.
147 changes: 147 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ofdb-webserver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ uuid = { version = "1.4.1", features = ["v4"] }

[dev-dependencies]
ofdb-entities = { version = "0.12.5", features = ["url", "builders"] }
reqwest = { version = "0.11.20", features = ["rustls", "json"] }
tokio = { version = "1.32.0", features = ["rt-multi-thread"] }

[build-dependencies]
walkdir = "2.4.0"
Expand Down
18 changes: 9 additions & 9 deletions ofdb-webserver/src/web/api/events/tests/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn without_creator_email() {
// But in the future we might allow anonymous event creation:
//
// assert_eq!(response.status(), HttpStatus::Ok);
// test_json(&response);
// assert_rocket_response_has_json_content_type(&response);
// let body_str = response.into_string().unwrap();
// let eid = db.get().unwrap().all_events_chronologically().unwrap()[0].id.
// clone(); assert_eq!(body_str, format!("\"{}\"", eid));
Expand All @@ -39,7 +39,7 @@ fn without_api_token_but_with_creator_email() {
// But in the future we might allow anonymous event creation:
//
// assert_eq!(response.status(), HttpStatus::Ok);
// test_json(&response);
// assert_rocket_response_has_json_content_type(&response);
// let body_str = response.into_string().unwrap();
// let ev = db.get().unwrap().all_events_chronologically().unwrap()[0].
// clone(); let eid = ev.id.clone();
Expand All @@ -50,7 +50,7 @@ fn without_api_token_but_with_creator_email() {
// .header(ContentType::JSON);
// let response = req.dispatch();
// assert_eq!(response.status(), HttpStatus::Ok);
// test_json(&response);
// assert_rocket_response_has_json_content_type(&response);
// let body_str = response.into_string().unwrap();
// assert_eq!(
// body_str,
Expand Down Expand Up @@ -83,7 +83,7 @@ mod with_api_token {
.body(r#"{"title":"x","start":4132508400,"created_by":"[email protected]"}"#)
.dispatch();
assert_eq!(res.status(), HttpStatus::Ok);
test_json(&res);
assert_rocket_response_has_json_content_type(&res);
let body_str = res.into_string().unwrap();
let ev = db.shared().unwrap().all_events_chronologically().unwrap()[0].clone();
let eid = ev.id.clone();
Expand All @@ -110,7 +110,7 @@ mod with_api_token {
.body(r#"{"title":"x","start":4132508400,"created_by":"[email protected]"}"#)
.dispatch();
assert_eq!(res.status(), HttpStatus::Ok);
test_json(&res);
assert_rocket_response_has_json_content_type(&res);
let body_str = res.into_string().unwrap();
let ev = db.shared().unwrap().all_events_chronologically().unwrap()[0].clone();
let eid = ev.id.clone();
Expand Down Expand Up @@ -163,7 +163,7 @@ mod with_api_token {
.body(r#"{"title":"x","start":4132508400,"created_by":"[email protected]","email":"","homepage":"","description":"","registration":""}"#)
.dispatch();
assert_eq!(res.status(), HttpStatus::Ok);
test_json(&res);
assert_rocket_response_has_json_content_type(&res);
let ev = db.shared().unwrap().all_events_chronologically().unwrap()[0].clone();
assert!(ev.contact.is_none());
assert!(ev.homepage.is_none());
Expand All @@ -189,7 +189,7 @@ mod with_api_token {
.body(r#"{"title":"title","description":"","start":-4132508400,"end":-4132508399,"created_by":"[email protected]"}"#)
.dispatch();
assert_eq!(res.status(), HttpStatus::Ok);
test_json(&res);
assert_rocket_response_has_json_content_type(&res);
let ev = db.shared().unwrap().all_events_chronologically().unwrap()[0].clone();
assert_eq!(-4132508400, ev.start.as_secs());
assert_eq!(Some(-4132508399), ev.end.map(Timestamp::as_secs));
Expand All @@ -214,7 +214,7 @@ mod with_api_token {
.body(r#"{"title":"x","start":4132508400,"created_by":"[email protected]","registration":"telephone","telephone":"12345"}"#)
.dispatch();
assert_eq!(res.status(), HttpStatus::Ok);
test_json(&res);
assert_rocket_response_has_json_content_type(&res);
let ev = db.shared().unwrap().all_events_chronologically().unwrap()[0].clone();
assert_eq!(ev.registration.unwrap(), RegistrationType::Phone);
}
Expand Down Expand Up @@ -282,7 +282,7 @@ mod with_api_token {
.body(r#"{"title":"x","start":4132508400,"created_by":"[email protected]","tags":["", " "," tag","tag ","two tags", "tag"]}"#)
.dispatch();
assert_eq!(res.status(), HttpStatus::Ok);
test_json(&res);
assert_rocket_response_has_json_content_type(&res);
let ev = db.shared().unwrap().all_events_chronologically().unwrap()[0].clone();
let mut actual_tags = ev.tags;
actual_tags.sort_unstable();
Expand Down
Loading

0 comments on commit 493dfdc

Please sign in to comment.