Führe Rabattcodes, Nutzerkreis der Lizenzoption und Pflichtangaben der Kasse ein
Domäne: Rabattcodes mit Geltungsbereich (Warenkorb oder gewählte Ziele) und Einlösungsberechtigung (allgemein oder freigeschaltete Konten) unabhängig voneinander; Prüfung bei Eingabe, in jeder Übersicht und unter Sperre vor Bestellabschluss (Prüfsumme der Übersicht enthält den Rabatt). Rabatt je Position, Zwischensumme und Zahlbetrag in der Bestellung; Stripe erhält den Preis nach Rabatt. Nutzerkreis (Einzel-/Mehrfachlizenz, Trainerzahl) an der Angebotsfassung, kopiert in Bestellposition und Erwerb, Teil der Prüfung "Bereits erworben". OfferService::activate lehnt Angebote ohne veröffentlichten Artikelstand ab. Kasse: Zustimmungen als Pflichtangabe mit Nachweis, "Zahlungspflichtig bestellen", Rechnungsweg für Organisationen, Erstattung über Stripe, Widerruf erklären. Produktivfreigabe SHOP_LIVE_RELEASE standardmäßig aus. Bestandstests geändert (fachlich überholt, Assertions nicht abgeschwächt): die Schaltfläche heißt "Zahlungspflichtig bestellen" (§ 312j BGB), die Summe heißt "Zu zahlen", der Vereinshinweis steht als Rollenliste; Bestellungen über die Kasse senden jetzt die Zustimmungen. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cb80835c92
commit
0154182f3b
40 files changed
+2151
-92
No files matched your search
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Domain\Commerce\Discount\DiscountCalculator;
|
||||
use App\Domain\Commerce\Discount\DiscountCode;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Rechenregel des Rabatts je Position (ganze Cent). Die Rundung ist eine Entscheidung zur Bestätigung durch Lars;
|
||||
* die Tests halten fest, was heute gilt.
|
||||
*/
|
||||
class DiscountCalculatorTest extends TestCase
|
||||
{
|
||||
public function test_a_percentage_is_rounded_per_line_half_up(): void
|
||||
{
|
||||
// Drei Positionen zu je 0,99 €, 50 %: je Position 49,5 Cent, aufgerundet auf 50 Cent.
|
||||
$discounts = DiscountCalculator::allocate(DiscountCode::PERCENT, 50, null, [1 => 99, 2 => 99, 3 => 99]);
|
||||
|
||||
$this->assertSame([1 => 50, 2 => 50, 3 => 50], $discounts);
|
||||
$this->assertSame(150, array_sum($discounts), 'Auf der Warenkorbsumme gerundet wären es 149 Cent.');
|
||||
}
|
||||
|
||||
public function test_a_percentage_never_exceeds_the_line_price(): void
|
||||
{
|
||||
$this->assertSame([1 => 4900], DiscountCalculator::allocate(DiscountCode::PERCENT, 100, null, [1 => 4900]));
|
||||
$this->assertSame([1 => 4900], DiscountCalculator::allocate(DiscountCode::PERCENT, 250, null, [1 => 4900]));
|
||||
$this->assertSame([1 => 0], DiscountCalculator::allocate(DiscountCode::PERCENT, 0, null, [1 => 4900]));
|
||||
}
|
||||
|
||||
public function test_a_fixed_amount_is_distributed_in_proportion_to_the_prices(): void
|
||||
{
|
||||
$this->assertSame([1 => 600, 2 => 400], DiscountCalculator::allocate(DiscountCode::AMOUNT, null, 1000, [1 => 3000, 2 => 2000]));
|
||||
}
|
||||
|
||||
public function test_the_remaining_cents_go_to_the_largest_remainder_and_the_sum_is_exact(): void
|
||||
{
|
||||
$discounts = DiscountCalculator::allocate(DiscountCode::AMOUNT, null, 100, [1 => 3333, 2 => 3333, 3 => 3334]);
|
||||
|
||||
$this->assertSame([1 => 33, 2 => 33, 3 => 34], $discounts);
|
||||
$this->assertSame(100, array_sum($discounts));
|
||||
}
|
||||
|
||||
public function test_a_fixed_amount_is_capped_at_the_affected_total(): void
|
||||
{
|
||||
$discounts = DiscountCalculator::allocate(DiscountCode::AMOUNT, null, 99999, [1 => 2900, 2 => 4900]);
|
||||
|
||||
$this->assertSame([1 => 2900, 2 => 4900], $discounts);
|
||||
}
|
||||
|
||||
public function test_nothing_to_discount_yields_nothing(): void
|
||||
{
|
||||
$this->assertSame([], DiscountCalculator::allocate(DiscountCode::PERCENT, 10, null, []));
|
||||
$this->assertSame([1 => 0], DiscountCalculator::allocate(DiscountCode::AMOUNT, null, 0, [1 => 100]));
|
||||
}
|
||||
|
||||
public function test_codes_are_normalised_without_spaces_and_in_capitals(): void
|
||||
{
|
||||
$this->assertSame('ZERT-2026', DiscountCode::normalise(' zert-2026 '));
|
||||
$this->assertSame('SOMMER10', DiscountCode::normalise('sommer 10'));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user