refactor: remove global Event::fake() and switch tests to standard teams#137
Merged
ManukMinasyan merged 4 commits intomainfrom Feb 20, 2026
Merged
refactor: remove global Event::fake() and switch tests to standard teams#137ManukMinasyan merged 4 commits intomainfrom
ManukMinasyan merged 4 commits intomainfrom
Conversation
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
There was a problem hiding this comment.
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()fromtests/Pest.phpso model/Jetstream events aren’t suppressed across the entire test suite. - Added
UserFactory::withTeam()and migrated many tests fromwithPersonalTeam()towithTeam()(plus related tenant setup updates). - Fixed an N+1 in
CompanyObserverby 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Event::fake()fromtests/Pest.phpthat was suppressing all model observer events, making tests run in an artificial environmentwithTeam()factory state toUserFactorythat creates standard (non-personal) teams, triggeringCreateTeamCustomFieldsso custom fields exist naturally in testswithPersonalTeam()towithTeam(), making tests more realisticCompanyObservereager loading (customFieldValues.customField) to preventLazyLoadingViolationExceptionTest plan