All checks were successful
Build MapleDeploy Coolify Image / build (push) Successful in 41s
65 lines
1.9 KiB
PHP
65 lines
1.9 KiB
PHP
<?php
|
|
|
|
use App\Http\Middleware\DecideWhatToDoWithUser;
|
|
use App\Models\InstanceSettings;
|
|
use App\Models\Team;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\Request;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
config([
|
|
'app.maintenance.store' => 'array',
|
|
'cache.default' => 'array',
|
|
]);
|
|
});
|
|
|
|
test('MapleDeploy root team admins log in to the managed root team', function () {
|
|
InstanceSettings::unguarded(fn () => InstanceSettings::query()->create(['id' => 0]));
|
|
$rootTeam = Team::factory()->create([
|
|
'id' => 0,
|
|
'name' => 'Root Team',
|
|
'personal_team' => false,
|
|
]);
|
|
$user = User::factory()->create([
|
|
'email' => 'member@example.com',
|
|
]);
|
|
expect($user->teams()->where('personal_team', true)->exists())->toBeTrue();
|
|
$user->teams()->syncWithoutDetaching([
|
|
$rootTeam->id => ['role' => 'admin'],
|
|
]);
|
|
|
|
$response = $this->post('/login', [
|
|
'email' => 'member@example.com',
|
|
'password' => 'password',
|
|
]);
|
|
|
|
$response->assertRedirect();
|
|
expect(session('currentTeam')?->id)->toBe(0);
|
|
});
|
|
|
|
test('MapleDeploy root team admin sessions are repaired from personal team to root team', function () {
|
|
$rootTeam = Team::factory()->create([
|
|
'id' => 0,
|
|
'name' => 'Root Team',
|
|
'personal_team' => false,
|
|
]);
|
|
$user = User::factory()->create([
|
|
'email' => 'member@example.com',
|
|
]);
|
|
$personalTeam = $user->teams()->where('personal_team', true)->firstOrFail();
|
|
$user->teams()->syncWithoutDetaching([
|
|
$rootTeam->id => ['role' => 'admin'],
|
|
]);
|
|
$this->actingAs($user);
|
|
session(['currentTeam' => $personalTeam]);
|
|
|
|
app(DecideWhatToDoWithUser::class)->handle(
|
|
Request::create('/'),
|
|
fn () => response('ok'),
|
|
);
|
|
|
|
expect(session('currentTeam')?->id)->toBe(0);
|
|
});
|