Skip to content

Commit

Permalink
Add test for checking ordering of customers
Browse files Browse the repository at this point in the history
Remove outlier changes for different PR

Fix outlier to have correct pagination

Remove outlier reverse changes

Remove outlier changes in CHANGELOG

Add more cases for customers
  • Loading branch information
marioCluml committed Feb 28, 2024
1 parent 57b0e98 commit 153b5a1
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Versioning](https://semver.org/spec/v2.0.0.html).

- Add `apply_target_id` field to `Node` struct for reverting node status.
- Add `apply_in_progress` field to `Node` struct for reverting node status.
- Add a unit test to `customers` to check the ordering of the edges returned.

### Fixed

Expand Down
174 changes: 174 additions & 0 deletions src/graphql/customer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,180 @@ pub async fn broadcast_customer_networks(
mod tests {
use crate::graphql::TestSchema;

#[tokio::test]
async fn check_customer_ordering() {
let schema = TestSchema::new().await;
let res = schema
.execute(r#"{customerList{edges{node{name}}totalCount}}"#)
.await;
assert_eq!(
res.data.to_string(),
r#"{customerList: {edges: [],totalCount: 0}}"#
);

let res = schema
.execute(
r#"mutation {
insertCustomer(name: "t1", description: "", networks: [])
}"#,
)
.await;
assert_eq!(res.data.to_string(), r#"{insertCustomer: "0"}"#);

let res = schema
.execute(
r#"mutation {
insertCustomer(name: "t2", description: "", networks: [])
}"#,
)
.await;
assert_eq!(res.data.to_string(), r#"{insertCustomer: "1"}"#);

let res = schema
.execute(
r#"mutation {
insertCustomer(name: "t3", description: "", networks: [])
}"#,
)
.await;
assert_eq!(res.data.to_string(), r#"{insertCustomer: "2"}"#);

let res = schema
.execute(
r#"mutation {
insertCustomer(name: "t4", description: "", networks: [])
}"#,
)
.await;
assert_eq!(res.data.to_string(), r#"{insertCustomer: "3"}"#);

let res = schema
.execute(
r#"mutation {
insertCustomer(name: "t5", description: "", networks: [])
}"#,
)
.await;
assert_eq!(res.data.to_string(), r#"{insertCustomer: "4"}"#);

let res = schema
.execute(
r#"mutation {
insertCustomer(name: "t6", description: "", networks: [])
}"#,
)
.await;
assert_eq!(res.data.to_string(), r#"{insertCustomer: "5"}"#);

let res = schema
.execute(
r#"mutation {
insertCustomer(name: "t7", description: "", networks: [])
}"#,
)
.await;
assert_eq!(res.data.to_string(), r#"{insertCustomer: "6"}"#);

let res = schema
.execute(
r#"mutation {
insertCustomer(name: "t8", description: "", networks: [])
}"#,
)
.await;
assert_eq!(res.data.to_string(), r#"{insertCustomer: "7"}"#);

let res = schema
.execute(
r#"mutation {
insertCustomer(name: "t9", description: "", networks: [])
}"#,
)
.await;
assert_eq!(res.data.to_string(), r#"{insertCustomer: "8"}"#);

let res = schema
.execute(
r#"mutation {
insertCustomer(name: "t10", description: "", networks: [])
}"#,
)
.await;
assert_eq!(res.data.to_string(), r#"{insertCustomer: "9"}"#);

let res = schema
.execute(r#"{customerList(last: 10){edges{node{name}}totalCount}}"#)
.await;
assert_eq!(
res.data.to_string(),
r#"{customerList: {edges: [{node: {name: "t1"}},{node: {name: "t10"}},{node: {name: "t2"}},{node: {name: "t3"}},{node: {name: "t4"}},{node: {name: "t5"}},{node: {name: "t6"}},{node: {name: "t7"}},{node: {name: "t8"}},{node: {name: "t9"}}],totalCount: 10}}"#
);

let res = schema
.execute(r#"{customerList(last: 10, before: "dDg="){edges{node{name}}totalCount,pageInfo{startCursor}}}"#)
.await;
assert_eq!(
res.data.to_string(),
r#"{customerList: {edges: [{node: {name: "t1"}},{node: {name: "t10"}},{node: {name: "t2"}},{node: {name: "t3"}},{node: {name: "t4"}},{node: {name: "t5"}},{node: {name: "t6"}},{node: {name: "t7"}}],totalCount: 10,pageInfo: {startCursor: "dDE="}}}"#
);

let res = schema
.execute(
r#"{customerList(last: 10, after: "dDc="){edges{node{name}}totalCount,pageInfo{startCursor}}}"#,
)
.await;
assert_eq!(
res.data.to_string(),
r#"{customerList: {edges: [{node: {name: "t8"}},{node: {name: "t9"}}],totalCount: 10,pageInfo: {startCursor: "dDg="}}}"#
);

let res = schema
.execute(
r#"{customerList(first:10 after:"dDc=" ){edges{node{name}}totalCount,pageInfo{endCursor}}}"#,
)
.await;
assert_eq!(
res.data.to_string(),
r#"{customerList: {edges: [{node: {name: "t8"}},{node: {name: "t9"}}],totalCount: 10,pageInfo: {endCursor: "dDk="}}}"#
);

let res = schema
.execute(
r#"{customerList(first:10 before:"dDc=" ){edges{node{name}}totalCount,pageInfo{endCursor}}}"#,
)
.await;
assert_eq!(
res.data.to_string(),
r#"{customerList: {edges: [{node: {name: "t1"}},{node: {name: "t10"}},{node: {name: "t2"}},{node: {name: "t3"}},{node: {name: "t4"}},{node: {name: "t5"}},{node: {name: "t6"}}],totalCount: 10,pageInfo: {endCursor: "dDY="}}}"#
);

let res = schema
.execute(r#"{customerList(first:10){edges{node{name}}totalCount}}"#)
.await;
assert_eq!(
res.data.to_string(),
r#"{customerList: {edges: [{node: {name: "t1"}},{node: {name: "t10"}},{node: {name: "t2"}},{node: {name: "t3"}},{node: {name: "t4"}},{node: {name: "t5"}},{node: {name: "t6"}},{node: {name: "t7"}},{node: {name: "t8"}},{node: {name: "t9"}}],totalCount: 10}}"#
);

let res = schema
.execute(
r#"mutation { removeCustomers(ids: ["0","1","2","3","4","5","6","7","8","9"]) }"#,
)
.await;
assert_eq!(
res.data.to_string(),
r#"{removeCustomers: ["t1","t2","t3","t4","t5","t6","t7","t8","t9","t10"]}"#
);

let res = schema
.execute(r#"{customerList{edges{node{name}}totalCount}}"#)
.await;
assert_eq!(
res.data.to_string(),
r#"{customerList: {edges: [],totalCount: 0}}"#
);
}

#[tokio::test]
async fn remove_customers() {
let schema = TestSchema::new().await;
Expand Down

0 comments on commit 153b5a1

Please sign in to comment.