34 lines
990 B
Rust
34 lines
990 B
Rust
|
use tracing::instrument;
|
||
|
|
||
|
use crate::api::api_prelude::*;
|
||
|
|
||
|
#[instrument]
|
||
|
#[get("/applications")]
|
||
|
pub async fn list_applications(state: web::Data<AppState>) -> Result<HttpResponse, Error> {
|
||
|
let apps: Vec<application::Model> = Application::find().all(&state.db).await.unwrap();
|
||
|
Ok(HttpResponse::Ok().json(apps))
|
||
|
}
|
||
|
|
||
|
#[cfg(test)]
|
||
|
mod tests {
|
||
|
use crate::api::test_prelude::*;
|
||
|
use actix_web::http::Method;
|
||
|
|
||
|
#[actix_rt::test]
|
||
|
async fn test_list_applications() {
|
||
|
let db = MockDatabase::new(DatabaseBackend::Sqlite)
|
||
|
.append_query_results(vec![vec![application::Model {
|
||
|
id: 1,
|
||
|
app_name: "Application 1".into(),
|
||
|
..Default::default()
|
||
|
}]])
|
||
|
.into_connection();
|
||
|
|
||
|
let req = actix_web::test::TestRequest::with_uri("/applications")
|
||
|
.method(Method::GET)
|
||
|
.to_request();
|
||
|
let resp = call_endpoint!(req, db);
|
||
|
assert_eq!(resp.status(), 200);
|
||
|
}
|
||
|
}
|