test(p3-1): 第二十五波 - 绑定联系方式+微信同步 use case 35个单测 #731

Merged
xiaoxia merged 2 commits from test/p3-1-wave25-bind-contact-wechat-sync-tests into develop 2026-07-23 00:25:25 +08:00
Owner

P3-1 单元测试补充 - 第二十五波

新增测试文件

  • tests/unit/test_auth_bind_wechat_sync.py — 35个测试

覆盖范围

BindContactUseCase (18个)

  • 手机绑定成功、邮箱绑定成功、同时绑定手机+邮箱
  • 绑定完成判定(真实邮箱 vs wechat.local)
  • 空手机号+空邮箱、用户不存在、手机号格式错误、邮箱格式错误
  • 缺少手机验证码、缺少邮箱验证码
  • 手机号已被其他账号绑定、邮箱已被其他账号绑定
  • 同账号重绑自己手机(无冲突)
  • 手机验证码错误、邮箱验证码错误、异常处理

SendVerificationCodeUseCase (10个)

  • 手机验证码发送成功、邮箱验证码发送成功
  • 手机号格式错误、邮箱格式错误、不支持的目标类型
  • 邮箱recipient自动转小写、无SMS服务仍返回成功
  • 异常处理、to_dict输出格式

WechatSyncUseCase (7个)

  • openid登录、unionid查找并绑定openid、新用户创建
  • 空openid、默认昵称、用户名冲突加后缀
  • to_dict兼容字段(token别名)、JWT claims验证、异常处理

累计

  • 第二十五波:35个
  • 累计:约1365+个单测
## P3-1 单元测试补充 - 第二十五波 ### 新增测试文件 - `tests/unit/test_auth_bind_wechat_sync.py` — 35个测试 ### 覆盖范围 **BindContactUseCase (18个)** - 手机绑定成功、邮箱绑定成功、同时绑定手机+邮箱 - 绑定完成判定(真实邮箱 vs wechat.local) - 空手机号+空邮箱、用户不存在、手机号格式错误、邮箱格式错误 - 缺少手机验证码、缺少邮箱验证码 - 手机号已被其他账号绑定、邮箱已被其他账号绑定 - 同账号重绑自己手机(无冲突) - 手机验证码错误、邮箱验证码错误、异常处理 **SendVerificationCodeUseCase (10个)** - 手机验证码发送成功、邮箱验证码发送成功 - 手机号格式错误、邮箱格式错误、不支持的目标类型 - 邮箱recipient自动转小写、无SMS服务仍返回成功 - 异常处理、to_dict输出格式 **WechatSyncUseCase (7个)** - openid登录、unionid查找并绑定openid、新用户创建 - 空openid、默认昵称、用户名冲突加后缀 - to_dict兼容字段(token别名)、JWT claims验证、异常处理 ### 累计 - 第二十五波:35个 - 累计:约1365+个单测
xiaoxia added 1 commit 2026-07-22 18:34:32 +08:00
test(p3-1): add 35 unit tests for bind_contact + wechat_sync use cases
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 39s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 55s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 53s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 56s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m24s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 2m34s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Failing after 1m16s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 1m20s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 57s
AI Code Review / AI Code Review (pull_request) Successful in 8m44s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 12m22s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Successful in 1m30s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Failing after 2m58s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 29m50s
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
e41484664e
Covers:
- BindContactUseCase (18 cases): phone bind, email bind, both bind,
  binding complete/incomplete, empty fields, user not found, invalid
  phone/email, missing codes, already bound to other user, same user
  rebind, verification failed, exception handling
- SendVerificationCodeUseCase (10 cases): phone send, email send,
  invalid phone/email, unsupported target, email lowercased, no sms
  service, exception handling, to_dict output
- WechatSyncUseCase (7 cases): openid login, unionid bind+login,
  new user creation, empty openid, default nickname, username
  uniqueness suffix, to_dict compat, JWT claims, exception handling
xiaoxia force-pushed test/p3-1-wave25-bind-contact-wechat-sync-tests from 06785d6828 to e41484664e 2026-07-22 18:38:00 +08:00 Compare

🚀 预览环境已部署

项目 详情
PR号 #731
预览链接 https://pr-731.preview.xiaoxiajianji.com
API环境 staging

💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。

🔄 每次提交新代码后预览环境会自动更新。

🗑️ PR 关闭或合并后,预览环境会自动清理。

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #731 | | 预览链接 | [https://pr-731.preview.xiaoxiajianji.com](https://pr-731.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
xiaoxia added 1 commit 2026-07-22 22:26:50 +08:00
style: black format fix
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m4s
AI Code Review / AI Code Review (pull_request) Successful in 8m16s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Failing after 2m39s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 5m2s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 3m7s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2m19s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m41s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 2m19s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 2m51s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 2m34s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 56s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 4m19s
CI/CD Pipeline / Integration Tests (pull_request) Failing after 4m55s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 17m54s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 24m31s
56b7cbfa51
Collaborator

代码审查结果 - PR #731

⚠️ 问题(0个需要修改)

💡 建议(2个可选)

  1. tests/unit/test_auth_bind_wechat_sync.py 第283行:存在无效代码(Dead Code)

    • test_phone_already_bound_to_other_user 方法中,先实例化了 FakeUserRepository,紧接着又在下一行将其覆盖为 MagicMock。第一行 repo = FakeUserRepository(user=other_user) 没有任何作用,建议删除以保持代码整洁。
    • 同样的问题出现在第307行的 test_email_already_bound_to_other_user 方法中。
  2. tests/unit/test_auth_bind_wechat_sync.py 第689行:建议将 import 语句移至文件顶部

    • import jwt as pyjwt 位于 test_access_token_has_correct_claims 函数内部。虽然 Python 允许在函数内导入,但通常建议将所有依赖库的 import 统一放在文件头部,以提高代码可读性并遵循 PEP 8 规范。

格式检查通过 | 逻辑审查需修改 | 建议关注性能


🤖 由 AI 代码审查机器人自动生成 | 2026-07-22 22:35:13 | 模型:

## 代码审查结果 - PR #731 ### ⚠️ 问题(0个需要修改) ### 💡 建议(2个可选) 1. **tests/unit/test_auth_bind_wechat_sync.py 第283行**:存在无效代码(Dead Code) - 在 `test_phone_already_bound_to_other_user` 方法中,先实例化了 `FakeUserRepository`,紧接着又在下一行将其覆盖为 `MagicMock`。第一行 `repo = FakeUserRepository(user=other_user)` 没有任何作用,建议删除以保持代码整洁。 - 同样的问题出现在第307行的 `test_email_already_bound_to_other_user` 方法中。 2. **tests/unit/test_auth_bind_wechat_sync.py 第689行**:建议将 import 语句移至文件顶部 - `import jwt as pyjwt` 位于 `test_access_token_has_correct_claims` 函数内部。虽然 Python 允许在函数内导入,但通常建议将所有依赖库的 import 统一放在文件头部,以提高代码可读性并遵循 PEP 8 规范。 --- ✅ 格式检查通过 | ✅ 逻辑审查需修改 | ✅ 建议关注性能 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-22 22:35:13 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia merged commit 99227bd9eb into develop 2026-07-23 00:25:25 +08:00
xiaoxia deleted branch test/p3-1-wave25-bind-contact-wechat-sync-tests 2026-07-23 00:25:25 +08:00

🗑️ 预览环境已清理

PR #731 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #731 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.