added test for admin deposit endpoint, fixed bugs

This commit is contained in:
yenicelik 2023-07-06 08:19:33 -04:00
parent fc9b1dd69e
commit af45f78ff5
4 changed files with 84 additions and 2 deletions

@ -122,7 +122,7 @@ pub async fn user_stripe_deposits_get(
// Filter by user ...
let receipts = stripe_increase_balance_receipt::Entity::find()
.filter(increase_on_chain_balance_receipt::Column::DepositToUserId.eq(Some(user.id)))
.filter(stripe_increase_balance_receipt::Column::DepositToUserId.eq(Some(user.id)))
.all(db_replica.as_ref())
.await?;
@ -165,7 +165,7 @@ pub async fn user_admin_deposits_get(
// Filter by user ...
let receipts = admin_increase_balance_receipt::Entity::find()
.filter(increase_on_chain_balance_receipt::Column::DepositToUserId.eq(user.id))
.filter(admin_increase_balance_receipt::Column::DepositToUserId.eq(user.id))
.all(db_replica.as_ref())
.await?;

@ -0,0 +1,33 @@
use crate::TestApp;
use ethers::prelude::{LocalWallet, Signer};
use rust_decimal::Decimal;
use tracing::info;
use web3_proxy::frontend::admin::AdminIncreaseBalancePost;
use web3_proxy::frontend::users::authentication::LoginPostResponse;
/// Helper function to increase the balance of a user, from an admin
#[allow(unused)]
pub async fn get_admin_deposits(
x: &TestApp,
r: &reqwest::Client,
user: &LoginPostResponse,
) -> serde_json::Value {
let increase_balance_post_url = format!("{}user/deposits/admin", x.proxy_provider.url());
info!("Get admin increase deposits");
// Login the user
// Use the bearer token of admin to increase user balance
let admin_balance_deposits = r
.get(increase_balance_post_url)
.bearer_auth(user.bearer_token)
.send()
.await
.unwrap();
info!(?admin_balance_deposits, "http response");
let admin_balance_deposits = admin_balance_deposits
.json::<serde_json::Value>()
.await
.unwrap();
info!(?admin_balance_deposits, "json response");
admin_balance_deposits
}

@ -2,6 +2,7 @@ pub mod admin_increases_balance;
pub mod app;
pub mod create_admin;
pub mod create_user;
pub mod get_admin_deposits;
pub mod get_rpc_key;
pub mod get_user_balance;
pub mod referral;

@ -3,6 +3,7 @@ mod common;
use crate::common::admin_increases_balance::admin_increase_balance;
use crate::common::create_admin::create_user_as_admin;
use crate::common::create_user::create_user;
use crate::common::get_admin_deposits::get_admin_deposits;
use crate::common::get_rpc_key::{user_get_first_rpc_key, RpcKey};
use crate::common::get_user_balance::user_get_balance;
use crate::common::referral::{
@ -87,6 +88,53 @@ async fn test_log_in_and_out() {
assert_eq!(logout_response, "goodbye");
}
#[cfg_attr(not(feature = "tests-needing-docker"), ignore)]
#[test_log::test(tokio::test)]
async fn test_admin_balance_increase() {
info!("Starting balance decreases with usage test");
let x = TestApp::spawn(true).await;
let r = reqwest::Client::builder()
.timeout(Duration::from_secs(20))
.build()
.unwrap();
let user_wallet = x.wallet(0);
let admin_wallet = x.wallet(1);
// Create three users, one referrer, one admin who bumps both their balances
let admin_login_response = create_user_as_admin(&x, &r, &admin_wallet).await;
let user_login_response = create_user(&x, &r, &user_wallet, None).await;
// Bump both user's wallet to $20
admin_increase_balance(
&x,
&r,
&admin_login_response,
&user_wallet,
Decimal::from(20),
)
.await;
info!("Getting admin deposits");
let response = get_admin_deposits(&x, &r, &user_login_response).await;
info!(?response);
assert_eq!(
Decimal::from_str(
response["deposits"].get(0).unwrap()["amount"]
.as_str()
.unwrap()
)
.unwrap(),
Decimal::from(20)
);
assert_eq!(
response["deposits"].get(0).unwrap()["note"]
.as_str()
.unwrap(),
"Test increasing balance"
);
}
#[cfg_attr(not(feature = "tests-needing-docker"), ignore)]
#[test_log::test(tokio::test)]
async fn test_user_balance_decreases() {