Skip to content

Commit

Permalink
Add AWS deployment test and refactor portfolio functions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rsachdeva committed Sep 16, 2024
1 parent 2d5a4d1 commit 69433dc
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 46 deletions.
29 changes: 16 additions & 13 deletions drive-deposits-cal-types/src/math/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<DriveDepositsEventBridge>>,
) -> Result<PortfolioResponse, CalculationHaltError> {
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 {
Expand Down Expand Up @@ -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<DriveDepositsEventBridge>,
) -> Result<PortfolioResponse, CalculationHaltError> {
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)
}
3 changes: 3 additions & 0 deletions drive-deposits-check-cmd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
73 changes: 40 additions & 33 deletions drive-deposits-check-cmd/tests/test_delta_calculator_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 69433dc

Please sign in to comment.