mod shared;
use datafusion_odata::collection::QueryParamsRaw;
use indoc::indoc;
use shared::fixture;
#[tokio::test]
async fn test_collection() {
let ctx = fixture("tickers.spy").await;
let resp = datafusion_odata::handlers::odata_collection_handler(
axum::Extension(ctx),
axum::extract::Query(QueryParamsRaw {
select: Some("offset,from_symbol,to_symbol,close".to_string()),
order_by: Some("offset asc".to_string()),
skip: None,
top: Some(2),
filter: None,
}),
axum::http::HeaderMap::new(),
)
.await
.unwrap();
pretty_assertions::assert_eq!(
*resp.body(),
indoc!(
r#"
http://example.com/odatatickers.spy
tickers.spy
2023-01-01T00:00:00.000Z
http://example.com/odatatickers.spy(0)
2023-01-01T00:00:00.000Z
0
spy
usd
135.5625
http://example.com/odatatickers.spy(1)
2023-01-01T00:00:00.000Z
1
spy
usd
134.5937
"#
)
.replace('\n', "")
);
}
///////////////////////////////////////////////////////////////////////////////
#[tokio::test]
async fn test_collection_entity_by_id() {
let ctx = fixture("tickers.spy(1)").await;
let resp = datafusion_odata::handlers::odata_collection_handler(
axum::Extension(ctx),
axum::extract::Query(QueryParamsRaw {
select: Some("offset,close".to_string()),
order_by: None,
skip: None,
top: None,
filter: None,
}),
axum::http::HeaderMap::new(),
)
.await
.unwrap();
pretty_assertions::assert_eq!(
*resp.body(),
indoc!(
r#"
http://example.com/odatatickers.spy(1)
2023-01-01T00:00:00.000Z
1
134.5937
"#
)
.replace('\n', "")
);
}
///////////////////////////////////////////////////////////////////////////////
#[tokio::test]
async fn test_collection_entity_by_id_not_found() {
let ctx = fixture("tickers.spy(999999)").await;
let resp = datafusion_odata::handlers::odata_collection_handler(
axum::Extension(ctx),
axum::extract::Query(QueryParamsRaw {
select: Some("offset,close".to_string()),
order_by: None,
skip: None,
top: None,
filter: None,
}),
axum::http::HeaderMap::new(),
)
.await
.unwrap();
assert_eq!(resp.status(), http::StatusCode::NOT_FOUND);
}
///////////////////////////////////////////////////////////////////////////////
#[tokio::test]
async fn test_collection_with_filter() {
let ctx = fixture("tickers.spy").await;
let resp = datafusion_odata::handlers::odata_collection_handler(
axum::Extension(ctx),
axum::extract::Query(QueryParamsRaw {
select: Some("offset,close".to_string()),
order_by: Some("offset asc".to_string()),
skip: None,
top: None,
filter: Some("offset eq 0".parse().unwrap()),
}),
axum::http::HeaderMap::new(),
)
.await
.unwrap();
pretty_assertions::assert_eq!(
*resp.body(),
indoc!(
r#"
http://example.com/odatatickers.spy
tickers.spy
2023-01-01T00:00:00.000Z
http://example.com/odatatickers.spy(0)
2023-01-01T00:00:00.000Z
0
135.5625
"#
)
.replace('\n', "")
);
}