Skip to content

Commit 89d0e6b

Browse files
committed
tests: add tests for id deserialization from integer
Signed-off-by: William Findlay <william@williamfindlay.com>
1 parent fdc983c commit 89d0e6b

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

graphql_client/tests/int_id.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use graphql_client::*;
2+
use serde_json::json;
3+
4+
#[derive(GraphQLQuery)]
5+
#[graphql(
6+
schema_path = "tests/more_derives/schema.graphql",
7+
query_path = "tests/more_derives/query.graphql",
8+
response_derives = "Debug, PartialEq, Eq, std::cmp::PartialOrd"
9+
)]
10+
pub struct MoreDerives;
11+
12+
#[test]
13+
fn int_id() {
14+
let response1 = json!({
15+
"currentUser": {
16+
"id": 1,
17+
"name": "Don Draper",
18+
}
19+
});
20+
21+
let response2 = json!({
22+
"currentUser": {
23+
"id": "2",
24+
"name": "Peggy Olson",
25+
}
26+
});
27+
28+
let res1 = serde_json::from_value::<more_derives::ResponseData>(response1)
29+
.expect("should deserialize");
30+
assert_eq!(
31+
res1.current_user.expect("res1 current user").id,
32+
Some("1".into())
33+
);
34+
35+
let res2 = serde_json::from_value::<more_derives::ResponseData>(response2)
36+
.expect("should deserialize");
37+
assert_eq!(
38+
res2.current_user.expect("res2 current user").id,
39+
Some("2".into())
40+
);
41+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
query MoreDerives {
2+
currentUser {
3+
name
4+
id
5+
}
6+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
schema {
2+
query: TestQuery
3+
}
4+
5+
type TestQuery {
6+
currentUser: TestUser
7+
}
8+
9+
type TestUser {
10+
name: String
11+
id: ID
12+
}

0 commit comments

Comments
 (0)