Skip to content

Commit

Permalink
Add test scenarios (#160)
Browse files Browse the repository at this point in the history
Adds test scenarios for the `/price` endpoint.

Drive-by:
- Fixes the new ratings endpoint.

Signed-off-by: Rémy Greinhofer <[email protected]>
  • Loading branch information
rgreinho authored Nov 26, 2024
1 parent 441ad46 commit 450d41b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lambdas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ name = "lambdas"
path = "src/lib.rs"

[[bin]]
name = "server"
name = "axumed"
path = "src/main.rs"

[[bin]]
Expand Down
24 changes: 13 additions & 11 deletions lambdas/src/core/resource/ratings/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use uuid::Uuid;

use super::BNAComponent;

#[derive(FromQueryResult, Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Debug, FromQueryResult, Clone, PartialEq, Serialize, Deserialize)]
pub struct Bna {
// BNA Summary
bna_id: Uuid,
id: Uuid,
city_id: Uuid,
score: f64,
version: String,
Expand Down Expand Up @@ -55,29 +55,29 @@ pub struct Bna {
transit: Option<f64>,
}

#[derive(FromQueryResult, Deserialize, Serialize)]
#[derive(Debug, FromQueryResult, Deserialize, Serialize)]
pub struct Summary {
bna_id: Uuid,
id: Uuid,
city_id: Uuid,
score: f64,
version: String,
}

#[derive(FromQueryResult, Deserialize, Serialize)]
#[derive(Debug, FromQueryResult, Deserialize, Serialize)]
pub struct Infrastructure {
low_stress_miles: Option<f64>,
high_stress_miles: Option<f64>,
}

#[derive(FromQueryResult, Deserialize, Serialize)]
#[derive(Debug, FromQueryResult, Deserialize, Serialize)]
pub struct Recreation {
community_centers: Option<f64>,
parks: Option<f64>,
recreation_trails: Option<f64>,
recreation_score: Option<f64>,
}

#[derive(FromQueryResult, Deserialize, Serialize)]
#[derive(Debug, FromQueryResult, Deserialize, Serialize)]
pub struct Opportunity {
employment: Option<f64>,
higher_education: Option<f64>,
Expand All @@ -86,7 +86,7 @@ pub struct Opportunity {
technical_vocational_college: Option<f64>,
}

#[derive(FromQueryResult, Deserialize, Serialize)]
#[derive(Debug, FromQueryResult, Deserialize, Serialize)]
pub struct CoreServices {
dentists: Option<f64>,
doctors: Option<f64>,
Expand All @@ -97,21 +97,22 @@ pub struct CoreServices {
social_services: Option<f64>,
}

#[derive(FromQueryResult, Deserialize, Serialize)]
#[derive(Debug, FromQueryResult, Deserialize, Serialize)]
pub struct People {
people: Option<f64>,
}

#[derive(FromQueryResult, Deserialize, Serialize)]
#[derive(Debug, FromQueryResult, Deserialize, Serialize)]
pub struct Retail {
retail: Option<f64>,
}

#[derive(FromQueryResult, Deserialize, Serialize)]
#[derive(Debug, FromQueryResult, Deserialize, Serialize)]
pub struct Transit {
transit: Option<f64>,
}

#[derive(Debug)]
pub enum BNAComponentValue {
All(Bna),
Summary(Summary),
Expand Down Expand Up @@ -146,6 +147,7 @@ pub async fn fetch_ratings_summary_with_parts(
) -> Result<Option<BNAComponentValue>, sea_orm::DbErr> {
let select = summary::Entity::find_by_id(rating_id);
let component = component.unwrap_or(BNAComponent::All);
dbg!(&component);
let res = match component {
BNAComponent::All => select
.clone()
Expand Down
5 changes: 5 additions & 0 deletions lambdas/src/core/resource/ratings/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use axum::{
use effortless::api::PaginationParameters;
use entity::wrappers::bna_pipeline::{BNAPipelinePatch, BNAPipelinePost};
use serde_json::{json, Value};
use tracing::debug;
use uuid::Uuid;

pub fn routes() -> Router {
Expand Down Expand Up @@ -53,6 +54,10 @@ async fn get_rating(

get_rating_adaptor(rating_id, component, ctx)
.await
.map_err(|e| {
debug!("{e}");
e
})
.map(|v| Json(json!(v)))
}

Expand Down
11 changes: 10 additions & 1 deletion lambdas/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ async fn main() -> Result<(), Error> {
// i.e with: `GET /test-stage/todo/id/123` without: `GET /todo/id/123`
set_var("AWS_LAMBDA_HTTP_IGNORE_STAGE_IN_PATH", "true");

// Check for user-defined log level.
let log_level = match env::var("BNA_API_LOG_LEVEL") {
Ok(v) => match v.to_ascii_lowercase().as_str() {
"debug" => tracing::Level::DEBUG,
_ => tracing::Level::INFO,
},
Err(_) => tracing::Level::INFO,
};

// required to enable CloudWatch error logging by the runtime
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.with_max_level(log_level)
// disable printing the name of the module in every log line.
.with_target(false)
// disabling time is handy because CloudWatch will add the ingestion time.
Expand Down
14 changes: 14 additions & 0 deletions lambdas/tests/endpoints/pricing.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Queries the first page of the fargate prices.
GET {{host}}/prices/fargate

HTTP 200
[Asserts]
jsonpath "$" count > 0
[Captures]
price_id: jsonpath "$.[0].id"


# Queries a specific fargate price.
GET {{host}}/prices/fargate/{{price_id}}

HTTP 200

0 comments on commit 450d41b

Please sign in to comment.