From cf356ecfdb9f0a8837a04bd643d35dd000dc651b Mon Sep 17 00:00:00 2001 From: Sam Samai Date: Mon, 5 Jul 2021 21:50:18 +1000 Subject: [PATCH] Test create customer --- tests/bakery_chain_tests.rs | 1 + tests/crud/mod.rs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/tests/bakery_chain_tests.rs b/tests/bakery_chain_tests.rs index e97c3c3b..c83dc8dc 100644 --- a/tests/bakery_chain_tests.rs +++ b/tests/bakery_chain_tests.rs @@ -27,4 +27,5 @@ async fn setup_schema(db: &DbConn) { async fn create_entities(db: &DbConn) { crud::test_create_bakery(db).await; crud::test_create_baker(db).await; + crud::test_create_customer(db).await; } diff --git a/tests/crud/mod.rs b/tests/crud/mod.rs index 8481577d..75fba65b 100644 --- a/tests/crud/mod.rs +++ b/tests/crud/mod.rs @@ -78,3 +78,25 @@ pub async fn test_create_baker(db: &DbConn) { assert_eq!(related_bakers.len(), 1); assert_eq!(related_bakers[0].name, "Baker Bob") } + +pub async fn test_create_customer(db: &DbConn) { + let customer_kate = customer::ActiveModel { + name: Set("Kate".to_owned()), + notes: Set("Loves cheese cake".to_owned()), + ..Default::default() + }; + let res: InsertResult = Customer::insert(customer_kate) + .exec(db) + .await + .expect("could not insert customer"); + + let customer: Option = Customer::find_by_id(res.last_insert_id) + .one(db) + .await + .expect("could not find customer"); + + assert!(customer.is_some()); + let customer_model = customer.unwrap(); + assert_eq!(customer_model.name, "Kate"); + assert_eq!(customer_model.notes, "Loves cheese cake"); +}