Add more tests

This commit is contained in:
Pig Fang 2019-04-27 23:20:42 +08:00
parent fd70a7182f
commit 7224b32c8f
2 changed files with 32 additions and 1 deletions

View File

@ -175,7 +175,7 @@ class User extends Authenticatable implements JWTSubject
$this->storageUsed = $result ?: 0;
}
return $this->storageUsed;
return (int) $this->storageUsed;
}
/**

View File

@ -11,6 +11,20 @@ struct User {
pub score: u32,
}
#[derive(Deserialize)]
struct SignResult {
pub score: u32,
pub storage: Usage,
pub remaining_time: u8,
}
#[derive(Deserialize)]
struct Usage {
pub used: u32,
pub total: u32,
pub percentage: f32,
}
#[test]
fn fetch_user_info() {
let client = reqwest::Client::new();
@ -30,3 +44,20 @@ fn fetch_user_info() {
assert_eq!(user.avatar, 0);
assert_eq!(user.score, 1000);
}
#[test]
fn sign() {
let client = reqwest::Client::new();
let body = client
.put("http://127.0.0.1:32123/api/user/sign")
.header("Authorization", login())
.send()
.unwrap()
.json::<JsonBody<SignResult>>()
.unwrap();
assert!(body.is_success());
let sign_result = body.data().unwrap();
assert!(sign_result.score > 1000);
assert!(sign_result.remaining_time > 0);
}