Skip to content

refactor: remove global Event::fake() and switch tests to standard teams#137

Merged
ManukMinasyan merged 4 commits intomainfrom
feat/resource-crud-tests
Feb 20, 2026
Merged

refactor: remove global Event::fake() and switch tests to standard teams#137
ManukMinasyan merged 4 commits intomainfrom
feat/resource-crud-tests

Conversation

@ManukMinasyan
Copy link
Copy Markdown
Contributor

@ManukMinasyan ManukMinasyan commented Feb 20, 2026

Summary

  • Remove the global Event::fake() from tests/Pest.php that was suppressing all model observer events, making tests run in an artificial environment
  • Add withTeam() factory state to UserFactory that creates standard (non-personal) teams, triggering CreateTeamCustomFields so custom fields exist naturally in tests
  • Migrate ~35 test files from withPersonalTeam() to withTeam(), making tests more realistic
  • Add CRUD tests (create, edit, delete, validation) to all 5 resource test files
  • Fix CompanyObserver eager loading (customFieldValues.customField) to prevent LazyLoadingViolationException

Test plan

  • All 723 tests passing
  • PHPStan clean (no new errors)
  • Pint formatting clean

Remove the global Event::fake() from tests/Pest.php that was suppressing
all model observer events. Tests now use withTeam() (non-personal teams)
instead of withPersonalTeam(), allowing observers and CreateTeamCustomFields
to run naturally. This makes tests more realistic since custom fields are
a fundamental part of the data model.

- Add withTeam() factory state to UserFactory
- Fix N+1 lazy loading in CompanyObserver (customFieldValues.customField)
- Migrate 33 test files from withPersonalTeam() to withTeam()
- Remove per-test Event::fake() workarounds from resource CRUD tests
- Fix board tests that manually invoked CreateTeamCustomFields (now automatic)
- Fix SystemAdminResourceTest to use withoutEvents() for record creation
Copilot AI review requested due to automatic review settings February 20, 2026 02:23
Copy link
Copy Markdown

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

Refactors the test suite to stop globally faking events (so observers/listeners run as in production) and standardizes tests on non-personal teams via a new withTeam() factory state, making custom-field-dependent behavior more realistic.

Changes:

  • Removed global Event::fake() from tests/Pest.php so model/Jetstream events aren’t suppressed across the entire test suite.
  • Added UserFactory::withTeam() and migrated many tests from withPersonalTeam() to withTeam() (plus related tenant setup updates).
  • Fixed an N+1 in CompanyObserver by eager-loading nested custom field relations.

Reviewed changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/Pest.php Removes global event faking so observers/listeners execute during tests.
tests/Feature/Teams/UpdateTeamNameTest.php Switches team setup from personal team to standard team.
tests/Feature/Teams/UpdateTeamMemberRoleTest.php Switches to withTeam() for standard-team behavior.
tests/Feature/Teams/RemoveTeamMemberTest.php Switches to withTeam() for standard-team behavior.
tests/Feature/Teams/LeaveTeamTest.php Switches to withTeam() for standard-team behavior.
tests/Feature/Teams/InviteTeamMemberTest.php Switches to withTeam() for standard-team behavior.
tests/Feature/Teams/DeleteTeamTest.php Uses withTeam() for deletable teams; keeps explicit personal-team assertions via personalTeam().
tests/Feature/SystemAdmin/SystemAdminResourceTest.php Creates data with explicit team context and selectively disables events for record creation.
tests/Feature/Profile/UpdateUserProfileInformationTest.php Moves profile tests to standard teams (withTeam()).
tests/Feature/Profile/UpdatePasswordTest.php Moves password tests to standard teams (withTeam()).
tests/Feature/Migrations/UlidMigrationTest.php Moves ULID migration assertions to standard teams (withTeam()).
tests/Feature/ImportWizard/Validation/EntityLinkValidatorTest.php Uses currentTeam as tenant rather than personal team.
tests/Feature/ImportWizard/Support/EntityLinkResolverTest.php Uses withTeam() for consistent tenant setup.
tests/Feature/ImportWizard/Livewire/UploadStepTest.php Uses currentTeam as tenant rather than personal team.
tests/Feature/ImportWizard/Livewire/ReviewStepTest.php Uses currentTeam as tenant rather than personal team.
tests/Feature/ImportWizard/Livewire/PreviewStepTest.php Uses currentTeam as tenant rather than personal team.
tests/Feature/ImportWizard/Livewire/MappingStepTest.php Uses currentTeam as tenant rather than personal team.
tests/Feature/ImportWizard/Livewire/ImportWizardTest.php Uses currentTeam as tenant and updates cross-team reset test setup accordingly.
tests/Feature/ImportWizard/Jobs/ValidateColumnJobTest.php Uses currentTeam as tenant rather than personal team.
tests/Feature/ImportWizard/Jobs/ResolveMatchesJobTest.php Uses currentTeam as tenant rather than personal team.
tests/Feature/ImportWizard/Jobs/ExecuteImportJobTest.php Uses currentTeam as tenant rather than personal team.
tests/Feature/ImportWizard/Commands/CleanupImportsCommandTest.php Uses currentTeam as tenant rather than personal team.
tests/Feature/Filament/App/Resources/TaskResourceTest.php Switches tenant initialization to standard team and adds CRUD action coverage without event workarounds.
tests/Feature/Filament/App/Resources/PeopleResourceTest.php Switches tenant initialization to standard team and adds CRUD action coverage.
tests/Feature/Filament/App/Resources/OpportunityResourceTest.php Switches tenant initialization to standard team and adds CRUD action coverage.
tests/Feature/Filament/App/Resources/NoteResourceTest.php Switches tenant initialization to standard team, removes redundant RefreshDatabase usage, adds CRUD action coverage.
tests/Feature/Filament/App/Resources/CompanyResourceTest.php Switches tenant initialization to standard team and adds CRUD action coverage.
tests/Feature/Filament/App/Pages/TasksBoardTest.php Removes manual custom-field seeding and relies on natural TeamCreated-driven setup under standard teams.
tests/Feature/Filament/App/Pages/OpportunitiesBoardTest.php Removes manual custom-field seeding and relies on natural TeamCreated-driven setup under standard teams.
tests/Feature/Auth/SocialiteLoginTest.php Uses withTeam() when creating users for auth flows.
tests/Feature/Auth/AuthenticationTest.php Uses withTeam() for login test setup.
tests/Feature/ApiTokens/DeleteApiTokenTest.php Uses withTeam() when team features are enabled.
tests/Feature/ApiTokens/CreateApiTokenTest.php Uses withTeam() when team features are enabled.
tests/Feature/ApiTokens/ApiTokenPermissionsTest.php Uses withTeam() when team features are enabled.
tests/Feature/AI/RecordSummaryServiceTest.php Switches to standard teams; adjusts custom-field setup to rely on seeded/system fields.
database/factories/UserFactory.php Adds withTeam() factory state to create/switch to a non-personal team.
app/Observers/CompanyObserver.php Fixes N+1 by eager-loading customFieldValues.customField.

Teams are always enabled in this multi-tenant SaaS — remove dead
conditional branches and simplify test setup accordingly. Also replace
withoutGlobalScopes() with proper query scopes in RecordSummaryServiceTest.
Replace hardcoded claude-3-5-haiku-latest (404) with claude-haiku-4-5
alias, configurable via ANTHROPIC_SUMMARY_MODEL env var. Add health
check to detect model availability issues before they reach users.
Health checks extend Spatie's Check base class, so they can't satisfy
the toExtendNothing and toBeReadonly arch constraints.
@ManukMinasyan ManukMinasyan merged commit 075988a into main Feb 20, 2026
9 checks passed
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.

2 participants