add revivability
This commit is contained in:
parent
77c50fac64
commit
3e6bfa8c34
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "torn-api"
|
||||
version = "0.5.2"
|
||||
version = "0.5.3"
|
||||
edition = "2021"
|
||||
authors = ["Pyrit [2111649]"]
|
||||
license = "MIT"
|
||||
|
|
|
@ -39,3 +39,16 @@ where
|
|||
Ok(Some(DateTime::from_utc(naive, Utc)))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn int_is_bool<'de, D>(deserializer: D) -> Result<bool, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let i = i64::deserialize(deserializer)?;
|
||||
|
||||
match i {
|
||||
0 => Ok(false),
|
||||
1 => Ok(true),
|
||||
x => Err(Error::invalid_value(Unexpected::Signed(x), &"0 or 1")),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -340,6 +340,9 @@ pub struct Profile {
|
|||
|
||||
#[serde(deserialize_with = "deserialize_comp")]
|
||||
pub competition: Option<Competition>,
|
||||
|
||||
#[serde(deserialize_with = "de_util::int_is_bool")]
|
||||
pub revivable: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
|
|
|
@ -78,3 +78,45 @@ where
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(test, feature = "postgres"))]
|
||||
mod test {
|
||||
use std::sync::{Arc, Once};
|
||||
|
||||
use sqlx::Row;
|
||||
use tokio::test;
|
||||
|
||||
use super::*;
|
||||
|
||||
static INIT: Once = Once::new();
|
||||
|
||||
pub(crate) async fn setup() -> postgres::PgKeyPoolStorage {
|
||||
INIT.call_once(|| {
|
||||
dotenv::dotenv().ok();
|
||||
});
|
||||
|
||||
let pool = sqlx::PgPool::connect(&std::env::var("DATABASE_URL").unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
sqlx::query("update api_keys set uses=0")
|
||||
.execute(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
postgres::PgKeyPoolStorage::new(pool, 50)
|
||||
}
|
||||
|
||||
#[test]
|
||||
async fn key_pool_bulk() {
|
||||
let storage = setup().await;
|
||||
|
||||
if let Err(e) = storage.initialise().await {
|
||||
panic!("Initialising key storage failed: {:?}", e);
|
||||
}
|
||||
|
||||
let pool = send::KeyPool::new(reqwest::Client::default(), storage);
|
||||
|
||||
pool.torn_api(KeyDomain::Public).users([1], |b| b).await;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue