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

Change change log

Fix unreleased section to have no date
  • Loading branch information
marioCluml authored Mar 6, 2024
1 parent 8247a88 commit 2a0d0cf
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Versioning](https://semver.org/spec/v2.0.0.html).
advancements and improvements in our system, this type is no longer necessary
and has been removed to streamline the codebase and enhance overall maintainability.

### Added

- Add unit tests to `customer_list` to check ordering of nodes and edges.

## [0.18.0] - 2024-02-26

### Added
Expand Down
174 changes: 174 additions & 0 deletions src/graphql/customer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,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 2a0d0cf

Please sign in to comment.