seed(RolesAndPermissionsSeeder::class); }); function makeAdminForPortalRestriction(): User { $admin = User::factory()->create(['is_active' => true]); $admin->assignRole('admin'); return $admin; } test('Admin-Anlage lehnt Portal Both ab', function () { /** @var TestCase $this */ $this->actingAs(makeAdminForPortalRestriction()); LivewireVolt::test('admin.companies.create') ->set('company_name', 'Beide Portale GmbH') ->set('email', 'kontakt@beide.de') ->set('portal', Portal::Both->value) ->call('save') ->assertHasErrors(['portal']); expect(Company::query()->withoutGlobalScopes()->where('name', 'Beide Portale GmbH')->exists()) ->toBeFalse(); }); test('Admin-Anlage bietet Beide Portale nicht an und legt Firma mit Einzelportal an', function () { /** @var TestCase $this */ $this->actingAs(makeAdminForPortalRestriction()); LivewireVolt::test('admin.companies.create') ->assertDontSeeText(Portal::Both->label()) ->set('company_name', 'Einzelportal GmbH') ->set('email', 'kontakt@einzel.de') ->set('portal', Portal::Businessportal24->value) ->call('save') ->assertHasNoErrors() ->assertRedirect(route('admin.companies.index')); expect(Company::query()->withoutGlobalScopes()->where('name', 'Einzelportal GmbH')->value('portal')) ->toBe(Portal::Businessportal24); }); test('Admin-Bearbeitung lehnt Wechsel auf Portal Both ab', function () { /** @var TestCase $this */ $this->actingAs(makeAdminForPortalRestriction()); $company = Company::factory()->presseecho()->create(); LivewireVolt::test('admin.companies.edit', ['id' => $company->id]) ->assertDontSeeText(Portal::Both->label()) ->set('portal', Portal::Both->value) ->call('update') ->assertHasErrors(['portal']); expect($company->fresh()->portal)->toBe(Portal::Presseecho); }); test('Admin-Bearbeitung erlaubt Bestandsfirmen mit Portal Both den Wert zu behalten', function () { /** @var TestCase $this */ $this->actingAs(makeAdminForPortalRestriction()); $company = Company::factory()->create(['portal' => Portal::Both->value]); LivewireVolt::test('admin.companies.edit', ['id' => $company->id]) ->assertSeeText(Portal::Both->label()) ->set('company_name', $company->name) ->call('update') ->assertHasNoErrors(); expect($company->fresh()->portal)->toBe(Portal::Both); }); test('Admin-Bearbeitung erlaubt Bestandsfirmen den Wechsel von Both auf ein Einzelportal', function () { /** @var TestCase $this */ $this->actingAs(makeAdminForPortalRestriction()); $company = Company::factory()->create(['portal' => Portal::Both->value]); LivewireVolt::test('admin.companies.edit', ['id' => $company->id]) ->set('portal', Portal::Presseecho->value) ->call('update') ->assertHasNoErrors(); expect($company->fresh()->portal)->toBe(Portal::Presseecho); });