How to append no results to SeaORM Mocking interface?

111 views Asked by At

I want to test a block of code that selects before insert. If the select find the element by id then we don't insert. If we get None then we can insert.

if TheEntity::find_by_id(id).one(&db).await?.is_some() {
    //Do not insert and do other stuff...
}else{
    //Insert the new entity.
}

How can I instruct MockDatabase to return a no results result?

MockDatabase::new(DatabaseBackend::Sqlite)
   .append_query_results([
       //Here instead of return this Model I want to return None.
       vec![my_entity::Model{id: "TheId".to_string()}]
   ]);
1

There are 1 answers

0
rsan On BEST ANSWER

I used an Empty vector and is working now...

MockDatabase::new(DatabaseBackend::Sqlite)
   .append_query_results([vec![] as Vec<model:MyEntity>]);