added tests for send email
This commit is contained in:
@ -4,6 +4,7 @@ namespace Tests\Feature\Banking;
|
||||
|
||||
use App\Exports\Banking\Transactions as Export;
|
||||
use App\Jobs\Banking\CreateTransaction;
|
||||
use App\Notifications\Banking\Transaction as Notification;
|
||||
use App\Models\Banking\Transaction;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\File;
|
||||
@ -70,6 +71,37 @@ class TransactionsTest extends FeatureTestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function testItShouldSendTransactionEmail()
|
||||
{
|
||||
config(['mail.default' => 'array']);
|
||||
|
||||
$transaction = $this->dispatch(new CreateTransaction($this->getRequest()));
|
||||
|
||||
$this->loginAs()
|
||||
->post(route('modals.transactions.emails.store', $transaction->id), $this->getEmailRequest($transaction))
|
||||
->assertStatus(200);
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
public function testItShouldHitRateLimitForSendTransactionEmail()
|
||||
{
|
||||
config(['mail.default' => 'array']);
|
||||
|
||||
$transaction = $this->dispatch(new CreateTransaction($this->getRequest()));
|
||||
|
||||
for ($i = 0; $i < config('app.throttles.email.minute'); $i++) {
|
||||
$this->loginAs()
|
||||
->post(route('modals.transactions.emails.store', $transaction->id), $this->getEmailRequest($transaction));
|
||||
}
|
||||
|
||||
$this->loginAs()
|
||||
->post(route('modals.transactions.emails.store', $transaction->id), $this->getEmailRequest($transaction))
|
||||
->assertJson([
|
||||
'success' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testItShouldSeeTransactionUpdatePage()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
@ -192,4 +224,18 @@ class TransactionsTest extends FeatureTestCase
|
||||
|
||||
return $factory->raw();
|
||||
}
|
||||
|
||||
public function getEmailRequest($transaction)
|
||||
{
|
||||
$email_template = config('type.transaction.' . $transaction->type . '.email_template');
|
||||
|
||||
$notification = new Notification($transaction, $email_template, true);
|
||||
|
||||
return [
|
||||
'transaction_id' => $transaction->id,
|
||||
'to' => $transaction->contact->email,
|
||||
'subject' => $notification->getSubject(),
|
||||
'body' => $notification->getBody(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user