From 9ab34aa83361efeba43c1640c5835945da4454ac Mon Sep 17 00:00:00 2001 From: James Holman Date: Wed, 6 Nov 2024 18:37:20 +1100 Subject: [PATCH] fix: tests for delete --- .github/workflows/ci.yml | 8 ++++++ .../delete_query_builder.rs | 12 ++++----- .../test_delete_query_builder.rs | 27 ++++++++++--------- ...b34e5b408bfec6c24f3044a8aae19117af6a1.json | 14 ++++++++++ tests/src/lib.rs | 6 ++--- 5 files changed, 46 insertions(+), 21 deletions(-) create mode 100644 tests/.sqlx/query-f27ad459b51bdb3c78cda0a9c13b34e5b408bfec6c24f3044a8aae19117af6a1.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 242fee9..6591490 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,11 +3,15 @@ name: Rust CI on: [push, pull_request] jobs: + + setup: name: Set up and Cache runs-on: ubuntu-latest outputs: cache-hit: ${{ steps.cache.outputs.cache-hit }} + env: + CARGO_TERM_COLOR: always steps: - name: Checkout code uses: actions/checkout@v3 @@ -30,6 +34,8 @@ jobs: name: Run Unit Tests runs-on: ubuntu-latest needs: setup + env: + CARGO_TERM_COLOR: always steps: - name: Checkout code uses: actions/checkout@v3 @@ -49,6 +55,8 @@ jobs: name: Run integration tests runs-on: ubuntu-latest needs: setup + env: + CARGO_TERM_COLOR: always steps: - name: Checkout code uses: actions/checkout@v3 diff --git a/src/modules/delete_query_builder/delete_query_builder.rs b/src/modules/delete_query_builder/delete_query_builder.rs index 6ce159d..9dec4a2 100644 --- a/src/modules/delete_query_builder/delete_query_builder.rs +++ b/src/modules/delete_query_builder/delete_query_builder.rs @@ -245,14 +245,14 @@ pub fn get_query_builder(input: &DeriveInput) -> proc_macro2::TokenStream { pub async fn delete<'e, E: sqlx::PgExecutor<'e>>( self, executor: E, - ) -> Result<#struct_name, sqlx::Error> { + ) -> Result<(), sqlx::Error> { sqlx::query!( - #struct_name, #query, #(#unique_query_args_2)* ) .execute(executor) - .await + .await?; + Ok(()) } } } @@ -273,14 +273,14 @@ pub fn get_query_builder(input: &DeriveInput) -> proc_macro2::TokenStream { pub async fn delete<'e, E: sqlx::PgExecutor<'e>>( self, executor: E, - ) -> Result<#struct_name, sqlx::Error> { + ) -> Result<(), sqlx::Error> { sqlx::query!( - #struct_name, #query, #(#key_query_args_2)* ) .execute(executor) - .await + .await?; + Ok(()) } } } diff --git a/src/modules/delete_query_builder/test_delete_query_builder.rs b/src/modules/delete_query_builder/test_delete_query_builder.rs index 9cada8c..4da243e 100644 --- a/src/modules/delete_query_builder/test_delete_query_builder.rs +++ b/src/modules/delete_query_builder/test_delete_query_builder.rs @@ -70,22 +70,24 @@ impl UserDbSetDeleteQueryBuilder { pub async fn delete<'e, E: sqlx::PgExecutor<'e>>( self, executor: E, - ) -> Result { - sqlx::query!(User, "DELETE FROM users WHERE id = $1", self.id,) + ) -> Result<(), sqlx::Error> { + sqlx::query!("DELETE FROM users WHERE id = $1", self.id,) .execute(executor) - .await + .await?; + Ok(()) } } impl UserDbSetDeleteQueryBuilder { pub async fn delete<'e, E: sqlx::PgExecutor<'e>>( self, executor: E, - ) -> Result { + ) -> Result<(), sqlx::Error> { sqlx::query!( - User, "DELETE FROM users WHERE (email = $1 OR $1 is null)", self.email, + "DELETE FROM users WHERE (email = $1 OR $1 is null)", self.email, ) .execute(executor) - .await + .await?; + Ok(()) } } @@ -150,12 +152,13 @@ impl TagDbSetDeleteQueryBuilder { pub async fn delete<'e, E: sqlx::PgExecutor<'e>>( self, executor: E, - ) -> Result { + ) -> Result<(), sqlx::Error> { sqlx::query!( - Tag, "DELETE FROM tags WHERE (tag_name = $1 OR $1 is null)", self.tag_name, + "DELETE FROM tags WHERE (tag_name = $1 OR $1 is null)", self.tag_name, ) .execute(executor) - .await + .await?; + Ok(()) } } @@ -234,14 +237,14 @@ impl FavouritedProductDbSetDeleteQueryBuilder { pub async fn delete<'e, E: sqlx::PgExecutor<'e>>( self, executor: E, - ) -> Result { + ) -> Result<(), sqlx::Error> { sqlx::query!( - FavouritedProduct, "DELETE FROM favourite_products WHERE product_id = $1 AND user_id = $2", self .product_id, self.user_id, ) .execute(executor) - .await + .await?; + Ok(()) } } diff --git a/tests/.sqlx/query-f27ad459b51bdb3c78cda0a9c13b34e5b408bfec6c24f3044a8aae19117af6a1.json b/tests/.sqlx/query-f27ad459b51bdb3c78cda0a9c13b34e5b408bfec6c24f3044a8aae19117af6a1.json new file mode 100644 index 0000000..6d601d2 --- /dev/null +++ b/tests/.sqlx/query-f27ad459b51bdb3c78cda0a9c13b34e5b408bfec6c24f3044a8aae19117af6a1.json @@ -0,0 +1,14 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM users WHERE (email = $1 OR $1 is null)", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [] + }, + "hash": "f27ad459b51bdb3c78cda0a9c13b34e5b408bfec6c24f3044a8aae19117af6a1" +} diff --git a/tests/src/lib.rs b/tests/src/lib.rs index fb4afe0..d34b1d6 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -102,7 +102,7 @@ async fn test_fetch_users_by_name() -> Result<(), String> { let users = UserDbSet::many() .name_eq("bob".to_string()) - .fetch(pool) + .fetch_all(pool) .await .expect("Could not fetch users"); @@ -117,7 +117,7 @@ async fn test_fetch_users_by_name_and_details() -> Result<(), String> { let users = UserDbSet::many() .name_eq("bob".to_string()) .details_eq("the best bob".to_string()) - .fetch(pool) + .fetch_all(pool) .await .expect("Could not fetch users"); @@ -130,7 +130,7 @@ async fn test_fetch_all_users() -> Result<(), String> { let pool = get_db_pool().await; let users = UserDbSet::many() - .fetch(pool) + .fetch_all(pool) .await .expect("Could not fetch users");