mirror of
https://git.dirksys.ovh/dirk/bankserver.git
synced 2026-01-06 11:12:41 +01:00
tests for user balance and account list
This commit is contained in:
parent
6e04bb561c
commit
a4e233398f
@ -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>) {}
|
||||
|
||||
|
||||
@ -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)]
|
||||
|
||||
17
tests/integration/user-account-list.hurl
Normal file
17
tests/integration/user-account-list.hurl
Normal 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
|
||||
15
tests/integration/user-balance.hurl
Normal file
15
tests/integration/user-balance.hurl
Normal 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
|
||||
Loading…
x
Reference in New Issue
Block a user