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 committed Feb 28, 2024
1 parent 19ed5c5 commit ac945f7
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ file is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and
this project adheres to [Semantic
Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

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

## [0.18.0] - 2024-02-26

### Added
Expand Down Expand Up @@ -405,6 +411,7 @@ Versioning](https://semver.org/spec/v2.0.0.html).

- An initial version.

[Unreleased]: https://github.com/aicers/review-web/compare/0.18.0...main
[0.18.0]: https://github.com/aicers/review-web/compare/0.17.0...0.18.0
[0.17.0]: https://github.com/aicers/review-web/compare/0.16.0...0.17.0
[0.16.0]: https://github.com/aicers/review-web/compare/0.15.0...0.16.0
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 ac945f7

Please sign in to comment.