Skip to content

Conversation

@zensgit
Copy link
Owner

@zensgit zensgit commented Sep 26, 2025

  • Fix families.owner_id write and default ledger created_by/is_default
  • Align users INSERT with actual schema (name/full_name/is_active/email_verified)
  • Route /api/v1/auth/register → fixed handler
  • Add route-level e2e tests:
    • auth_register_route_e2e_test.rs: register → family/ledger assertions → export.csv header
    • auth_register_enhanced_route_e2e_test.rs: enhanced register → export.csv header
  • Refresh jive-api/.sqlx cache for SQLX_OFFLINE

Local validation

  • Docker DB on 55432; migrations applied
  • SQLX_OFFLINE=true cargo test --tests → all green
  • Foreground API with sqlx::query=trace confirms new INSERT shape

Risk/Notes

  • Touches auth handlers and family service; scope is surgical.
  • Consider removing deprecated docker-compose version field in a follow-up.

… register and enhanced register; refresh SQLx cache
@Copilot Copilot AI review requested due to automatic review settings September 26, 2025 08:23
@zensgit
Copy link
Owner Author

zensgit commented Sep 26, 2025

approve

@gemini-code-assist
Copy link

Summary of Changes

Hello @zensgit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在完善用户注册流程,确保新用户在注册时能够正确地与家庭 (family) 和默认账本 (ledger) 关联起来。它解决了数据库写入的准确性问题,更新了用户数据插入的模式,并引入了全面的端到端测试来验证注册功能的健壮性。

Highlights

  • 修复注册流程中的数据库写入: 修复了 families.owner_id 写入和默认 ledger created_by/is_default 的问题。
  • 更新用户表插入模式: 调整了 users 表的 INSERT 语句,使其与实际的 schema 对齐(增加了 name/full_name/is_active/email_verified 字段)。
  • 路由处理函数修正: 将 /api/v1/auth/register 路由指向了正确的处理函数。
  • 新增端到端测试: 为 auth_registerauth_register_enhanced 路由添加了端到端 (E2E) 测试,以验证注册流程和数据导出功能。
  • 刷新 SQLX 缓存: 刷新了 jive-api/.sqlx 缓存,以确保 SQLX_OFFLINE 模式下的正确性。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@zensgit zensgit merged commit 38f60cb into main Sep 26, 2025
7 checks passed
@zensgit zensgit deleted the feat/api-register-e2e-fixes branch September 26, 2025 08:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Fixes authentication registration flow by ensuring proper database schema alignment, adding owner_id to families, and providing comprehensive route-level e2e testing for both standard and enhanced registration endpoints.

  • Corrected families table to include owner_id and ledgers to use created_by with is_default flags
  • Updated user creation to match actual schema with name/full_name/is_active/email_verified fields
  • Added comprehensive e2e tests validating full registration flow including CSV export functionality

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
jive-api/tests/integration/mod.rs Added module declaration for new e2e test files
jive-api/tests/integration/auth_register_route_e2e_test.rs New e2e test for standard registration route with family/ledger validation
jive-api/tests/integration/auth_register_enhanced_route_e2e_test.rs New e2e test for enhanced registration route with CSV export verification
jive-api/src/services/family_service.rs Updated family creation to include owner_id and ledger creation with created_by
jive-api/src/main.rs Fixed route handler mapping from register_with_family to register
jive-api/src/handlers/enhanced_profile.rs Added error handling and logging for family creation
jive-api/src/handlers/auth.rs Restructured user/family creation with proper schema alignment and owner_id

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +135 to +136
// 先创建用户(避免 families.owner_id 外键约束失败)
tracing::info!(target: "auth_register", user_id = %user_id, family_id = %family_id, email = %final_email, "Creating user then family with owner_id");
Copy link

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The Chinese comment should be consistent with the codebase language. Consider using English: '// Create user first (to avoid families.owner_id foreign key constraint failure)'

Copilot uses AI. Check for mistakes.

.await
.map_err(|e| ApiError::DatabaseError(e.to_string()))?;

// 再创建家庭(带 owner_id)
Copy link

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The Chinese comment should be consistent with the codebase language. Consider using English: '// Then create family (with owner_id)'

Suggested change
// 再创建家庭(带 owner_id
// Then create family (with owner_id)

Copilot uses AI. Check for mistakes.

.map_err(|e| ApiError::DatabaseError(e.to_string()))?;

// 创建默认账本
// 创建默认账本(标记 is_default,记录创建者)
Copy link

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The Chinese comment should be consistent with the codebase language. Consider using English: '// Create default ledger (mark as is_default, record creator)'

Suggested change
// 创建默认账本(标记 is_default,记录创建者)
// Create default ledger (mark as is_default, record creator)

Copilot uses AI. Check for mistakes.

.await
.map_err(|e| ApiError::DatabaseError(e.to_string()))?;

// 绑定用户的当前家庭并提交事务
Copy link

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The Chinese comment should be consistent with the codebase language. Consider using English: '// Bind user's current family and commit transaction'

Suggested change
// 绑定用户的当前家庭并提交事务
// Bind user's current family and commit transaction

Copilot uses AI. Check for mistakes.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a solid improvement, correctly fixing the owner_id assignment in the registration flow and aligning database schemas. The addition of comprehensive end-to-end tests for both registration paths is a major plus, greatly increasing the reliability of these critical features. My review includes a few suggestions to improve test hygiene by ensuring proper cleanup of test data and to enhance code clarity and idiomatic error handling in one of the handlers.

Comment on lines +159 to +165
let family = match family_service.create_family(user_id, family_request).await {
Ok(f) => f,
Err(e) => {
tracing::error!(target: "enhanced_register", error=?e, user_id=%user_id, "create_family failed");
return Err(ApiError::InternalServerError);
}
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The error handling for family_service.create_family has been improved by adding logging, which is great. However, the match statement with an early return can be written more idiomatically using Result::map_err. This makes the code more concise and follows a more common pattern for error handling in Rust, improving maintainability.

Suggested change
let family = match family_service.create_family(user_id, family_request).await {
Ok(f) => f,
Err(e) => {
tracing::error!(target: "enhanced_register", error=?e, user_id=%user_id, "create_family failed");
return Err(ApiError::InternalServerError);
}
};
let family = family_service
.create_family(user_id, family_request)
.await
.map_err(|e| {
tracing::error!(target: "enhanced_register", error=?e, user_id=%user_id, "create_family failed");
ApiError::InternalServerError
})?;

let resp2 = app.clone().oneshot(req2).await.unwrap();
assert_eq!(resp2.status(), StatusCode::OK);
let body_bytes = hyper::body::to_bytes(resp2.into_body()).await.unwrap();
assert!(body_bytes.starts_with(b"Date,Description"), "CSV header missing or incorrect");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This test creates a user but doesn't clean it up afterwards. This can pollute the test database and cause other tests to fail on subsequent runs. To ensure test isolation and reliability, the created user should be deleted at the end of the test, similar to how it's done in auth_register_route_e2e_test.rs.

        assert!(body_bytes.starts_with(b"Date,Description"), "CSV header missing or incorrect");

        // Cleanup user to prevent polluting the test database
        let user_id_val = v.pointer("/data/user_id").expect("user_id not in response");
        let user_id: Uuid = serde_json::from_value(user_id_val.clone()).expect("user_id is not a valid UUID");
        sqlx::query("DELETE FROM users WHERE id = $1")
            .bind(user_id)
            .execute(&pool)
            .await
            .expect("Failed to clean up user after test");

Comment on lines +87 to +90
let _ = sqlx::query("DELETE FROM users WHERE id = $1")
.bind(user_id)
.execute(&pool)
.await;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The result of the database query for cleaning up the test user is not handled. This could lead to silent failures in test cleanup, causing subsequent test runs to fail due to data conflicts. It's better to handle the Result explicitly, for example by using .expect(), to ensure that cleanup failures are immediately visible.

        sqlx::query("DELETE FROM users WHERE id = $1")
            .bind(user_id)
            .execute(&pool)
            .await
            .expect("Failed to clean up test user");

@zensgit zensgit mentioned this pull request Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant