test: added tests for M2M relationships, it works

This commit is contained in:
2025-01-31 22:52:28 +01:00
parent 86e29fa2dc
commit b70b4b7a81
5 changed files with 93 additions and 5 deletions
+20
View File
@@ -0,0 +1,20 @@
use georm::Georm;
mod models;
use models::*;
#[sqlx::test(fixtures("simple_struct", "o2o", "m2m"))]
async fn genres_should_be_able_to_access_all_books(pool: sqlx::PgPool) -> sqlx::Result<()> {
let fantasy = Genre::find(&pool, &1).await?.unwrap();
let books = fantasy.get_books(&pool).await?;
assert_eq!(3, books.len());
Ok(())
}
#[sqlx::test(fixtures("simple_struct", "o2o", "m2m"))]
async fn books_should_be_able_to_access_their_genres(pool: sqlx::PgPool) -> sqlx::Result<()> {
let to_build_a_fire = Book::find(&pool, &4).await?.unwrap();
let genres = to_build_a_fire.get_genres(&pool).await?;
assert_eq!(2, genres.len());
Ok(())
}