tests for user balance and account list

This commit is contained in:
DSeeLP 2025-03-07 15:13:19 +01:00
parent 6e04bb561c
commit a4e233398f
4 changed files with 34 additions and 9 deletions

View File

@ -1,7 +1,6 @@
use std::sync::Arc;
use axum::{Router, extract::Path, http::StatusCode, routing::get};
use serde::Serialize;
use tracing::instrument;
use uuid::Uuid;
@ -24,12 +23,6 @@ pub(super) fn router() -> Router<Arc<AppState>> {
make_schemas!((); (Pagination<AccountInfo>));
#[derive(Serialize)]
#[cfg_attr(feature = "schemas", derive(schemars::JsonSchema))]
pub struct ListAccounts {
accounts: Vec<AccountInfo>,
}
#[instrument(skip(state))]
pub async fn account_info(EState(state): State, _: Auth, Path(id): Path<Uuid>) {}

View File

@ -45,7 +45,7 @@ make_schemas!((); (Pagination<User>, UserAccounts, UserBalance));
#[derive(Serialize)]
#[cfg_attr(feature = "schemas", derive(schemars::JsonSchema))]
pub struct UserAccounts {
pub accounts: Vec<UserAccountInfo>,
pub result: Vec<UserAccountInfo>,
}
#[derive(Serialize)]
@ -109,7 +109,7 @@ pub async fn user_accounts(EState(state): State, auth: Auth) -> Result<Json<User
let user = auth.user_id();
let conn = state.conn().await?;
let result = Account::list_for_user(&conn, user).await?;
Ok(Json(UserAccounts { accounts: result }))
Ok(Json(UserAccounts { result }))
}
#[cfg(test)]

View File

@ -0,0 +1,17 @@
POST {{host}}/api/login
{
"name": "user1",
"password": "this-is-a-password"
}
HTTP 200
[Captures]
token: jsonpath "$.token"
GET {{host}}/api/users/@me/accounts
Authorization: Bearer {{token}}
HTTP 200
[Asserts]
jsonpath "$.result" isCollection
jsonpath "$.result[0].name" == "user1"
jsonpath "$.result[0].balance" == 100000

View File

@ -0,0 +1,15 @@
POST {{host}}/api/login
{
"name": "user1",
"password": "this-is-a-password"
}
HTTP 200
[Captures]
token: jsonpath "$.token"
GET {{host}}/api/users/@me/balance
Authorization: Bearer {{token}}
HTTP 200
[Asserts]
jsonpath "$.balance" == 100000