From 2e65a2501a79f757f0f29ba5743fc9097ba3b0a7 Mon Sep 17 00:00:00 2001 From: Panagiotis Karatakis Date: Fri, 28 Jul 2023 17:04:50 +0300 Subject: [PATCH] Add update mutation tests --- examples/mysql/tests/mutation_tests.rs | 179 +++++++++++++++++++++ examples/postgres/tests/mutation_tests.rs | 181 +++++++++++++++++++++- examples/sqlite/tests/mutation_tests.rs | 179 +++++++++++++++++++++ 3 files changed, 538 insertions(+), 1 deletion(-) diff --git a/examples/mysql/tests/mutation_tests.rs b/examples/mysql/tests/mutation_tests.rs index 73e0b407..b0c4e2e3 100644 --- a/examples/mysql/tests/mutation_tests.rs +++ b/examples/mysql/tests/mutation_tests.rs @@ -359,3 +359,182 @@ async fn test_create_batch_mutation() { "#, ) } + +#[tokio::test] +async fn test_update_mutation() { + let schema = get_schema().await; + + assert_eq( + schema + .execute( + r#" + { + country(pagination: { page: { limit: 10, page: 0 } }) { + nodes { + country + countryId + } + } + } + "#, + ) + .await, + r#" + { + "country": { + "nodes": [ + { + "country": "Afghanistan", + "countryId": 1 + }, + { + "country": "Algeria", + "countryId": 2 + }, + { + "country": "American Samoa", + "countryId": 3 + }, + { + "country": "Angola", + "countryId": 4 + }, + { + "country": "Anguilla", + "countryId": 5 + }, + { + "country": "Argentina", + "countryId": 6 + }, + { + "country": "Armenia", + "countryId": 7 + }, + { + "country": "Australia", + "countryId": 8 + }, + { + "country": "Austria", + "countryId": 9 + }, + { + "country": "Azerbaijan", + "countryId": 10 + } + ] + } + } + "#, + ); + + assert_eq( + schema + .execute( + r#" + mutation { + countryUpdate( + data: { country: "[DELETED]" } + filter: { countryId: { lt: 6 } } + ) { + countryId + country + } + } + "#, + ) + .await, + r#" + { + "countryUpdate": [ + { + "countryId": 1, + "country": "[DELETED]" + }, + { + "countryId": 2, + "country": "[DELETED]" + }, + { + "countryId": 3, + "country": "[DELETED]" + }, + { + "countryId": 4, + "country": "[DELETED]" + }, + { + "countryId": 5, + "country": "[DELETED]" + } + ] + } + "#, + ); + + assert_eq( + schema + .execute( + r#" + { + country(pagination: { page: { limit: 10, page: 0 } }) { + nodes { + country + countryId + } + } + } + "#, + ) + .await, + r#" + { + "country": { + "nodes": [ + { + "country": "[DELETED]", + "countryId": 1 + }, + { + "country": "[DELETED]", + "countryId": 2 + }, + { + "country": "[DELETED]", + "countryId": 3 + }, + { + "country": "[DELETED]", + "countryId": 4 + }, + { + "country": "[DELETED]", + "countryId": 5 + }, + { + "country": "Argentina", + "countryId": 6 + }, + { + "country": "Armenia", + "countryId": 7 + }, + { + "country": "Australia", + "countryId": 8 + }, + { + "country": "Austria", + "countryId": 9 + }, + { + "country": "Azerbaijan", + "countryId": 10 + } + ] + } + } + "#, + ); +} diff --git a/examples/postgres/tests/mutation_tests.rs b/examples/postgres/tests/mutation_tests.rs index 5a8ceeb0..7d7da73c 100644 --- a/examples/postgres/tests/mutation_tests.rs +++ b/examples/postgres/tests/mutation_tests.rs @@ -62,7 +62,7 @@ async fn test_simple_insert_one() { filmActorCreateOne(data: { actorId: 1, filmId: 2, lastUpdate: "2030-01-01 11:11:11"}) { actorId filmId - __typename + __typename } } "#, @@ -361,3 +361,182 @@ async fn test_create_batch_mutation() { "#, ) } + +#[tokio::test] +async fn test_update_mutation() { + let schema = get_schema().await; + + assert_eq( + schema + .execute( + r#" + { + country(pagination: { page: { limit: 10, page: 0 } }) { + nodes { + country + countryId + } + } + } + "#, + ) + .await, + r#" + { + "country": { + "nodes": [ + { + "country": "Afghanistan", + "countryId": 1 + }, + { + "country": "Algeria", + "countryId": 2 + }, + { + "country": "American Samoa", + "countryId": 3 + }, + { + "country": "Angola", + "countryId": 4 + }, + { + "country": "Anguilla", + "countryId": 5 + }, + { + "country": "Argentina", + "countryId": 6 + }, + { + "country": "Armenia", + "countryId": 7 + }, + { + "country": "Australia", + "countryId": 8 + }, + { + "country": "Austria", + "countryId": 9 + }, + { + "country": "Azerbaijan", + "countryId": 10 + } + ] + } + } + "#, + ); + + assert_eq( + schema + .execute( + r#" + mutation { + countryUpdate( + data: { country: "[DELETED]" } + filter: { countryId: { lt: 6 } } + ) { + countryId + country + } + } + "#, + ) + .await, + r#" + { + "countryUpdate": [ + { + "countryId": 1, + "country": "[DELETED]" + }, + { + "countryId": 2, + "country": "[DELETED]" + }, + { + "countryId": 3, + "country": "[DELETED]" + }, + { + "countryId": 4, + "country": "[DELETED]" + }, + { + "countryId": 5, + "country": "[DELETED]" + } + ] + } + "#, + ); + + assert_eq( + schema + .execute( + r#" + { + country(pagination: { page: { limit: 10, page: 0 } }) { + nodes { + country + countryId + } + } + } + "#, + ) + .await, + r#" + { + "country": { + "nodes": [ + { + "country": "[DELETED]", + "countryId": 1 + }, + { + "country": "[DELETED]", + "countryId": 2 + }, + { + "country": "[DELETED]", + "countryId": 3 + }, + { + "country": "[DELETED]", + "countryId": 4 + }, + { + "country": "[DELETED]", + "countryId": 5 + }, + { + "country": "Argentina", + "countryId": 6 + }, + { + "country": "Armenia", + "countryId": 7 + }, + { + "country": "Australia", + "countryId": 8 + }, + { + "country": "Austria", + "countryId": 9 + }, + { + "country": "Azerbaijan", + "countryId": 10 + } + ] + } + } + "#, + ); +} diff --git a/examples/sqlite/tests/mutation_tests.rs b/examples/sqlite/tests/mutation_tests.rs index 270c7098..5a24bd7c 100644 --- a/examples/sqlite/tests/mutation_tests.rs +++ b/examples/sqlite/tests/mutation_tests.rs @@ -322,3 +322,182 @@ async fn test_create_batch_mutation() { "#, ); } + +#[tokio::test] +async fn test_update_mutation() { + let schema = get_schema().await; + + assert_eq( + schema + .execute( + r#" + { + country(pagination: { page: { limit: 10, page: 0 } }) { + nodes { + country + countryId + } + } + } + "#, + ) + .await, + r#" + { + "country": { + "nodes": [ + { + "country": "Afghanistan", + "countryId": 1 + }, + { + "country": "Algeria", + "countryId": 2 + }, + { + "country": "American Samoa", + "countryId": 3 + }, + { + "country": "Angola", + "countryId": 4 + }, + { + "country": "Anguilla", + "countryId": 5 + }, + { + "country": "Argentina", + "countryId": 6 + }, + { + "country": "Armenia", + "countryId": 7 + }, + { + "country": "Australia", + "countryId": 8 + }, + { + "country": "Austria", + "countryId": 9 + }, + { + "country": "Azerbaijan", + "countryId": 10 + } + ] + } + } + "#, + ); + + assert_eq( + schema + .execute( + r#" + mutation { + countryUpdate( + data: { country: "[DELETED]" } + filter: { countryId: { lt: 6 } } + ) { + countryId + country + } + } + "#, + ) + .await, + r#" + { + "countryUpdate": [ + { + "countryId": 1, + "country": "[DELETED]" + }, + { + "countryId": 2, + "country": "[DELETED]" + }, + { + "countryId": 3, + "country": "[DELETED]" + }, + { + "countryId": 4, + "country": "[DELETED]" + }, + { + "countryId": 5, + "country": "[DELETED]" + } + ] + } + "#, + ); + + assert_eq( + schema + .execute( + r#" + { + country(pagination: { page: { limit: 10, page: 0 } }) { + nodes { + country + countryId + } + } + } + "#, + ) + .await, + r#" + { + "country": { + "nodes": [ + { + "country": "[DELETED]", + "countryId": 1 + }, + { + "country": "[DELETED]", + "countryId": 2 + }, + { + "country": "[DELETED]", + "countryId": 3 + }, + { + "country": "[DELETED]", + "countryId": 4 + }, + { + "country": "[DELETED]", + "countryId": 5 + }, + { + "country": "Argentina", + "countryId": 6 + }, + { + "country": "Armenia", + "countryId": 7 + }, + { + "country": "Australia", + "countryId": 8 + }, + { + "country": "Austria", + "countryId": 9 + }, + { + "country": "Azerbaijan", + "countryId": 10 + } + ] + } + } + "#, + ); +}