167 lines
5.7 KiB
PHP
167 lines
5.7 KiB
PHP
<?php
|
|
|
|
use App\Enums\PressReleaseStatus;
|
|
use App\Models\Category;
|
|
use App\Models\Company;
|
|
use App\Models\Contact;
|
|
use App\Models\PressRelease;
|
|
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);
|
|
});
|
|
|
|
/**
|
|
* @return array{customer: User, company: Company, contact: Contact, category: Category}
|
|
*/
|
|
function makeCustomerForContactWarning(): array
|
|
{
|
|
$customer = User::factory()->create(['is_active' => true]);
|
|
$customer->assignRole('customer');
|
|
|
|
$company = Company::factory()->presseecho()->create();
|
|
$customer->companies()->attach($company->id, ['role' => 'owner']);
|
|
|
|
$contact = Contact::factory()->for($company)->create([
|
|
'portal' => $company->portal->value,
|
|
'phone' => '+49 30 1234567',
|
|
]);
|
|
$category = Category::factory()->create();
|
|
|
|
return compact('customer', 'company', 'contact', 'category');
|
|
}
|
|
|
|
function makeAdminForContactWarning(): User
|
|
{
|
|
$admin = User::factory()->create(['is_active' => true]);
|
|
$admin->assignRole('admin');
|
|
|
|
return $admin;
|
|
}
|
|
|
|
test('customer create zeigt Warn-Box, wenn kein Pressekontakt gewählt ist', function () {
|
|
/** @var TestCase $this */
|
|
['customer' => $customer, 'company' => $company] = makeCustomerForContactWarning();
|
|
$this->actingAs($customer);
|
|
|
|
LivewireVolt::test('customer.press-releases.create')
|
|
->set('companyId', $company->id)
|
|
->set('contactId', null)
|
|
->assertSee('Noch kein Pressekontakt ausgewählt');
|
|
});
|
|
|
|
test('customer create zeigt Warn-Box NICHT, wenn ein Kontakt gewählt ist', function () {
|
|
/** @var TestCase $this */
|
|
['customer' => $customer, 'company' => $company, 'contact' => $contact] = makeCustomerForContactWarning();
|
|
$this->actingAs($customer);
|
|
|
|
LivewireVolt::test('customer.press-releases.create')
|
|
->set('companyId', $company->id)
|
|
->set('contactId', $contact->id)
|
|
->assertDontSee('Noch kein Pressekontakt ausgewählt');
|
|
});
|
|
|
|
test('customer edit zeigt Warn-Box, wenn kein Pressekontakt gewählt ist', function () {
|
|
/** @var TestCase $this */
|
|
['customer' => $customer, 'company' => $company, 'category' => $category] = makeCustomerForContactWarning();
|
|
$this->actingAs($customer);
|
|
|
|
$pr = PressRelease::factory()->create([
|
|
'user_id' => $customer->id,
|
|
'company_id' => $company->id,
|
|
'category_id' => $category->id,
|
|
'portal' => $company->portal->value,
|
|
'status' => PressReleaseStatus::Draft->value,
|
|
]);
|
|
|
|
LivewireVolt::test('customer.press-releases.edit', ['id' => $pr->id])
|
|
->set('contactId', null)
|
|
->assertSee('Noch kein Pressekontakt ausgewählt');
|
|
});
|
|
|
|
test('customer edit zeigt Warn-Box NICHT, wenn ein Kontakt gewählt ist', function () {
|
|
/** @var TestCase $this */
|
|
['customer' => $customer, 'company' => $company, 'contact' => $contact, 'category' => $category] = makeCustomerForContactWarning();
|
|
$this->actingAs($customer);
|
|
|
|
$pr = PressRelease::factory()->create([
|
|
'user_id' => $customer->id,
|
|
'company_id' => $company->id,
|
|
'category_id' => $category->id,
|
|
'portal' => $company->portal->value,
|
|
'status' => PressReleaseStatus::Draft->value,
|
|
]);
|
|
$pr->contacts()->sync([$contact->id]);
|
|
|
|
LivewireVolt::test('customer.press-releases.edit', ['id' => $pr->id])
|
|
->assertDontSee('Noch kein Pressekontakt ausgewählt');
|
|
});
|
|
|
|
test('admin create zeigt Warn-Box, wenn kein Pressekontakt gewählt ist', function () {
|
|
/** @var TestCase $this */
|
|
$admin = makeAdminForContactWarning();
|
|
$this->actingAs($admin);
|
|
|
|
$company = Company::factory()->presseecho()->create();
|
|
Contact::factory()->for($company)->create([
|
|
'portal' => $company->portal->value,
|
|
'phone' => '+49 30 7654321',
|
|
]);
|
|
|
|
LivewireVolt::test('admin.press-releases.create')
|
|
->set('companyId', $company->id)
|
|
->set('contactId', null)
|
|
->assertSee('Noch kein Pressekontakt ausgewählt');
|
|
});
|
|
|
|
test('admin edit zeigt Warn-Box, wenn kein Pressekontakt gewählt ist', function () {
|
|
/** @var TestCase $this */
|
|
$admin = makeAdminForContactWarning();
|
|
$this->actingAs($admin);
|
|
|
|
$company = Company::factory()->presseecho()->create();
|
|
Contact::factory()->for($company)->create([
|
|
'portal' => $company->portal->value,
|
|
'phone' => '+49 30 7654321',
|
|
]);
|
|
$category = Category::factory()->create();
|
|
|
|
$pr = PressRelease::factory()->create([
|
|
'company_id' => $company->id,
|
|
'category_id' => $category->id,
|
|
'portal' => $company->portal->value,
|
|
'status' => PressReleaseStatus::Draft->value,
|
|
]);
|
|
|
|
LivewireVolt::test('admin.press-releases.edit', ['id' => $pr->id])
|
|
->set('contactId', null)
|
|
->assertSee('Noch kein Pressekontakt ausgewählt');
|
|
});
|
|
|
|
test('admin edit zeigt Warn-Box NICHT, wenn ein Kontakt gewählt ist', function () {
|
|
/** @var TestCase $this */
|
|
$admin = makeAdminForContactWarning();
|
|
$this->actingAs($admin);
|
|
|
|
$company = Company::factory()->presseecho()->create();
|
|
$contact = Contact::factory()->for($company)->create([
|
|
'portal' => $company->portal->value,
|
|
'phone' => '+49 30 7654321',
|
|
]);
|
|
$category = Category::factory()->create();
|
|
|
|
$pr = PressRelease::factory()->create([
|
|
'company_id' => $company->id,
|
|
'category_id' => $category->id,
|
|
'portal' => $company->portal->value,
|
|
'status' => PressReleaseStatus::Draft->value,
|
|
]);
|
|
$pr->contacts()->sync([$contact->id]);
|
|
|
|
LivewireVolt::test('admin.press-releases.edit', ['id' => $pr->id])
|
|
->assertDontSee('Noch kein Pressekontakt ausgewählt');
|
|
});
|