Skip to content

Commit bee2bb9

Browse files
committed
Update tests
1 parent 61aa5c8 commit bee2bb9

1 file changed

Lines changed: 34 additions & 18 deletions

File tree

tests/Feature/ForumPostFavoriteTest.php

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,51 @@
33
use Filament\Facades\Filament;
44
use Tapp\FilamentForum\Models\Forum;
55
use Tapp\FilamentForum\Models\ForumPost;
6-
use Workbench\App\Models\Team;
7-
use Workbench\App\Models\User;
86

97
beforeEach(function () {
8+
// Get models from config
9+
$this->userModel = config('filament-forum.user.model', 'App\\Models\\User');
10+
$this->tenantModel = config('filament-forum.tenancy.model', 'App\\Models\\Team');
11+
1012
// Enable tenancy for tests
1113
config(['filament-forum.tenancy.enabled' => true]);
12-
config(['filament-forum.tenancy.model' => Team::class]);
14+
config(['filament-forum.tenancy.model' => $this->tenantModel]);
1315
});
1416

1517
it('can toggle favorite with tenancy enabled', function () {
16-
$team = Team::factory()->create();
17-
$user = User::factory()->create();
18+
$tenantModel = $this->tenantModel;
19+
$userModel = $this->userModel;
20+
21+
$team = $tenantModel::factory()->create();
22+
$user = $userModel::factory()->create();
1823

1924
// Set current tenant
2025
Filament::setTenant($team);
2126
actingAs($user);
2227

28+
// Get the tenant column name dynamically
29+
$tenantColumn = Forum::getTenantColumnName();
30+
2331
$forum = Forum::factory()->create([
24-
'team_id' => $team->id,
32+
$tenantColumn => $team->id,
2533
]);
2634

2735
$post = ForumPost::factory()->create([
2836
'forum_id' => $forum->id,
2937
'user_id' => $user->id,
30-
'team_id' => $team->id,
38+
$tenantColumn => $team->id,
3139
]);
3240

3341
// Toggle favorite
3442
$post->toggleFavorite();
3543

36-
// Check that the favorite was created with team_id
44+
// Check that the favorite was created with tenant_id
3745
expect($user->favoriteForumPosts()->count())->toBe(1);
3846
expect($user->favoriteForumPosts->first()->id)->toBe($post->id);
3947

40-
// Verify pivot data includes team_id
48+
// Verify pivot data includes tenant_id
4149
$pivot = $user->favoriteForumPosts()->first()->pivot;
42-
expect($pivot->team_id)->toBe($team->id);
50+
expect($pivot->{$tenantColumn})->toBe($team->id);
4351

4452
// Check isFavorite returns true
4553
expect($post->isFavorite())->toBeTrue();
@@ -51,25 +59,31 @@
5159
});
5260

5361
it('scopes favorites to current tenant', function () {
54-
$team1 = Team::factory()->create();
55-
$team2 = Team::factory()->create();
56-
$user = User::factory()->create();
62+
$tenantModel = $this->tenantModel;
63+
$userModel = $this->userModel;
64+
65+
$team1 = $tenantModel::factory()->create();
66+
$team2 = $tenantModel::factory()->create();
67+
$user = $userModel::factory()->create();
5768

5869
actingAs($user);
5970

60-
$forum1 = Forum::factory()->create(['team_id' => $team1->id]);
61-
$forum2 = Forum::factory()->create(['team_id' => $team2->id]);
71+
// Get the tenant column name dynamically
72+
$tenantColumn = Forum::getTenantColumnName();
73+
74+
$forum1 = Forum::factory()->create([$tenantColumn => $team1->id]);
75+
$forum2 = Forum::factory()->create([$tenantColumn => $team2->id]);
6276

6377
$post1 = ForumPost::factory()->create([
6478
'forum_id' => $forum1->id,
6579
'user_id' => $user->id,
66-
'team_id' => $team1->id,
80+
$tenantColumn => $team1->id,
6781
]);
6882

6983
$post2 = ForumPost::factory()->create([
7084
'forum_id' => $forum2->id,
7185
'user_id' => $user->id,
72-
'team_id' => $team2->id,
86+
$tenantColumn => $team2->id,
7387
]);
7488

7589
// Favorite post1 in team1 context
@@ -97,10 +111,12 @@
97111
});
98112

99113
it('works without tenancy when disabled', function () {
114+
$userModel = $this->userModel;
115+
100116
// Disable tenancy
101117
config(['filament-forum.tenancy.enabled' => false]);
102118

103-
$user = User::factory()->create();
119+
$user = $userModel::factory()->create();
104120
actingAs($user);
105121

106122
$forum = Forum::factory()->create();

0 commit comments

Comments
 (0)