66use App \Models \License ;
77use App \Models \User ;
88use Illuminate \Foundation \Testing \RefreshDatabase ;
9+ use Illuminate \Support \Facades \Cache ;
910use Illuminate \Support \Facades \Http ;
1011use Laravel \Pennant \Feature ;
1112use Tests \TestCase ;
@@ -19,10 +20,15 @@ protected function setUp(): void
1920 parent ::setUp ();
2021
2122 Feature::define (ShowAuthButtons::class, true );
23+
24+ // Clear cache between tests to avoid stale collaborator status
25+ Cache::flush ();
2226 }
2327
2428 public function test_user_with_active_max_license_sees_github_integration_card (): void
2529 {
30+ Http::fake (['api.github.com/* ' => Http::response ([], 404 )]);
31+
2632 $ user = User::factory ()->create ();
2733 License::factory ()->create ([
2834 'user_id ' => $ user ->id ,
@@ -34,12 +40,15 @@ public function test_user_with_active_max_license_sees_github_integration_card()
3440 $ response = $ this ->actingAs ($ user )->get ('/customer/licenses ' );
3541
3642 $ response ->assertStatus (200 );
37- $ response ->assertSee ('GitHub Repository Access ' );
43+ $ response ->assertSee ('nativephp/mobile ' );
44+ $ response ->assertSee ('Repo Access ' );
3845 $ response ->assertSee ('Connect GitHub ' );
3946 }
4047
4148 public function test_user_without_max_license_does_not_see_github_integration_card (): void
4249 {
50+ Http::fake (['api.github.com/* ' => Http::response ([], 404 )]);
51+
4352 $ user = User::factory ()->create ();
4453 License::factory ()->create ([
4554 'user_id ' => $ user ->id ,
@@ -51,11 +60,13 @@ public function test_user_without_max_license_does_not_see_github_integration_ca
5160 $ response = $ this ->actingAs ($ user )->get ('/customer/licenses ' );
5261
5362 $ response ->assertStatus (200 );
54- $ response ->assertDontSee ('GitHub Repository Access ' );
63+ $ response ->assertDontSee ('Repo Access ' );
5564 }
5665
5766 public function test_user_with_connected_github_sees_username (): void
5867 {
68+ Http::fake (['api.github.com/* ' => Http::response ([], 404 )]);
69+
5970 $ user = User::factory ()->create ([
6071 'github_username ' => 'testuser ' ,
6172 'github_id ' => '123456 ' ,
@@ -78,7 +89,7 @@ public function test_user_with_connected_github_sees_username(): void
7889 public function test_user_can_request_repo_access_with_active_max_license (): void
7990 {
8091 Http::fake ([
81- 'api.github.com/repos/nativephp/mobile/collaborators/* ' => Http::response ([], 201 ),
92+ 'api.github.com/repos/nativephp/mobile/collaborators/testuser ' => Http::response ([], 201 ),
8293 ]);
8394
8495 $ user = User::factory ()->create ([
@@ -146,7 +157,7 @@ public function test_user_cannot_request_repo_access_without_connected_github():
146157 public function test_user_can_disconnect_github_account (): void
147158 {
148159 Http::fake ([
149- 'api.github.com/repos/nativephp/mobile/collaborators/* ' => Http::response ([], 204 ),
160+ 'api.github.com/repos/nativephp/mobile/collaborators/testuser ' => Http::response ([], 204 ),
150161 ]);
151162
152163 $ user = User::factory ()->create ([
@@ -178,7 +189,7 @@ public function test_user_can_disconnect_github_account(): void
178189 public function test_scheduled_command_removes_access_for_expired_max_license (): void
179190 {
180191 Http::fake ([
181- 'api.github.com/repos/nativephp/mobile/collaborators/* ' => Http::response ([], 204 ),
192+ 'api.github.com/repos/nativephp/mobile/collaborators/testuser ' => Http::response ([], 204 ),
182193 ]);
183194
184195 $ user = User::factory ()->create ([
@@ -226,12 +237,15 @@ public function test_scheduled_command_does_not_remove_access_for_active_max_lic
226237 ]);
227238 }
228239
229- public function test_user_with_granted_access_sees_access_status (): void
240+ public function test_user_with_active_collaborator_status_sees_access_granted (): void
230241 {
242+ Http::fake ([
243+ 'api.github.com/repos/nativephp/mobile/collaborators/testuser ' => Http::response ([], 204 ),
244+ ]);
245+
231246 $ user = User::factory ()->create ([
232247 'github_username ' => 'testuser ' ,
233248 'github_id ' => '123456 ' ,
234- 'mobile_repo_access_granted_at ' => now ()->subHours (2 ),
235249 ]);
236250 License::factory ()->create ([
237251 'user_id ' => $ user ->id ,
@@ -243,8 +257,37 @@ public function test_user_with_granted_access_sees_access_status(): void
243257 $ response = $ this ->actingAs ($ user )->get ('/customer/licenses ' );
244258
245259 $ response ->assertStatus (200 );
246- $ response ->assertSee ('Invitation Sent ' );
260+ $ response ->assertSee ('Access Granted ' );
247261 $ response ->assertSee ('@testuser ' );
262+ $ response ->assertSee ('View Repo ' );
248263 $ response ->assertDontSee ('Request Access ' );
249264 }
265+
266+ public function test_user_with_pending_invitation_sees_pending_status (): void
267+ {
268+ Http::fake ([
269+ 'api.github.com/repos/nativephp/mobile/collaborators/testuser ' => Http::response ([], 404 ),
270+ 'api.github.com/repos/nativephp/mobile/invitations ' => Http::response ([
271+ ['invitee ' => ['login ' => 'testuser ' ]],
272+ ], 200 ),
273+ ]);
274+
275+ $ user = User::factory ()->create ([
276+ 'github_username ' => 'testuser ' ,
277+ 'github_id ' => '123456 ' ,
278+ ]);
279+ License::factory ()->create ([
280+ 'user_id ' => $ user ->id ,
281+ 'policy_name ' => 'max ' ,
282+ 'expires_at ' => now ()->addDays (30 ),
283+ 'is_suspended ' => false ,
284+ ]);
285+
286+ $ response = $ this ->actingAs ($ user )->get ('/customer/licenses ' );
287+
288+ $ response ->assertStatus (200 );
289+ $ response ->assertSee ('Invitation Pending ' );
290+ $ response ->assertSee ('@testuser ' );
291+ $ response ->assertSee ('Check Status ' );
292+ }
250293}
0 commit comments