From 69433dc729faf290ff72b0533d15167450ee2331 Mon Sep 17 00:00:00 2001 From: Rohit Sachdeva Date: Mon, 16 Sep 2024 18:05:00 -0500 Subject: [PATCH] Add AWS deployment test and refactor portfolio functions Added a new test target `test-with-aws-deploy-only` in `justfile` for AWS features and uncommented the `test_valid_two_banks_json_request` test with AWS deployment. Refactored function names in `engine.rs` from `bank` to `portfolio` for better clarity and consistency. --- drive-deposits-cal-types/src/math/engine.rs | 29 ++++---- drive-deposits-check-cmd/Cargo.toml | 3 + .../tests/test_delta_calculator_cli.rs | 73 ++++++++++--------- justfile | 3 + 4 files changed, 62 insertions(+), 46 deletions(-) diff --git a/drive-deposits-cal-types/src/math/engine.rs b/drive-deposits-cal-types/src/math/engine.rs index bf7723c..e7953de 100644 --- a/drive-deposits-cal-types/src/math/engine.rs +++ b/drive-deposits-cal-types/src/math/engine.rs @@ -142,17 +142,17 @@ async fn build_from_new_banks( Ok(banks) } -async fn build_from_bank_request( - bank_req: PortfolioRequest, +async fn build_from_portfolio_request( + portfolio_req: PortfolioRequest, eb: Arc>, ) -> Result { let uuid = Uuid::new_v4(); - info!("build_from_bank_request uuid created: {:?}", uuid); + info!("build_from_portfolio_request uuid created: {:?}", uuid); let created_at = chrono::Utc::now(); let created_at_iso8061 = created_at.to_rfc3339_opts(SecondsFormat::Micros, true); let eb_clone = eb.clone(); - let new_delta = Arc::new(bank_req.new_delta); - let banks = build_from_new_banks(bank_req.new_banks, new_delta.clone(), eb).await?; + let new_delta = Arc::new(portfolio_req.new_delta); + let banks = build_from_new_banks(portfolio_req.new_banks, new_delta.clone(), eb).await?; let outcome = build_outcome_from_banks(&banks, new_delta.clone().as_ref()); let bank_response = PortfolioResponse { @@ -181,20 +181,23 @@ async fn build_from_bank_request( Ok(bank_response) } -#[instrument(skip(bank_req, eb))] +#[instrument(skip(portfolio_req, eb))] pub async fn calculate_portfolio( - bank_req: PortfolioRequest, + portfolio_req: PortfolioRequest, eb: Option, ) -> Result { debug!( - "Starting calculation by period per BankRequest overall: {:?}", - bank_req + "Starting calculation by period per PortfolioRequest overall: {:?}", + portfolio_req ); - if eb.is_none() { - info!("Drive Deposits SEND_CAL_EVENTS is false, so no events will be sent"); - } + info!( + "Drive Deposits SEND_CAL_EVENTS is {}, so events will {}be sent", + eb.is_some(), + if eb.is_some() { "" } else { "not " } + ); + let eb_access = Arc::new(eb); - let bank_resp = build_from_bank_request(bank_req, eb_access).await?; + let bank_resp = build_from_portfolio_request(portfolio_req, eb_access).await?; Ok(bank_resp) } diff --git a/drive-deposits-check-cmd/Cargo.toml b/drive-deposits-check-cmd/Cargo.toml index 3ffe687..41a03f2 100644 --- a/drive-deposits-check-cmd/Cargo.toml +++ b/drive-deposits-check-cmd/Cargo.toml @@ -30,3 +30,6 @@ drive-deposits-event-source = { path = "../drive-deposits-event-source" } assert_cmd = "2.0.14" predicates = "3.1.0" #pretty_assertions = "1.4.0" + +[features] +aws_deploy = [] diff --git a/drive-deposits-check-cmd/tests/test_delta_calculator_cli.rs b/drive-deposits-check-cmd/tests/test_delta_calculator_cli.rs index 39bf624..b842f88 100644 --- a/drive-deposits-check-cmd/tests/test_delta_calculator_cli.rs +++ b/drive-deposits-check-cmd/tests/test_delta_calculator_cli.rs @@ -8,39 +8,46 @@ use enable_tracing::initialize_test_span; mod enable_tracing; // this test actually can be uncommented to check aws deploy works -// #[test] -// fn test_valid_two_banks_json_request() -> Result<()> { -// initialize_test_span("test_two_banks_json_request").in_scope(|| { -// let json_request_file_path = "tests/data/two_banks_json_request_valid.json"; -// let cmd = Command::cargo_bin("drive-deposits-check-cmd")? -// // .env("RUST_LOG", "test=debug,drive_deposits_check_cmd=debug") -// .arg(json_request_file_path) -// .assert() -// .success(); -// -// // let output = cmd.get_output(); -// // debug!( -// // "Command Stdout is: {}", -// // String::from_utf8_lossy(&output.stdout) -// // ); -// // -// // debug!( -// // "Command Stderr is: {}", -// // String::from_utf8_lossy(&output.stderr) -// // ); -// // assert!(output.stderr.is_empty()); -// -// cmd.stdout(predicate::str::contains("VISION-BANK")) -// .stdout(predicate::str::contains( -// "tests/data/two_banks_json_request_valid.json", -// )) -// .stdout(predicate::str::contains( -// "\"maturity_date_in_bank_tz\":\"2044-02-11\"", -// )); -// -// Ok(()) -// }) -// } + +#[cfg(feature = "aws_deploy")] +#[test] +fn test_valid_two_banks_json_request() -> Result<()> { + initialize_test_span("test_two_banks_json_request").in_scope(|| { + let json_request_file_path = "tests/data/two_banks_json_request_valid.json"; + let cmd = Command::cargo_bin("drive-deposits-check-cmd")? + // .env( + // "RUST_LOG", + // "test=debug,drive_deposits_check_cmd=debug,drive_deposits_cal_types=debug", + // ) + // SEND_CAL_EVENTS = "true" + .env("SEND_CAL_EVENTS", "false") + .arg(json_request_file_path) + .assert() + .success(); + + let output = cmd.get_output(); + debug!( + "Command Stdout is: {}", + String::from_utf8_lossy(&output.stdout) + ); + // + // debug!( + // "Command Stderr is: {}", + // String::from_utf8_lossy(&output.stderr) + // ); + // assert!(output.stderr.is_empty()); + + cmd.stdout(predicate::str::contains("VISION-BANK")) + .stdout(predicate::str::contains( + "tests/data/two_banks_json_request_valid.json", + )) + .stdout(predicate::str::contains( + "\"maturity_date_in_bank_tz\":\"2044-02-11\"", + )); + + Ok(()) + }) +} #[test] fn test_invalid_two_banks_json_request() -> Result<()> { diff --git a/justfile b/justfile index 8614e0f..4275eb7 100644 --- a/justfile +++ b/justfile @@ -119,6 +119,9 @@ watch-run-drive-deposits-rest-gateway-server: test: cargo test --workspace +test-with-aws-deploy-only: + cargo test -p drive-deposits-check-cmd --test test_delta_calculator_cli --features aws_deploy -- test_valid_two_banks_json_request --exact + # watch test watch-test: cargo watch -x "test --workspace"