2023-06-29 22:41:21 +03:00
|
|
|
mod common;
|
|
|
|
|
2023-07-04 01:54:22 +03:00
|
|
|
use std::str::FromStr;
|
|
|
|
use std::time::Duration;
|
|
|
|
|
2023-07-06 08:18:39 +03:00
|
|
|
use crate::common::admin_increases_balance::admin_increase_balance;
|
2023-07-13 00:23:39 +03:00
|
|
|
use crate::common::anvil::TestAnvil;
|
2023-07-06 08:18:39 +03:00
|
|
|
use crate::common::create_admin::create_user_as_admin;
|
2023-07-12 20:24:16 +03:00
|
|
|
use crate::common::create_user::create_user;
|
2023-07-13 00:23:39 +03:00
|
|
|
use crate::common::mysql::TestMysql;
|
2023-07-12 10:35:07 +03:00
|
|
|
use crate::common::user_balance::user_get_balance;
|
2023-06-29 22:41:21 +03:00
|
|
|
use crate::common::TestApp;
|
2023-07-10 06:13:03 +03:00
|
|
|
use migration::sea_orm::prelude::Decimal;
|
2023-07-04 01:54:22 +03:00
|
|
|
use tracing::info;
|
2023-06-29 22:41:21 +03:00
|
|
|
|
2023-06-30 22:53:21 +03:00
|
|
|
// #[cfg_attr(not(feature = "tests-needing-docker"), ignore)]
|
2023-06-30 07:28:31 +03:00
|
|
|
#[ignore = "under construction"]
|
2023-06-29 22:41:21 +03:00
|
|
|
#[test_log::test(tokio::test)]
|
|
|
|
async fn test_admin_imitate_user() {
|
|
|
|
todo!();
|
|
|
|
}
|
|
|
|
|
2023-07-01 05:24:48 +03:00
|
|
|
#[cfg_attr(not(feature = "tests-needing-docker"), ignore)]
|
2023-06-29 22:41:21 +03:00
|
|
|
#[test_log::test(tokio::test)]
|
|
|
|
async fn test_admin_grant_credits() {
|
2023-07-01 22:26:42 +03:00
|
|
|
info!("Starting admin grant credits test");
|
2023-07-13 00:23:39 +03:00
|
|
|
|
|
|
|
let a: TestAnvil = TestAnvil::spawn(31337).await;
|
|
|
|
|
|
|
|
let db = TestMysql::spawn().await;
|
|
|
|
|
2023-07-22 11:38:54 +03:00
|
|
|
let x = TestApp::spawn(&a, Some(&db), None, None).await;
|
2023-07-13 00:23:39 +03:00
|
|
|
|
2023-07-04 01:54:22 +03:00
|
|
|
let r = reqwest::Client::builder()
|
|
|
|
.timeout(Duration::from_secs(3))
|
|
|
|
.build()
|
|
|
|
.unwrap();
|
2023-06-29 22:41:21 +03:00
|
|
|
|
2023-07-01 05:24:48 +03:00
|
|
|
// Setup variables that will be used
|
2023-07-13 00:42:47 +03:00
|
|
|
let user_wallet = a.wallet(0);
|
|
|
|
let admin_wallet = a.wallet(1);
|
2023-07-06 08:18:39 +03:00
|
|
|
info!(?admin_wallet);
|
2023-07-04 01:54:22 +03:00
|
|
|
|
2023-07-06 08:18:39 +03:00
|
|
|
let user_login_response = create_user(&x, &r, &user_wallet, None).await;
|
2023-07-13 00:42:47 +03:00
|
|
|
let admin_login_response = create_user_as_admin(&x, &db, &r, &admin_wallet).await;
|
2023-07-01 22:26:42 +03:00
|
|
|
info!(?admin_login_response);
|
2023-07-01 05:24:48 +03:00
|
|
|
|
2023-07-06 08:18:39 +03:00
|
|
|
let increase_balance_response = admin_increase_balance(
|
|
|
|
&x,
|
|
|
|
&r,
|
|
|
|
&admin_login_response,
|
|
|
|
&user_wallet,
|
|
|
|
Decimal::from(100),
|
|
|
|
)
|
|
|
|
.await;
|
2023-07-01 05:24:48 +03:00
|
|
|
|
2023-07-06 08:18:39 +03:00
|
|
|
assert_eq!(
|
|
|
|
Decimal::from_str(increase_balance_response["amount"].as_str().unwrap()).unwrap(),
|
|
|
|
Decimal::from(100)
|
2023-07-01 22:38:56 +03:00
|
|
|
);
|
2023-07-04 01:54:22 +03:00
|
|
|
|
2023-07-12 10:35:07 +03:00
|
|
|
let user_balance = user_get_balance(&x, &r, &user_login_response).await;
|
|
|
|
assert_eq!(user_balance.remaining(), Decimal::from(100));
|
2023-07-04 01:54:22 +03:00
|
|
|
|
2023-07-15 04:30:01 +03:00
|
|
|
x.wait_for_stop();
|
2023-06-29 22:41:21 +03:00
|
|
|
}
|
|
|
|
|
2023-06-30 22:53:21 +03:00
|
|
|
// #[cfg_attr(not(feature = "tests-needing-docker"), ignore)]
|
2023-06-30 07:28:31 +03:00
|
|
|
#[ignore = "under construction"]
|
2023-06-29 22:41:21 +03:00
|
|
|
#[test_log::test(tokio::test)]
|
|
|
|
async fn test_admin_change_user_tier() {
|
|
|
|
todo!();
|
|
|
|
}
|