mirror of
https://github.com/Phundrak/georm.git
synced 2025-12-14 00:31:53 +01:00
test: added tests for M2M relationships, it works
This commit is contained in:
33
tests/o2m_relationship.rs
Normal file
33
tests/o2m_relationship.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use georm::Georm;
|
||||
|
||||
mod models;
|
||||
use models::*;
|
||||
|
||||
#[sqlx::test(fixtures("simple_struct", "o2o"))]
|
||||
async fn books_access_one_review(pool: sqlx::PgPool) -> sqlx::Result<()> {
|
||||
let book = Book::find(&pool, &1).await?.unwrap();
|
||||
let reviews = book.get_reviews(&pool).await?;
|
||||
let review = Review {
|
||||
id: 1,
|
||||
book_id: 1,
|
||||
review: "Great book".into(),
|
||||
};
|
||||
assert_eq!(vec![review], reviews);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[sqlx::test(fixtures("simple_struct", "o2o"))]
|
||||
async fn books_should_access_their_multiple_reviews(pool: sqlx::PgPool) -> sqlx::Result<()> {
|
||||
let book = Book::find(&pool, &2).await?.unwrap();
|
||||
let reviews = book.get_reviews(&pool).await?;
|
||||
assert_eq!(2, reviews.len());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[sqlx::test(fixtures("simple_struct", "o2o"))]
|
||||
async fn books_can_have_no_reviews(pool: sqlx::PgPool) -> sqlx::Result<()> {
|
||||
let book = Book::find(&pool, &4).await?.unwrap();
|
||||
let reviews = book.get_reviews(&pool).await?;
|
||||
assert_eq!(0, reviews.len());
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user