Email quick sale receipts and send them again from the sales list
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -21,10 +21,12 @@ use App\Modules\Sales\Domain\ValueObjects\CashDayBalance;
|
||||
use App\Modules\Sales\Domain\ValueObjects\QuickSaleLine;
|
||||
use App\Modules\Sales\Domain\ValueObjects\VatTotal;
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
use App\Modules\Shared\Domain\Exceptions\InvalidEmailAddress;
|
||||
use Tests\Fakes\FakeClock;
|
||||
use Tests\Fakes\FakeCustomerQueries;
|
||||
use Tests\Fakes\FakeQuickSaleHours;
|
||||
use Tests\Fakes\FakeQuickSaleProducts;
|
||||
use Tests\Fakes\FakeReceiptMailer;
|
||||
use Tests\Fakes\FakeTransactionManager;
|
||||
use Tests\Fakes\InMemoryCashDayRepository;
|
||||
use Tests\Fakes\InMemoryQuickSaleRepository;
|
||||
@@ -35,11 +37,12 @@ beforeEach(function () {
|
||||
$this->products = new FakeQuickSaleProducts;
|
||||
$this->hours = new FakeQuickSaleHours;
|
||||
$this->customers = new FakeCustomerQueries;
|
||||
$this->mailer = new FakeReceiptMailer;
|
||||
$this->clock = new FakeClock(new DateTimeImmutable('2026-11-24'));
|
||||
$transactions = new FakeTransactionManager;
|
||||
|
||||
$this->sell = new SellQuickSale($this->sales, $this->cashDays, $this->products, $this->hours, $this->customers, $transactions, $this->clock);
|
||||
$this->credit = new CreditQuickSale($this->sales, $this->cashDays, $transactions, $this->clock);
|
||||
$this->sell = new SellQuickSale($this->sales, $this->cashDays, $this->products, $this->hours, $this->mailer, $this->customers, $transactions, $this->clock);
|
||||
$this->credit = new CreditQuickSale($this->sales, $this->cashDays, $this->mailer, $transactions, $this->clock);
|
||||
$this->close = new CloseCashDay($this->cashDays, $this->sales, $transactions, $this->clock);
|
||||
$this->reopen = new ReopenCashDay($this->cashDays, $transactions, $this->clock);
|
||||
|
||||
@@ -162,3 +165,22 @@ it('closes a day without sales with a zero balance', function () {
|
||||
|
||||
expect($day->balance())->toEqual(CashDayBalance::empty());
|
||||
});
|
||||
|
||||
it('emails the receipt when an address is given, and the credit receipt to the same address', function () {
|
||||
$plain = $this->sell->execute(1, new SaleData([1 => 1], 'cash'));
|
||||
$mailed = $this->sell->execute(1, new SaleData([1 => 1], 'card', receiptEmail: ' [email protected] '));
|
||||
|
||||
expect($plain->receiptEmail)->toBeNull()
|
||||
->and($mailed->receiptEmail)->toBe('[email protected]')
|
||||
->and($this->mailer->sent)->toBe([$mailed->saleId]);
|
||||
|
||||
$this->credit->execute($plain->saleId, 1);
|
||||
$creditId = $this->credit->execute($mailed->saleId, 1);
|
||||
|
||||
expect($this->mailer->sent)->toBe([$mailed->saleId, $creditId])
|
||||
->and($this->sales->findById($creditId)->receiptEmail()->value)->toBe('[email protected]');
|
||||
});
|
||||
|
||||
it('rejects an invalid receipt address without recording the sale', function () {
|
||||
$this->sell->execute(1, new SaleData([1 => 1], 'cash', receiptEmail: 'ei-osoite'));
|
||||
})->throws(InvalidEmailAddress::class);
|
||||
|
||||
Reference in New Issue
Block a user