105 lines
3.2 KiB
PHP
105 lines
3.2 KiB
PHP
<?php
|
|
|
|
use App\Enums\Portal;
|
|
use App\Models\Company;
|
|
use App\Models\User;
|
|
use Database\Seeders\RolesAndPermissionsSeeder;
|
|
use Livewire\Volt\Volt as LivewireVolt;
|
|
use Tests\TestCase;
|
|
|
|
beforeEach(function (): void {
|
|
/** @var TestCase $this */
|
|
$this->seed(RolesAndPermissionsSeeder::class);
|
|
});
|
|
|
|
function makeCustomerForCreate(): User
|
|
{
|
|
$customer = User::factory()->create(['is_active' => true]);
|
|
$customer->assignRole('customer');
|
|
|
|
return $customer;
|
|
}
|
|
|
|
test('Create-Route ist für eingeloggte Customer erreichbar', function () {
|
|
/** @var TestCase $this */
|
|
$customer = makeCustomerForCreate();
|
|
|
|
$this->actingAs($customer)
|
|
->get('/admin/me/firmen/anlegen')
|
|
->assertOk()
|
|
->assertSeeText('Neue Firma anlegen')
|
|
->assertSeeText('Firmenname');
|
|
});
|
|
|
|
test('Create-Route ist für Gäste nicht zugänglich', function () {
|
|
/** @var TestCase $this */
|
|
$this->get('/admin/me/firmen/anlegen')
|
|
->assertRedirect();
|
|
});
|
|
|
|
test('save erstellt eine Firma und ordnet sie dem User als Owner zu', function () {
|
|
/** @var TestCase $this */
|
|
$customer = makeCustomerForCreate();
|
|
|
|
LivewireVolt::actingAs($customer)
|
|
->test('customer.press-kits.create')
|
|
->set('name', 'Neue Brauerei AG')
|
|
->set('portal', 'presseecho')
|
|
->set('type', 'company')
|
|
->set('email', 'kontakt@brauerei.de')
|
|
->call('save')
|
|
->assertHasNoErrors()
|
|
->assertRedirect();
|
|
|
|
/** @var Company $company */
|
|
$company = Company::query()->withoutGlobalScopes()->where('name', 'Neue Brauerei AG')->first();
|
|
|
|
expect($company)->not->toBeNull()
|
|
->and($company->owner_user_id)->toBe($customer->id)
|
|
->and($company->portal->value)->toBe('presseecho')
|
|
->and($company->email)->toBe('kontakt@brauerei.de')
|
|
->and($company->is_active)->toBeTrue();
|
|
|
|
expect($customer->companies()->where('companies.id', $company->id)->wherePivot('role', 'owner')->exists())
|
|
->toBeTrue();
|
|
});
|
|
|
|
test('save validiert Pflichtfelder Name und Portal', function () {
|
|
/** @var TestCase $this */
|
|
$customer = makeCustomerForCreate();
|
|
|
|
LivewireVolt::actingAs($customer)
|
|
->test('customer.press-kits.create')
|
|
->set('name', '')
|
|
->set('portal', '')
|
|
->call('save')
|
|
->assertHasErrors(['name' => 'required', 'portal' => 'required']);
|
|
});
|
|
|
|
test('save lehnt unbekannte Portal-Werte ab', function () {
|
|
/** @var TestCase $this */
|
|
$customer = makeCustomerForCreate();
|
|
|
|
LivewireVolt::actingAs($customer)
|
|
->test('customer.press-kits.create')
|
|
->set('name', 'Test GmbH')
|
|
->set('portal', 'invalid')
|
|
->call('save')
|
|
->assertHasErrors(['portal']);
|
|
});
|
|
|
|
test('save akzeptiert Portal Both', function () {
|
|
/** @var TestCase $this */
|
|
$customer = makeCustomerForCreate();
|
|
|
|
LivewireVolt::actingAs($customer)
|
|
->test('customer.press-kits.create')
|
|
->set('name', 'Beide Portale GmbH')
|
|
->set('portal', 'both')
|
|
->set('type', 'company')
|
|
->call('save')
|
|
->assertHasNoErrors();
|
|
|
|
expect(Company::query()->withoutGlobalScopes()->where('name', 'Beide Portale GmbH')->value('portal'))
|
|
->toBe(Portal::Both);
|
|
});
|