Test order addresses

This commit is contained in:
Adrian Woźniak 2022-06-10 15:02:28 +02:00
parent 69bf0b5dff
commit 9b1e95fe81
No known key found for this signature in database
GPG Key ID: 0012845A89C7352B
2 changed files with 70 additions and 3 deletions

View File

@ -36,7 +36,7 @@ SELECT
order_addresses.street,
order_addresses.city,
order_addresses.country,
order_addresses.zip
order_addresses.zip,
order_addresses.phone
FROM order_addresses
INNER JOIN orders ON orders.address_id = order_addresses.id
@ -46,7 +46,11 @@ WHERE orders.id = $1
.bind(msg.order_id)
.fetch_one(pool)
.await
.map_err(|_| Error::OrderAddress.into())
.map_err(|e| {
tracing::error!("{e}");
dbg!(e);
Error::OrderAddress.into()
})
}
#[derive(actix::Message)]
@ -156,6 +160,44 @@ mod tests {
use crate::*;
async fn test_account(t: &mut sqlx::Transaction<'_, sqlx::Postgres>) -> FullAccount {
use fake::faker::internet::en;
let login: String = en::Username().fake();
let email: String = en::FreeEmail().fake();
let hash: String = en::Password(10..22).fake();
create_account(
CreateAccount {
email: Email::new(email),
login: Login::new(login),
pass_hash: PassHash::new(hash),
role: Role::Admin,
},
t,
)
.await
.unwrap()
}
async fn test_order(
t: &mut sqlx::Transaction<'_, sqlx::Postgres>,
address_id: OrderAddressId,
) -> Order {
let buyer_id = test_account(t).await.id;
crate::create_order(
CreateOrder {
buyer_id,
items: vec![],
shopping_cart_id: None,
checkout_notes: None,
delivery_address_id: address_id,
},
t,
)
.await
.unwrap()
}
async fn test_order_address(
t: &mut sqlx::Transaction<'_, sqlx::Postgres>,
) -> model::OrderAddress {
@ -230,11 +272,31 @@ mod tests {
);
}
#[actix::test]
async fn order_address() {
testx::db_t_ref!(t);
test_order_address(&mut t).await;
{
let _address = test_order_address(&mut t).await;
let _order = test_order(&mut t, _address.id).await;
}
let (original, order) = {
let address = test_order_address(&mut t).await;
let order = test_order(&mut t, address.id).await;
(address, order)
};
{
let _address = test_order_address(&mut t).await;
let _order = test_order(&mut t, _address.id).await;
}
let loaded = super::order_address(super::OrderAddress { order_id: order.id }, &mut t)
.await
.unwrap();
testx::db_rollback!(t);
assert_eq!(original, loaded);
}
}

View File

@ -496,6 +496,11 @@ mod tests {
quantity: Default::default(),
quantity_unit: QuantityUnit::Gram,
},
create_order::OrderItem {
product_id: test_product(&mut t).await.id,
quantity: Default::default(),
quantity_unit: QuantityUnit::Gram,
},
],
shopping_cart_id: None,
checkout_notes: None,