-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtests.rs
35 lines (28 loc) · 1.01 KB
/
tests.rs
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
use anyhow::Result;
use axum::{
body::Body,
http::{self, Request, StatusCode},
};
use cynic::QueryBuilder;
use http_body_util::BodyExt; // for `collect`
use serde_json as json;
use tin::route::app;
use tower::util::ServiceExt;
use super::{graphql::queries::MetaQuery, schema::MetaResponse};
#[tokio::test]
async fn meta() -> Result<()> {
let app = app().await?;
let query = MetaQuery::build(());
let request = Request::builder()
.method(http::Method::POST)
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.uri("/graphql")
.body(Body::from(json::to_string(&query)?))?;
let response = app.oneshot(request).await?;
assert_eq!(response.status(), StatusCode::OK);
let body = response.into_body().collect().await?.to_bytes();
let meta_response: MetaResponse = json::from_slice(&body)?;
let cargo_package_version = env!("CARGO_PKG_VERSION").to_string();
assert_eq!(meta_response.data.meta.version, cargo_package_version);
Ok(())
}