Skip to content

Conversation

@pedroccastro
Copy link

What does this PR do?

Refactors organizations-users.e2e-spec.ts to reduce duplication and improve maintainability.

Problem:

  • User + profile + membership setup repeated 6+ times across describes
  • Inconsistent fixture naming (membershipFixtures vs profileRepositoryFixture)
  • Cleanup logic duplicated with different patterns

Key Changes:

  • org-user.helper.ts: New helper with createOrgUser() and cleanupOrgTest()
  • Standardized fixture naming to *Fixture (singular)
  • Added afterEach to restore mocks between tests
  • Removed dead code and redundant assertions

Result: 891 → 582 lines, helper adds 62 lines.

How should this be tested?

Run the test:

npx jest src/modules/organizations/users/index/controllers/organizations-users.e2e-spec.ts --config jest-e2e.ts

All 17 tests should pass. No behavior changes, same coverage.

Mandatory Tasks

  • I have self-reviewed the code
  • N/A I have updated the developer docs in /docs if this PR makes changes that would require a documentation change
  • I confirm automated tests are in place that prove my fix is effective or that my feature works

- avatarValidator: accept URLs in addition to base64 images
- organizations-users-service: use email for user creation instead of username

The avatarValidator was incorrectly rejecting valid URLs even though the API documentation shows URL examples and all e2e tests use URLs.

The user creation was failing when username was provided because createNewUsersConnectToOrgIfExists requires a valid email, not username. The username is correctly applied via updateOrganizationUser after creation.

Fixes user creation endpoint POST /v2/organizations/{orgId}/users
  Add comprehensive test coverage for avatarValidator changes:

  - Unit tests: 18 scenarios covering valid/invalid URLs and base64 images
  - E2E tests: user creation with username + avatarUrl (URL and base64)
  - Security validation: reject unsafe protocols and malformed data
  - Error message verification for validation failures

  Addresses testing requirements from code review
- Preparing for complete test file rewrite to improve maintainability, reduce code duplication while preserving test coverage
…lpers

  - Add org-user.helper.ts with createOrgUser and cleanupOrgTest functions
  - Rewrite organizations-users.e2e-spec.ts with improved structure and DRY principles
  - Reduce code duplication while preserving test coverage
  - Add factory functions and enhanced assertions for better maintainability
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants