#![allow(clippy::unwrap_used, clippy::expect_used)]
use axum::{
Router,
body::to_bytes,
http::{Request, StatusCode},
routing::get,
};
use modkit::api::odata::OData;
use tower::ServiceExt;
#[tokio::test]
async fn order_with_cursor_is_422() {
async fn handler(OData(_q): OData) -> &'static str {
"ok"
}
let app = Router::new().route("/", get(handler));
let req = Request::builder()
.uri("/?cursor=eyJ2IjoxLCJrIjpbIjEiXS&$orderby=id%20desc")
.body(axum::body::Body::empty())
.unwrap();
let resp = app.oneshot(req).await.unwrap();
assert_eq!(resp.status(), StatusCode::UNPROCESSABLE_ENTITY);
let body = to_bytes(resp.into_body(), usize::MAX).await.unwrap();
let s = String::from_utf8_lossy(&body);
assert!(s.contains("invalid_cursor") || s.contains("cursor") || s.contains("orderby"));
}
#[tokio::test]
async fn cursor_only_is_ok() {
async fn handler(OData(_q): OData) -> &'static str {
"ok"
}
let app = Router::new().route("/", get(handler));
let req = Request::builder()
.uri("/?cursor=eyJ2IjoxLCJrIjpbIjEiXS")
.body(axum::body::Body::empty())
.unwrap();
let resp = app.oneshot(req).await.unwrap();
let body = to_bytes(resp.into_body(), usize::MAX).await.unwrap();
let s = String::from_utf8_lossy(&body);
assert!(!s.contains("orderby") || !s.contains("both"));
}
#[tokio::test]
async fn orderby_only_is_ok() {
async fn handler(OData(_q): OData) -> &'static str {
"ok"
}
let app = Router::new().route("/", get(handler));
let req = Request::builder()
.uri("/?$orderby=id%20desc")
.body(axum::body::Body::empty())
.unwrap();
let resp = app.oneshot(req).await.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
}