mirror of
https://github.com/redlib-org/redlib.git
synced 2025-06-23 17:40:58 +00:00
fix(client): update rate limit self-check (fix #335)
This commit is contained in:
parent
7fe109df22
commit
a4f511f67e
2 changed files with 27 additions and 6 deletions
|
@ -19,8 +19,7 @@ use std::{io, result::Result};
|
|||
use crate::dbg_msg;
|
||||
use crate::oauth::{force_refresh_token, token_daemon, Oauth};
|
||||
use crate::server::RequestExt;
|
||||
use crate::subreddit::community;
|
||||
use crate::utils::format_url;
|
||||
use crate::utils::{format_url, Post};
|
||||
|
||||
const REDDIT_URL_BASE: &str = "https://oauth.reddit.com";
|
||||
const REDDIT_URL_BASE_HOST: &str = "oauth.reddit.com";
|
||||
|
@ -480,11 +479,10 @@ pub async fn json(path: String, quarantine: bool) -> Result<Value, String> {
|
|||
}
|
||||
|
||||
async fn self_check(sub: &str) -> Result<(), String> {
|
||||
let request = Request::get(format!("/r/{sub}/")).body(Body::empty()).unwrap();
|
||||
let query = format!("/r/{sub}/hot.json?&raw_json=1");
|
||||
|
||||
match community(request).await {
|
||||
Ok(sub) if sub.status().is_success() => Ok(()),
|
||||
Ok(sub) => Err(sub.status().to_string()),
|
||||
match Post::fetch(&query, true).await {
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
@ -509,6 +507,26 @@ pub async fn rate_limit_check() -> Result<(), String> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
use {crate::config::get_setting, sealed_test::prelude::*};
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn test_rate_limit_check() {
|
||||
rate_limit_check().await.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[sealed_test(env = [("REDLIB_DEFAULT_SUBSCRIPTIONS", "rust")])]
|
||||
fn test_default_subscriptions() {
|
||||
tokio::runtime::Builder::new_multi_thread().enable_all().build().unwrap().block_on(async {
|
||||
let subscriptions = get_setting("REDLIB_DEFAULT_SUBSCRIPTIONS");
|
||||
assert!(subscriptions.is_some());
|
||||
|
||||
// check rate limit
|
||||
rate_limit_check().await.unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
static POPULAR_URL: &str = "/r/popular/hot.json?&raw_json=1&geo_filter=GLOBAL";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue