Skip to content

Commit

Permalink
Mock find related (SeaQL/sea-orm#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed Jan 31, 2022
1 parent f8e723b commit ef0083f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions SeaORM/docs/07-write-test/02-mock.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ mod tests {
},
],
])
.append_query_results(vec![
// Third query result
vec![(
cake::Model {
id: 1,
name: "Apple Cake".to_owned(),
},
fruit::Model {
id: 2,
name: "Apple".to_owned(),
cake_id: Some(1),
},
)],
])
.into_connection();

// Find a cake from MockDatabase
Expand Down Expand Up @@ -74,6 +88,25 @@ mod tests {
]
);

// Find all cakes with its related fruits
assert_eq!(
cake::Entity::find()
.find_also_related(fruit::Entity)
.all(&db)
.await?,
vec![(
cake::Model {
id: 1,
name: "Apple Cake".to_owned(),
},
Some(fruit::Model {
id: 2,
name: "Apple".to_owned(),
cake_id: Some(1),
})
)]
);

// Checking transaction log
assert_eq!(
db.into_transaction_log(),
Expand All @@ -88,6 +121,11 @@ mod tests {
r#"SELECT "cake"."id", "cake"."name" FROM "cake""#,
vec![]
),
Transaction::from_sql_and_values(
DatabaseBackend::Postgres,
r#"SELECT "cake"."id" AS "A_id", "cake"."name" AS "A_name", "fruit"."id" AS "B_id", "fruit"."name" AS "B_name", "fruit"."cake_id" AS "B_cake_id" FROM "cake" LEFT JOIN "fruit" ON "cake"."id" = "fruit"."cake_id""#,
vec![]
),
]
);

Expand Down

0 comments on commit ef0083f

Please sign in to comment.