Skip to content

Commit b6fd857

Browse files
committed
Move test into model (#19)
1 parent dbc7040 commit b6fd857

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

src/handlers.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,3 @@ pub async fn graphql_handler<T: Client + Send + Sync + 'static>(
1919
pub async fn graphiql_handler() -> impl IntoResponse {
2020
Html(GraphiQLSource::build().endpoint("/graphql").finish())
2121
}
22-
23-
#[cfg(test)]
24-
mod tests {
25-
use async_graphql::{EmptyMutation, EmptySubscription, Schema};
26-
use httpmock::MockServer;
27-
use url::Url;
28-
29-
use crate::TiledQuery;
30-
use crate::clients::TiledClient;
31-
32-
#[tokio::test]
33-
async fn test_api_version_query() {
34-
let mock_server = MockServer::start();
35-
36-
let mock = mock_server
37-
.mock_async(|when, then| {
38-
when.method("GET").path("/api/v1/");
39-
then.status(200)
40-
.body_from_file("resources/tiled_metadata.json");
41-
})
42-
.await;
43-
44-
let schema = Schema::build(
45-
TiledQuery(TiledClient {
46-
address: Url::parse(&mock_server.base_url()).unwrap(),
47-
}),
48-
EmptyMutation,
49-
EmptySubscription,
50-
)
51-
.finish();
52-
53-
let response = schema.execute("{metadata { apiVersion } }").await;
54-
55-
assert_eq!(response.data.to_string(), "{metadata: {apiVersion: 0}}");
56-
mock.assert();
57-
}
58-
}

src/model.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,40 @@ impl TiledQuery {
1212
self.0.metadata().await
1313
}
1414
}
15+
16+
#[cfg(test)]
17+
mod tests {
18+
use async_graphql::{EmptyMutation, EmptySubscription, Schema};
19+
use httpmock::MockServer;
20+
use url::Url;
21+
22+
use crate::TiledQuery;
23+
use crate::clients::TiledClient;
24+
25+
#[tokio::test]
26+
async fn test_api_version_query() {
27+
let mock_server = MockServer::start();
28+
29+
let mock = mock_server
30+
.mock_async(|when, then| {
31+
when.method("GET").path("/api/v1/");
32+
then.status(200)
33+
.body_from_file("resources/tiled_metadata.json");
34+
})
35+
.await;
36+
37+
let schema = Schema::build(
38+
TiledQuery(TiledClient {
39+
address: Url::parse(&mock_server.base_url()).unwrap(),
40+
}),
41+
EmptyMutation,
42+
EmptySubscription,
43+
)
44+
.finish();
45+
46+
let response = schema.execute("{metadata { apiVersion } }").await;
47+
48+
assert_eq!(response.data.to_string(), "{metadata: {apiVersion: 0}}");
49+
mock.assert();
50+
}
51+
}

0 commit comments

Comments
 (0)