From 71086e97964470b8cc1f1456a1fe5fd46c5c5120 Mon Sep 17 00:00:00 2001 From: Panagiotis Karatakis Date: Tue, 4 Oct 2022 21:41:03 +0300 Subject: [PATCH] Update tests and postgres example --- examples/mysql/tests/query_tests.rs | 231 +++++++++++++++++++++++++ examples/postgres/.env | 3 + examples/postgres/tests/query_tests.rs | 231 +++++++++++++++++++++++++ examples/sqlite/tests/query_tests.rs | 175 ++++++++++++++++++- 4 files changed, 637 insertions(+), 3 deletions(-) create mode 100644 examples/postgres/.env diff --git a/examples/mysql/tests/query_tests.rs b/examples/mysql/tests/query_tests.rs index b63cbf3b..ec8ae842 100644 --- a/examples/mysql/tests/query_tests.rs +++ b/examples/mysql/tests/query_tests.rs @@ -197,3 +197,234 @@ async fn test_complex_filter_with_pagination() { "#, ) } + +#[tokio::test] +async fn test_cursor_pagination() { + let schema = get_schema().await; + + assert_eq( + schema + .execute( + r#" + { + paymentCursor(filters: {amount: {gt: "11"}}, cursor: {limit: 5}) { + edges { + node { + paymentId + amount + customer { + firstName + } + } + } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } + } + } + "#, + ) + .await, + r#" + { + "paymentCursor": { + "edges": [ + { + "node": { + "paymentId": 342, + "amount": "11.99", + "customer": { + "firstName": "KAREN" + } + } + }, + { + "node": { + "paymentId": 3146, + "amount": "11.99", + "customer": { + "firstName": "VICTORIA" + } + } + }, + { + "node": { + "paymentId": 5280, + "amount": "11.99", + "customer": { + "firstName": "VANESSA" + } + } + }, + { + "node": { + "paymentId": 5281, + "amount": "11.99", + "customer": { + "firstName": "ALMA" + } + } + }, + { + "node": { + "paymentId": 5550, + "amount": "11.99", + "customer": { + "firstName": "ROSEMARY" + } + } + } + ], + "pageInfo": { + "hasPreviousPage": false, + "hasNextPage": true, + "startCursor": "SmallUnsigned[3]:342", + "endCursor": "SmallUnsigned[4]:5550" + } + } + } + "#, + ) +} + +#[tokio::test] +async fn test_cursor_pagination_prev() { + let schema = get_schema().await; + + assert_eq( + schema + .execute( + r#" + { + paymentCursor(filters: {amount: {gt: "11"}}, cursor: {limit: 3, cursor: "SmallUnsigned[4]:5550"}) { + edges { + node { + paymentId + amount + customer { + firstName + } + } + } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } + } + } + "#, + ) + .await, + r#" + { + "paymentCursor": { + "edges": [ + { + "node": { + "paymentId": 6409, + "amount": "11.99", + "customer": { + "firstName": "TANYA" + } + } + }, + { + "node": { + "paymentId": 8272, + "amount": "11.99", + "customer": { + "firstName": "RICHARD" + } + } + }, + { + "node": { + "paymentId": 9803, + "amount": "11.99", + "customer": { + "firstName": "NICHOLAS" + } + } + } + ], + "pageInfo": { + "hasPreviousPage": true, + "hasNextPage": true, + "startCursor": "SmallUnsigned[4]:6409", + "endCursor": "SmallUnsigned[4]:9803" + } + } + } + "#, + ) +} + +#[tokio::test] +async fn test_cursor_pagination_no_next() { + let schema = get_schema().await; + + assert_eq( + schema + .execute( + r#" + { + paymentCursor(filters: {amount: {gt: "11"}}, cursor: {limit: 3, cursor: "SmallUnsigned[4]:9803"}) { + edges { + node { + paymentId + amount + customer { + firstName + } + } + } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } + } + } + "#, + ) + .await, + r#" + { + "paymentCursor": { + "edges": [ + { + "node": { + "paymentId": 15821, + "amount": "11.99", + "customer": { + "firstName": "KENT" + } + } + }, + { + "node": { + "paymentId": 15850, + "amount": "11.99", + "customer": { + "firstName": "TERRANCE" + } + } + } + ], + "pageInfo": { + "hasPreviousPage": true, + "hasNextPage": false, + "startCursor": "SmallUnsigned[5]:15821", + "endCursor": "SmallUnsigned[5]:15850" + } + } + } + "#, + ) +} diff --git a/examples/postgres/.env b/examples/postgres/.env new file mode 100644 index 00000000..869d217e --- /dev/null +++ b/examples/postgres/.env @@ -0,0 +1,3 @@ +DATABASE_URL="postgres://postgres:postgres@127.0.0.1/sakila?currentSchema=public" +# COMPLEXITY_LIMIT= +# DEPTH_LIMIT= \ No newline at end of file diff --git a/examples/postgres/tests/query_tests.rs b/examples/postgres/tests/query_tests.rs index 66e97488..43feeb38 100644 --- a/examples/postgres/tests/query_tests.rs +++ b/examples/postgres/tests/query_tests.rs @@ -197,3 +197,234 @@ async fn test_complex_filter_with_pagination() { "#, ) } + +#[tokio::test] +async fn test_cursor_pagination() { + let schema = get_schema().await; + + assert_eq( + schema + .execute( + r#" + { + paymentCursor(filters: {amount: {gt: "11"}}, cursor: {limit: 5}) { + edges { + node { + paymentId + amount + customer { + firstName + } + } + } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } + } + } + "#, + ) + .await, + r#" + { + "paymentCursor": { + "edges": [ + { + "node": { + "paymentId": 342, + "amount": "11.9900", + "customer": { + "firstName": "KAREN" + } + } + }, + { + "node": { + "paymentId": 3146, + "amount": "11.9900", + "customer": { + "firstName": "VICTORIA" + } + } + }, + { + "node": { + "paymentId": 5280, + "amount": "11.9900", + "customer": { + "firstName": "VANESSA" + } + } + }, + { + "node": { + "paymentId": 5281, + "amount": "11.9900", + "customer": { + "firstName": "ALMA" + } + } + }, + { + "node": { + "paymentId": 5550, + "amount": "11.9900", + "customer": { + "firstName": "ROSEMARY" + } + } + } + ], + "pageInfo": { + "hasPreviousPage": false, + "hasNextPage": true, + "startCursor": "Int[3]:342", + "endCursor": "Int[4]:5550" + } + } + } + "#, + ) +} + +#[tokio::test] +async fn test_cursor_pagination_prev() { + let schema = get_schema().await; + + assert_eq( + schema + .execute( + r#" + { + paymentCursor(filters: {amount: {gt: "11"}}, cursor: {limit: 3, cursor: "SmallUnsigned[4]:5550"}) { + edges { + node { + paymentId + amount + customer { + firstName + } + } + } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } + } + } + "#, + ) + .await, + r#" + { + "paymentCursor": { + "edges": [ + { + "node": { + "paymentId": 6409, + "amount": "11.9900", + "customer": { + "firstName": "TANYA" + } + } + }, + { + "node": { + "paymentId": 8272, + "amount": "11.9900", + "customer": { + "firstName": "RICHARD" + } + } + }, + { + "node": { + "paymentId": 9803, + "amount": "11.9900", + "customer": { + "firstName": "NICHOLAS" + } + } + } + ], + "pageInfo": { + "hasPreviousPage": true, + "hasNextPage": true, + "startCursor": "Int[4]:6409", + "endCursor": "Int[4]:9803" + } + } + } + "#, + ) +} + +#[tokio::test] +async fn test_cursor_pagination_no_next() { + let schema = get_schema().await; + + assert_eq( + schema + .execute( + r#" + { + paymentCursor(filters: {amount: {gt: "11"}}, cursor: {limit: 3, cursor: "SmallUnsigned[4]:9803"}) { + edges { + node { + paymentId + amount + customer { + firstName + } + } + } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } + } + } + "#, + ) + .await, + r#" + { + "paymentCursor": { + "edges": [ + { + "node": { + "paymentId": 15821, + "amount": "11.9900", + "customer": { + "firstName": "KENT" + } + } + }, + { + "node": { + "paymentId": 15850, + "amount": "11.9900", + "customer": { + "firstName": "TERRANCE" + } + } + } + ], + "pageInfo": { + "hasPreviousPage": true, + "hasNextPage": false, + "startCursor": "Int[5]:15821", + "endCursor": "Int[5]:15850" + } + } + } + "#, + ) +} diff --git a/examples/sqlite/tests/query_tests.rs b/examples/sqlite/tests/query_tests.rs index 58250eef..e538713f 100644 --- a/examples/sqlite/tests/query_tests.rs +++ b/examples/sqlite/tests/query_tests.rs @@ -205,7 +205,7 @@ async fn test_cursor_pagination() { .execute( r#" { - tracksCursor(cursor:{limit: 4, cursor: "Int[4]:2822"}, filters:{milliseconds: { gt: 2573031}}) { + tracksCursor(cursor:{limit: 5}, filters:{milliseconds: { gt: 2573031}}) { edges { node { trackId @@ -214,6 +214,12 @@ async fn test_cursor_pagination() { } cursor } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } } } "#, @@ -223,6 +229,38 @@ async fn test_cursor_pagination() { { "tracksCursor": { "edges": [ + { + "node": { + "trackId": 2819, + "name": "Battlestar Galactica: The Story So Far", + "milliseconds": 2622250 + }, + "cursor": "Int[4]:2819" + }, + { + "node": { + "trackId": 2820, + "name": "Occupation / Precipice", + "milliseconds": 5286953 + }, + "cursor": "Int[4]:2820" + }, + { + "node": { + "trackId": 2821, + "name": "Exodus, Pt. 1", + "milliseconds": 2621708 + }, + "cursor": "Int[4]:2821" + }, + { + "node": { + "trackId": 2822, + "name": "Exodus, Pt. 2", + "milliseconds": 2618000 + }, + "cursor": "Int[4]:2822" + }, { "node": { "trackId": 2823, @@ -230,7 +268,53 @@ async fn test_cursor_pagination() { "milliseconds": 2626626 }, "cursor": "Int[4]:2823" - }, + } + ], + "pageInfo": { + "hasPreviousPage": false, + "hasNextPage": true, + "startCursor": "Int[4]:2819", + "endCursor": "Int[4]:2823" + } + } + } + "#, + ) +} + +#[tokio::test] +async fn test_cursor_pagination_prev() { + let schema = get_schema().await; + + assert_eq( + schema + .execute( + r#" + { + tracksCursor(cursor:{limit: 5, cursor: "Int[4]:2823"}, filters:{milliseconds: { gt: 2573031}}) { + edges { + node { + trackId + name + milliseconds + } + cursor + } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } + } + } + "#, + ) + .await, + r#" + { + "tracksCursor": { + "edges": [ { "node": { "trackId": 2824, @@ -254,10 +338,95 @@ async fn test_cursor_pagination() { "milliseconds": 2622038 }, "cursor": "Int[4]:2827" + }, + { + "node": { + "trackId": 2828, + "name": "The Passage", + "milliseconds": 2623875 + }, + "cursor": "Int[4]:2828" + }, + { + "node": { + "trackId": 2829, + "name": "The Eye of Jupiter", + "milliseconds": 2618750 + }, + "cursor": "Int[4]:2829" } - ] + ], + "pageInfo": { + "hasPreviousPage": true, + "hasNextPage": true, + "startCursor": "Int[4]:2824", + "endCursor": "Int[4]:2829" + } } } "#, ) } + +#[tokio::test] +async fn test_cursor_pagination_no_next() { + let schema = get_schema().await; + + assert_eq( + schema + .execute( + r#" + { + tracksCursor(cursor:{limit: 5, cursor: "Int[4]:3361"}, filters:{milliseconds: { gt: 2573031}}) { + edges { + node { + trackId + name + milliseconds + } + cursor + } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } + } + } + "#, + ) + .await, + r#" + { + "tracksCursor": { + "edges": [ + { + "node": { + "trackId": 3362, + "name": "There's No Place Like Home, Pt. 1", + "milliseconds": 2609526 + }, + "cursor": "Int[4]:3362" + }, + { + "node": { + "trackId": 3364, + "name": "There's No Place Like Home, Pt. 3", + "milliseconds": 2582957 + }, + "cursor": "Int[4]:3364" + } + ], + "pageInfo": { + "hasPreviousPage": true, + "hasNextPage": false, + "startCursor": "Int[4]:3362", + "endCursor": "Int[4]:3364" + } + } + } + "#, + ) +} +