add dev resources; plumb GUI_ENV_FILE/API_ENV_FILE/API_DESI_DATA into run targets
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
use axum::body::{to_bytes, Body};
|
||||
use axum::http::{Request, StatusCode};
|
||||
use std::sync::Arc;
|
||||
use tower::ServiceExt;
|
||||
|
||||
use desi_explorer_api::models::CatalogObject;
|
||||
use desi_explorer_api::routes;
|
||||
use desi_explorer_api::store::CatalogStore;
|
||||
|
||||
fn sample_store() -> CatalogStore {
|
||||
CatalogStore {
|
||||
catalogs: Vec::new(),
|
||||
objects: vec![
|
||||
CatalogObject {
|
||||
id: "o1".to_string(),
|
||||
catalog: "edr".to_string(),
|
||||
object_type: "GALAXY".to_string(),
|
||||
ra: 1.5,
|
||||
dec: 2.5,
|
||||
redshift: 0.8,
|
||||
},
|
||||
CatalogObject {
|
||||
id: "o2".to_string(),
|
||||
catalog: "dr1".to_string(),
|
||||
object_type: "STAR".to_string(),
|
||||
ra: 3.5,
|
||||
dec: 4.5,
|
||||
redshift: 0.0,
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn objects_returns_all_when_no_filter() {
|
||||
let app = routes::app_with_state(Arc::new(sample_store()));
|
||||
|
||||
let response = app
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.uri("/api/v1/objects")
|
||||
.body(Body::empty())
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
let body = to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
||||
let objects: Vec<CatalogObject> = serde_json::from_slice(&body).unwrap();
|
||||
assert_eq!(objects.len(), 2);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn objects_filters_by_catalog() {
|
||||
let app = routes::app_with_state(Arc::new(sample_store()));
|
||||
|
||||
let response = app
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.uri("/api/v1/objects?catalog=edr")
|
||||
.body(Body::empty())
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
let body = to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
||||
let objects: Vec<CatalogObject> = serde_json::from_slice(&body).unwrap();
|
||||
assert_eq!(objects.len(), 1);
|
||||
assert_eq!(objects[0].id, "o1");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn objects_respects_limit() {
|
||||
let app = routes::app_with_state(Arc::new(sample_store()));
|
||||
|
||||
let response = app
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.uri("/api/v1/objects?limit=1")
|
||||
.body(Body::empty())
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
let body = to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
||||
let objects: Vec<CatalogObject> = serde_json::from_slice(&body).unwrap();
|
||||
assert_eq!(objects.len(), 1);
|
||||
}
|
||||
Reference in New Issue
Block a user