83 lines
2.6 KiB
PHP
83 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Enums\ConsultationStatus;
|
|
use App\Models\Consultation;
|
|
use App\Notifications\NewConsultationRequest;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Notifications\AnonymousNotifiable;
|
|
use Illuminate\Support\Facades\Notification;
|
|
use Tests\TestCase;
|
|
|
|
class ConsultationRequestTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function payload(array $overrides = []): array
|
|
{
|
|
return [
|
|
'source' => 'home',
|
|
'name' => 'Budi Santoso',
|
|
'email' => 'budi@example.com',
|
|
'phone' => '0811 2345 678',
|
|
'service' => 'Implementasi Odoo ERP',
|
|
...$overrides,
|
|
];
|
|
}
|
|
|
|
public function test_visitor_request_is_saved_and_busdev_is_notified()
|
|
{
|
|
Notification::fake();
|
|
|
|
$this->from(route('home'))
|
|
->post(route('consultations.store'), $this->payload())
|
|
->assertRedirect(route('home'))
|
|
->assertSessionHasNoErrors();
|
|
|
|
$consultation = Consultation::query()->sole();
|
|
$this->assertSame('Budi Santoso', $consultation->name);
|
|
$this->assertSame(ConsultationStatus::New, $consultation->status);
|
|
$this->assertSame('id', $consultation->locale);
|
|
|
|
Notification::assertSentTo(
|
|
new AnonymousNotifiable,
|
|
NewConsultationRequest::class,
|
|
fn ($notification, $channels, $notifiable) => $notifiable->routes['mail'] === 'busdev@probindo.com',
|
|
);
|
|
}
|
|
|
|
public function test_required_fields_are_validated()
|
|
{
|
|
Notification::fake();
|
|
|
|
$this->post(route('consultations.store'), $this->payload(['name' => '', 'email' => 'bukan-email']))
|
|
->assertSessionHasErrors(['name', 'email']);
|
|
|
|
$this->assertDatabaseCount('consultations', 0);
|
|
Notification::assertNothingSent();
|
|
}
|
|
|
|
public function test_contact_form_requires_nda_consent()
|
|
{
|
|
$this->post(route('consultations.store'), $this->payload(['source' => 'contact']))
|
|
->assertSessionHasErrors('nda_agreed');
|
|
|
|
$this->post(route('consultations.store'), $this->payload(['source' => 'contact', 'nda_agreed' => '1']))
|
|
->assertSessionHasNoErrors();
|
|
|
|
$this->assertTrue(Consultation::query()->sole()->nda_agreed);
|
|
}
|
|
|
|
public function test_honeypot_submissions_are_rejected()
|
|
{
|
|
$this->post(route('consultations.store'), $this->payload(['website' => 'http://spam.test']))
|
|
->assertSessionHasErrors('website');
|
|
|
|
$this->assertDatabaseCount('consultations', 0);
|
|
}
|
|
}
|