From 1e92b166c7be73a94ee65e62e25bd75373d02880 Mon Sep 17 00:00:00 2001 From: philipp Date: Wed, 26 Apr 2023 11:31:02 +0200 Subject: [PATCH] add tests for trip_details --- README.md | 9 +++++++++ src/model/tripdetails.rs | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/README.md b/README.md index c6fecdb..ad01892 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,12 @@ ´cd frontend´ ´npm install´ ´npm run (watch/build)´ + + +# Backend tests +- [x] model/user.rs +- [x] model/tripdetails.rs +- [ ] model/planned_event.rs +- [ ] model/trip.rs +- [ ] model/usertrip.rs +- [ ] Rest? diff --git a/src/model/tripdetails.rs b/src/model/tripdetails.rs index e26c88b..62d9721 100644 --- a/src/model/tripdetails.rs +++ b/src/model/tripdetails.rs @@ -11,6 +11,7 @@ pub struct TripDetails { } impl TripDetails { + /// Creates a new entry in `trip_details` and returns its id. pub async fn create( db: &SqlitePool, planned_starting_time: String, @@ -31,3 +32,25 @@ impl TripDetails { query.last_insert_rowid() } } + +#[cfg(test)] +mod test { + use crate::testdb; + + use super::TripDetails; + use sqlx::SqlitePool; + + #[sqlx::test] + fn test() { + let pool = testdb!(); + + assert_eq!( + TripDetails::create(&pool, "10:00".into(), 2, "1970-01-01".into(), None).await, + 1, + ); + assert_eq!( + TripDetails::create(&pool, "10:00".into(), 2, "1970-01-01".into(), None).await, + 2, + ); + } +}