commit f5a57a3f1eb4e92b5d1f80eb3d68ccf2fd39e7a7
parent 290a07f14a882208b25653c47e863ca9fba0504a
Author: Antoine A <>
Date: Fri, 24 Apr 2026 10:37:58 +0200
EbicsTxTest
Diffstat:
| M | src/db.rs | | | 45 | +++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 45 insertions(+), 0 deletions(-)
diff --git a/src/db.rs b/src/db.rs
@@ -14,6 +14,7 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
+use compact_str::CompactString;
use jiff::Timestamp;
use sqlx::{PgPool, QueryBuilder, Row, postgres::PgRow};
use taler_api::db::{BindHelper, IncomingType, TypeHelper, history};
@@ -250,6 +251,34 @@ pub async fn incoming_history(
.await
}
+/** Register a pending transaction */
+pub async fn ebics_register(db: &PgPool, id: &str) -> sqlx::Result<()> {
+ sqlx::query(
+ "INSERT INTO pending_ebics_transactions (tx_id) VALUES ($1) ON CONFLICT DO NOTHING",
+ )
+ .bind(id)
+ .execute(db)
+ .await?;
+ Ok(())
+}
+
+/** Register a pending transaction */
+pub async fn ebics_remove(db: &PgPool, id: &str) -> sqlx::Result<()> {
+ sqlx::query("DELETE FROM pending_ebics_transactions WHERE tx_id = $1")
+ .bind(id)
+ .execute(db)
+ .await?;
+ Ok(())
+}
+
+/** Register a pending transaction */
+pub async fn ebics_first(db: &PgPool) -> sqlx::Result<Option<CompactString>> {
+ sqlx::query("SELECT tx_id FROM pending_ebics_transactions LIMIT 1")
+ .try_map(|r: PgRow| r.try_get(0))
+ .fetch_optional(db)
+ .await
+}
+
#[cfg(test)]
mod test {
use std::{str::FromStr, sync::LazyLock};
@@ -268,6 +297,7 @@ mod test {
use crate::{
CONFIG_SOURCE,
+ db::{ebics_first, ebics_register, ebics_remove},
model::{IncomingId, IncomingPayment, InitiatedPayment, OutgoingId, OutgoingPayment},
rand_ebics_id,
};
@@ -440,4 +470,19 @@ mod test {
.unwrap();
assert_eq!(state, current);
}
+
+ #[tokio::test]
+ pub async fn ebics_pending() {
+ let (_, db) = setup().await;
+ let ids = ["first", "second", "third"];
+
+ for id in ids {
+ ebics_register(&db, id).await.unwrap();
+ }
+ for id in ids {
+ assert_eq!(Some(id), ebics_first(&db).await.unwrap().as_deref());
+ ebics_remove(&db, id).await.unwrap();
+ }
+ assert_eq!(ebics_first(&db).await.unwrap(), None);
+ }
}