[PR #23380] Feat add testcontainers test for account service #30259

Closed
opened 2026-02-21 20:47:09 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/23380

State: closed
Merged: Yes


Based on the code content provided, here's the documentation in the requested format:

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

fix #23440

This PR introduces comprehensive integration tests for account-related services using testcontainers. The implementation adds three main test classes that provide thorough coverage of account management, tenant operations, and user registration workflows.

Key Changes:

  • TestAccountService: Comprehensive testing of account lifecycle operations including creation, authentication, password management, OAuth integration, login/logout functionality, token management, and account deletion
  • TestTenantService: Complete coverage of tenant management including creation, member management, role assignments, tenant switching, dissolution, and custom configurations
  • TestRegisterService: Full testing of registration workflows including system setup, user registration with/without workspaces, invitation system, and token management

Technical Implementation:

  • Uses testcontainers for isolated database testing environments
  • Implements proper mocking of external service dependencies (FeatureService, BillingService, PassportService)
  • Provides extensive test coverage for error scenarios and edge cases
  • Includes proper cleanup and rollback testing for transaction integrity
  • Tests both success and failure paths with appropriate exception handling

Test Coverage Highlights:

  • Account creation with various configurations (with/without passwords, different statuses)
  • Authentication flows including banned accounts, wrong passwords, and invite tokens
  • Password update operations with validation
  • OAuth provider integration and account linking
  • Tenant creation, member management, and permission systems
  • Role-based access control and tenant switching
  • Registration workflows with workspace creation controls
  • Invitation system with token generation, validation, and revocation
  • Redis-based token storage and retrieval mechanisms

Screenshots

Before After
Limited test coverage for account services Comprehensive integration tests with 100+ test cases covering all major workflows

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/23380 **State:** closed **Merged:** Yes --- Based on the code content provided, here's the documentation in the requested format: > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 2. Ensure there is an associated issue and you have been assigned to it > 3. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary fix #23440 This PR introduces comprehensive integration tests for account-related services using testcontainers. The implementation adds three main test classes that provide thorough coverage of account management, tenant operations, and user registration workflows. **Key Changes:** - **TestAccountService**: Comprehensive testing of account lifecycle operations including creation, authentication, password management, OAuth integration, login/logout functionality, token management, and account deletion - **TestTenantService**: Complete coverage of tenant management including creation, member management, role assignments, tenant switching, dissolution, and custom configurations - **TestRegisterService**: Full testing of registration workflows including system setup, user registration with/without workspaces, invitation system, and token management **Technical Implementation:** - Uses testcontainers for isolated database testing environments - Implements proper mocking of external service dependencies (FeatureService, BillingService, PassportService) - Provides extensive test coverage for error scenarios and edge cases - Includes proper cleanup and rollback testing for transaction integrity - Tests both success and failure paths with appropriate exception handling **Test Coverage Highlights:** - Account creation with various configurations (with/without passwords, different statuses) - Authentication flows including banned accounts, wrong passwords, and invite tokens - Password update operations with validation - OAuth provider integration and account linking - Tenant creation, member management, and permission systems - Role-based access control and tenant switching - Registration workflows with workspace creation controls - Invitation system with token generation, validation, and revocation - Redis-based token storage and retrieval mechanisms ## Screenshots | Before | After | |--------|-------| | Limited test coverage for account services | Comprehensive integration tests with 100+ test cases covering all major workflows | ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:47:09 -05:00
yindo closed this issue 2026-02-21 20:47:09 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#30259