83 lines
2.3 KiB
PHP
83 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Services\Sms;
|
|
|
|
use App\Jobs\SendPatternSms;
|
|
use App\Models\Document;
|
|
use App\Models\Invoice;
|
|
use App\Services\Sms\SmsNotificationService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Queue;
|
|
use Tests\TestCase;
|
|
|
|
class SmsNotificationServiceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected SmsNotificationService $service;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
Queue::fake();
|
|
config(['services.iranpayamak.patterns' => [
|
|
'request_registered' => 'p-registered',
|
|
'payment_confirmed' => 'p-payment',
|
|
'report_ready' => 'p-report',
|
|
]]);
|
|
$this->service = app(SmsNotificationService::class);
|
|
}
|
|
|
|
public function test_request_registered_dispatches_sms_to_requester(): void
|
|
{
|
|
$this->service->requestRegistered(Document::factory()->create());
|
|
|
|
Queue::assertPushed(SendPatternSms::class, 1);
|
|
}
|
|
|
|
public function test_payment_confirmed_dispatches_sms_to_invoice_user(): void
|
|
{
|
|
$this->service->paymentConfirmed(Invoice::factory()->create());
|
|
|
|
Queue::assertPushed(SendPatternSms::class, 1);
|
|
}
|
|
|
|
public function test_report_ready_dispatches_sms_to_requester(): void
|
|
{
|
|
$this->service->reportReady(Document::factory()->create());
|
|
|
|
Queue::assertPushed(SendPatternSms::class, 1);
|
|
}
|
|
|
|
public function test_nothing_is_dispatched_when_pattern_is_missing(): void
|
|
{
|
|
config(['services.iranpayamak.patterns.request_registered' => null]);
|
|
|
|
$this->service->requestRegistered(Document::factory()->create());
|
|
|
|
Queue::assertNothingPushed();
|
|
}
|
|
|
|
public function test_nothing_is_dispatched_when_document_has_no_requester(): void
|
|
{
|
|
$document = Document::factory()->create();
|
|
$document->requester()->dissociate();
|
|
$document->setRelation('requester', null);
|
|
|
|
$this->service->reportReady($document);
|
|
|
|
Queue::assertNothingPushed();
|
|
}
|
|
|
|
public function test_nothing_is_dispatched_when_user_phone_is_empty(): void
|
|
{
|
|
$document = Document::factory()->create();
|
|
$document->requester->phone = '';
|
|
|
|
$this->service->requestRegistered($document);
|
|
|
|
Queue::assertNothingPushed();
|
|
}
|
|
}
|