Separate schema tests

This commit is contained in:
Sam Samai 2021-06-30 21:15:12 +10:00
parent 6104770b65
commit 391fb08260
4 changed files with 35 additions and 7 deletions

View File

@ -5,3 +5,11 @@ pub mod cakes_bakers;
pub mod customer; pub mod customer;
pub mod lineitem; pub mod lineitem;
pub mod order; pub mod order;
pub use super::baker::Entity as Baker;
pub use super::bakery::Entity as Bakery;
pub use super::cake::Entity as Cake;
pub use super::cakes_bakers::Entity as CakesBakers;
pub use super::customer::Entity as Customer;
pub use super::lineitem::Entity as Lineitem;
pub use super::order::Entity as Order;

View File

@ -3,20 +3,26 @@ use sea_orm::DbConn;
pub mod bakery_chain; pub mod bakery_chain;
mod setup; mod setup;
pub use bakery_chain::*; pub use bakery_chain::*;
mod table_creation; mod crud;
mod schema;
#[async_std::test] #[async_std::test]
// cargo test --test bakery_chain_tests -- --nocapture // cargo test --test bakery_chain_tests -- --nocapture
async fn main() { async fn main() {
let db: DbConn = setup::setup().await; let db: DbConn = setup::setup().await;
setup_schema(&db).await; setup_schema(&db).await;
create_entities(&db).await;
} }
async fn setup_schema(db: &DbConn) { async fn setup_schema(db: &DbConn) {
assert!(table_creation::create_bakery_table(db).await.is_ok()); assert!(schema::create_bakery_table(db).await.is_ok());
assert!(table_creation::create_baker_table(db).await.is_ok()); assert!(schema::create_baker_table(db).await.is_ok());
assert!(table_creation::create_customer_table(db).await.is_ok()); assert!(schema::create_customer_table(db).await.is_ok());
assert!(table_creation::create_order_table(db).await.is_ok()); assert!(schema::create_order_table(db).await.is_ok());
assert!(table_creation::create_lineitem_table(db).await.is_ok()); assert!(schema::create_lineitem_table(db).await.is_ok());
assert!(table_creation::create_cakes_bakers_table(db).await.is_ok()); assert!(schema::create_cakes_bakers_table(db).await.is_ok());
}
async fn create_entities(db: &DbConn) {
assert!(crud::create_bakery(db).await.is_ok());
} }

14
tests/crud/mod.rs Normal file
View File

@ -0,0 +1,14 @@
use sea_orm::{entity::*, DbConn, ExecErr, InsertResult};
pub use super::bakery_chain::*;
pub async fn create_bakery(db: &DbConn) -> Result<(), ExecErr> {
let seaside_bakery = bakery::ActiveModel {
name: Set("SeaSide Bakery".to_owned()),
profit_margin: Set(10.4),
..Default::default()
};
let res: InsertResult = Bakery::insert(seaside_bakery).exec(db).await?;
Ok(())
}