Test create customer

This commit is contained in:
Sam Samai 2021-07-05 21:50:18 +10:00
parent a40785c554
commit cf356ecfdb
2 changed files with 23 additions and 0 deletions

View File

@ -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;
}

View File

@ -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::Model> = 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");
}