Skip to content

Commit

Permalink
fix: tests for delete
Browse files Browse the repository at this point in the history
  • Loading branch information
jayy-lmao committed Nov 6, 2024
1 parent 1f7a9d8 commit 9ab34aa
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 21 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/modules/delete_query_builder/delete_query_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
}
Expand All @@ -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(())
}
}
}
Expand Down
27 changes: 15 additions & 12 deletions src/modules/delete_query_builder/test_delete_query_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,24 @@ impl UserDbSetDeleteQueryBuilder<Set, NotSet> {
pub async fn delete<'e, E: sqlx::PgExecutor<'e>>(
self,
executor: E,
) -> Result<User, sqlx::Error> {
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<NotSet, Set> {
pub async fn delete<'e, E: sqlx::PgExecutor<'e>>(
self,
executor: E,
) -> Result<User, sqlx::Error> {
) -> 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(())
}
}
Expand Down Expand Up @@ -150,12 +152,13 @@ impl TagDbSetDeleteQueryBuilder<Set> {
pub async fn delete<'e, E: sqlx::PgExecutor<'e>>(
self,
executor: E,
) -> Result<Tag, sqlx::Error> {
) -> 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(())
}
}
Expand Down Expand Up @@ -234,14 +237,14 @@ impl FavouritedProductDbSetDeleteQueryBuilder<Set, Set, NotSet> {
pub async fn delete<'e, E: sqlx::PgExecutor<'e>>(
self,
executor: E,
) -> Result<FavouritedProduct, sqlx::Error> {
) -> 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(())
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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");

Expand All @@ -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");

Expand Down

0 comments on commit 9ab34aa

Please sign in to comment.