mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-05 11:00:56 +00:00
feat: find_candidate_by_id_test
This commit is contained in:
parent
37c418d8cd
commit
b82092e323
1 changed files with 40 additions and 0 deletions
|
|
@ -8,3 +8,43 @@ impl Query {
|
||||||
Candidate::find_by_id(id).one(db).await
|
Candidate::find_by_id(id).one(db).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use sea_orm::{DbConn, Set, ActiveModelTrait};
|
||||||
|
use entity::candidate;
|
||||||
|
use sea_orm::{Schema, Database, DbBackend, sea_query::TableCreateStatement, ConnectionTrait};
|
||||||
|
|
||||||
|
use crate::Query;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
async fn get_memory_sqlite_connection() -> DbConn {
|
||||||
|
let base_url = "sqlite::memory:";
|
||||||
|
let db: DbConn = Database::connect(base_url).await.unwrap();
|
||||||
|
|
||||||
|
let schema = Schema::new(DbBackend::Sqlite);
|
||||||
|
let stmt: TableCreateStatement = schema.create_table_from_entity(candidate::Entity);
|
||||||
|
db.execute(db.get_database_backend().build(&stmt)).await.unwrap();
|
||||||
|
db
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_find_candidate_by_id() {
|
||||||
|
let db = get_memory_sqlite_connection().await;
|
||||||
|
let candidate = candidate::ActiveModel {
|
||||||
|
application: Set(103158),
|
||||||
|
code: Set("test".to_string()),
|
||||||
|
public_key: Set("test".to_string()),
|
||||||
|
private_key: Set("test".to_string()),
|
||||||
|
created_at: Set(chrono::offset::Local::now().naive_local()),
|
||||||
|
updated_at: Set(chrono::offset::Local::now().naive_local()),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.insert(&db)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let candidate = Query::find_candidate_by_id(&db, candidate.application).await.unwrap();
|
||||||
|
assert!(candidate.is_some());
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue