95 lines
2.7 KiB
Rust
95 lines
2.7 KiB
Rust
|
use lakewatch::v1::ramps::domain::{Ramp, RampStatus};
|
||
|
use sqlx::PgPool;
|
||
|
|
||
|
#[sqlx::test]
|
||
|
async fn ramps_returns_200_ok(pool: PgPool) {
|
||
|
let app = crate::helpers::TestApp::spawn(&pool).await;
|
||
|
let client = reqwest::Client::new();
|
||
|
let ramps_url = app.url("/v1/ramps");
|
||
|
println!("{}", ramps_url);
|
||
|
let response = client
|
||
|
.get(ramps_url)
|
||
|
.send()
|
||
|
.await
|
||
|
.expect("Failed to execute request");
|
||
|
assert!(response.status().is_success());
|
||
|
}
|
||
|
|
||
|
#[sqlx::test]
|
||
|
async fn ramps_returns_expected_ramps(pool: PgPool) {
|
||
|
let app = crate::helpers::TestApp::spawn(&pool).await;
|
||
|
let mock_ramps = [
|
||
|
Ramp {
|
||
|
number: 1,
|
||
|
name: "Canyon Lake Village".to_string(),
|
||
|
operator: "Comal County".to_string(),
|
||
|
address: "569 Skyline Dr, Canyon Lake, TX 78134".to_string(),
|
||
|
status: RampStatus::Open,
|
||
|
last_updated: chrono::NaiveDate::from_ymd_opt(2024, 8, 2).unwrap(),
|
||
|
operating_times: Some("8am - Sunset".to_string()),
|
||
|
},
|
||
|
Ramp {
|
||
|
number: 2,
|
||
|
name: "Canyon Lake Village West".to_string(),
|
||
|
operator: "Comal County".to_string(),
|
||
|
address: "2410 Colleen Dr, Canyon Lake, TX 78133".to_string(),
|
||
|
status: RampStatus::Closed,
|
||
|
last_updated: chrono::NaiveDate::from_ymd_opt(2024, 8, 2).unwrap(),
|
||
|
operating_times: Some("8am - Sunset".to_string()),
|
||
|
},
|
||
|
];
|
||
|
for ramp in &mock_ramps[..] {
|
||
|
sqlx::query!(
|
||
|
r#"INSERT INTO rampdata(
|
||
|
number,
|
||
|
name,
|
||
|
operator,
|
||
|
address,
|
||
|
status,
|
||
|
last_updated,
|
||
|
operating_times
|
||
|
) VALUES (
|
||
|
$1,
|
||
|
$2,
|
||
|
$3,
|
||
|
$4,
|
||
|
$5,
|
||
|
$6,
|
||
|
$7
|
||
|
);"#,
|
||
|
ramp.number,
|
||
|
ramp.name,
|
||
|
ramp.operator,
|
||
|
ramp.address,
|
||
|
String::from(ramp.status),
|
||
|
ramp.last_updated,
|
||
|
ramp.operating_times
|
||
|
)
|
||
|
.execute(&pool)
|
||
|
.await
|
||
|
.expect("Failed to insert mock data!");
|
||
|
}
|
||
|
let client = reqwest::Client::new();
|
||
|
let ramps_url = app.url("/v1/ramps");
|
||
|
println!("{}", ramps_url);
|
||
|
let response = client
|
||
|
.get(ramps_url)
|
||
|
.send()
|
||
|
.await
|
||
|
.expect("Failed to execute request");
|
||
|
assert!(response.status().is_success());
|
||
|
assert_eq!(
|
||
|
response.headers().get("content-type").unwrap(),
|
||
|
"application/json"
|
||
|
);
|
||
|
let ramps: Vec<Ramp> = serde_json::from_str(
|
||
|
&response
|
||
|
.text()
|
||
|
.await
|
||
|
.expect("Failed to ready body of response!"),
|
||
|
)
|
||
|
.expect("Failed to parse body into json!");
|
||
|
|
||
|
assert_eq!(ramps[0], mock_ramps[0]);
|
||
|
}
|