use petro::entity::Entity as _;
use petro::op;
use petro::query::QueryBuilder;

mod common;
use common::db::get_db_client;
use common::entities::Customer;
use common::entities::Order;

#[tokio::test]
async fn it_passes() {
    let mut client = get_db_client().await;
    let tx = client.transaction().await.unwrap();

    let order = &Order::alias("order_");
    let customer = &Customer::alias("customer");

    let qb = QueryBuilder::from(order)
        .inner_join(customer, op!(customer.c.id, "=", order.c.customer_id))
        .where_cond(op!(order.c.order_number, "=", "001"));

    let (o, _c) = qb.fetch_one(&tx, &(order, customer)).await.unwrap();

    assert_eq!(&o.order_number, "001");

    tx.rollback().await.unwrap(); // Rollback to keep the DB in the same state
}

// TODO: Test query building without actually fetching (or do this in unit tests?)
// TODO: Test each of the possible joins and conditions
// TODO: Test mutations (insert, update, delete + versioned + bulk)
