1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use warp::{Filter, Rejection, Reply};

/// GET /api/v0/sensors
pub fn get() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
  warp::path("api")
    .and(warp::path("v0"))
    .and(warp::path("sensors"))
    .and(warp::get())
    .map(|| {
      warp::reply::json(&serde_json::json!({
        "resources": [
          {"endpoint": "/api/v0/sensors/latest", "description": "GET latest measurment from every sensor"},
          {"endpoint": "/api/v0/sensors/latest/:count", "description": "GET latest :count measurments from every sensor"},
          {"endpoint": "/api/v0/sensors/meta", "description": "GET metadata from every sensor"},
          {"endpoint": "/api/v0/sensors/aggregates", "description": "GET aggregates from every sensor"},
        ],
        "description": "Discover resources available for all sensors",
      }))
    })
}

#[tokio::test]
async fn test_get() {
  let database_test_factory =
    crate::db::DatabaseTestFactory::new(".temp/test/sensors/test_get");

  for db in database_test_factory.get_instance().values() {
    let api = super::endpoints((*db).clone());

    let resp = warp::test::request()
      .method("GET")
      .path("/api/v0/sensors")
      .reply(&api)
      .await;
    assert_eq!(resp.status(), 200);
  }
}