111 lines
3.6 KiB
PHP
111 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use Tests\TestCase;
|
|
use App\Services\PrinterService;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\Facades\View;
|
|
|
|
class PrinterServiceTest extends TestCase
|
|
{
|
|
public function test_printForCheckout_calls_printPickupSlip_with_correct_data()
|
|
{
|
|
Mail::fake();
|
|
Config::set('services.printer.enabled', true);
|
|
Config::set('services.printer.email', 'printer@example.com');
|
|
Config::set('mail.from.address', 'hello@example.com');
|
|
Config::set('mail.from.name', 'Example');
|
|
|
|
// Mock Checkout model
|
|
$checkout = \Mockery::mock(\App\Models\Checkout::class)->makePartial();
|
|
$checkout->bidder_num = 1;
|
|
$checkout->checkout_id = 1;
|
|
$checkout->payment_method = 1;
|
|
$checkout->check_number = null;
|
|
$checkout->cc_transaction = null;
|
|
|
|
// Mock DB calls
|
|
\Illuminate\Support\Facades\DB::shouldReceive('select')
|
|
->twice()
|
|
->andReturn([
|
|
(object)['item_assigned_num' => 'A1', 'item_desc' => 'Test', 'winning_cost' => 50]
|
|
], [
|
|
(object)[
|
|
'bidder_assigned_number' => '123',
|
|
'total_cost' => '50',
|
|
'bidder_fname' => 'John',
|
|
'bidder_lname' => 'Doe',
|
|
'bidder_phone' => '1234567890',
|
|
'bidder_addr' => '123 St',
|
|
'bidder_city' => 'Troy',
|
|
'bidder_state' => 'MI',
|
|
'bidder_zip' => '48083'
|
|
]
|
|
]);
|
|
|
|
$service = new PrinterService();
|
|
$service->printForCheckout($checkout);
|
|
|
|
Mail::assertSent(\App\Mail\PickupSlipMail::class);
|
|
}
|
|
|
|
public function test_printPickupSlip_sends_email_when_enabled()
|
|
{
|
|
Mail::fake();
|
|
Config::set('services.printer.enabled', true);
|
|
Config::set('services.printer.email', 'printer@example.com');
|
|
Config::set('mail.from.address', 'hello@example.com');
|
|
Config::set('mail.from.name', 'Example');
|
|
|
|
// Mock data matching what receiptpdf expects
|
|
$checkoutData = [
|
|
'checkout_final_results' => (object)[
|
|
'payment_method' => 1,
|
|
'check_number' => null,
|
|
'cc_transaction' => null,
|
|
'checkout_id' => 1
|
|
],
|
|
'checkout_list_results' => [
|
|
(object)[
|
|
'item_assigned_num' => 'A1',
|
|
'item_desc' => 'Test Item',
|
|
'winning_cost' => '50'
|
|
]
|
|
],
|
|
'checkout_info_results' => [
|
|
(object)[
|
|
'bidder_assigned_number' => '123',
|
|
'total_cost' => '50',
|
|
'bidder_fname' => 'John',
|
|
'bidder_lname' => 'Doe',
|
|
'bidder_phone' => '1234567890',
|
|
'bidder_addr' => '123 St',
|
|
'bidder_city' => 'Troy',
|
|
'bidder_state' => 'MI',
|
|
'bidder_zip' => '48083'
|
|
]
|
|
]
|
|
];
|
|
|
|
$service = new PrinterService();
|
|
$service->printPickupSlip($checkoutData);
|
|
|
|
Mail::assertSent(\App\Mail\PickupSlipMail::class, function ($mail) {
|
|
return $mail->hasTo('printer@example.com');
|
|
});
|
|
}
|
|
|
|
public function test_printPickupSlip_does_not_send_email_when_disabled()
|
|
{
|
|
Mail::fake();
|
|
Config::set('services.printer.enabled', false);
|
|
|
|
$service = new PrinterService();
|
|
$service->printPickupSlip([]);
|
|
|
|
Mail::assertNothingSent();
|
|
}
|
|
}
|