1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-06-20 22:54:05 +00:00

minor test improvements

This commit is contained in:
Samuel Stancl 2026-06-05 13:59:58 -07:00
parent 142efdccd6
commit 3e20576dc0
No known key found for this signature in database
GPG key ID: BA146259A1E16C57

View file

@ -150,7 +150,7 @@ test('tenant user can be impersonated on a tenant path', function () {
->assertRedirect('/login'); ->assertRedirect('/login');
}); });
test('stopImpersonating can keep the user authenticated', function() { test('stopImpersonating can keep the user authenticated', function () {
makeLoginRoute(); makeLoginRoute();
Route::middleware(InitializeTenancyByPath::class)->prefix('/{tenant}')->group(getRoutes(false)); Route::middleware(InitializeTenancyByPath::class)->prefix('/{tenant}')->group(getRoutes(false));
@ -191,7 +191,7 @@ test('stopImpersonating can keep the user authenticated', function() {
->assertSee('You are logged in as Joe'); ->assertSee('You are logged in as Joe');
}); });
test('stopImpersonating logs out the user from the impersonation guard stored in session', function() { test('stopImpersonating logs out the user from the impersonation guard stored in session', function () {
Route::middleware(InitializeTenancyByPath::class)->prefix('/{tenant}')->group(getRoutes(false)); Route::middleware(InitializeTenancyByPath::class)->prefix('/{tenant}')->group(getRoutes(false));
$tenant = Tenant::create([ $tenant = Tenant::create([
@ -225,11 +225,10 @@ test('stopImpersonating logs out the user from the impersonation guard stored in
'provider' => 'users', 'provider' => 'users',
]]); ]]);
// Switch guard from 'web' to 'test' and manually log in the user through 'test' // Manually log the user in through the 'test' guard
auth()->shouldUse('test'); auth('test')->loginUsingId($user->id);
auth()->loginUsingId($user->id);
// Should log out the user from the guard used for impersonation ('web') // Should log the user out from the guard used for impersonation ('web')
UserImpersonation::stopImpersonating(); UserImpersonation::stopImpersonating();
expect(auth('web')->check())->toBeFalse(); expect(auth('web')->check())->toBeFalse();
@ -241,7 +240,7 @@ test('stopImpersonating logs out the user from the impersonation guard stored in
// stopImpersonating should throw an exception instead of logging out // stopImpersonating should throw an exception instead of logging out
expect(fn() => UserImpersonation::stopImpersonating())->toThrow(Exception::class); expect(fn() => UserImpersonation::stopImpersonating())->toThrow(Exception::class);
expect(auth()->check())->toBeTrue(); expect(auth('test')->check())->toBeTrue();
}); });
test('tokens have a limited ttl', function () { test('tokens have a limited ttl', function () {