diff --git a/tests/core/Unit/Models/OrderTest.php b/tests/core/Unit/Models/OrderTest.php index 0ecc5df282..027fa8e0fd 100644 --- a/tests/core/Unit/Models/OrderTest.php +++ b/tests/core/Unit/Models/OrderTest.php @@ -16,6 +16,10 @@ use Lunar\Models\Transaction; use Lunar\Tests\Core\Stubs\User; +use function Pest\Laravel\assertDatabaseCount; +use function Pest\Laravel\assertDatabaseHas; +use function Pest\Laravel\assertDatabaseMissing; + uses(\Illuminate\Foundation\Testing\RefreshDatabase::class); beforeEach(function () { @@ -246,3 +250,47 @@ expect($breakdownItem->price)->toBeInstanceOf(Price::class); expect($breakdownItem->price->value)->toEqual(123); }); + +test('can delete an order', function () { + Currency::factory()->create([ + 'default' => false, + ]); + $currency = Currency::factory()->create([ + 'default' => true, + ]); + + $order = Order::factory()->create([ + 'user_id' => null, + 'currency_code' => $currency->code, + ]); + + OrderLine::factory(4)->create([ + 'order_id' => $order->id, + 'tax_breakdown' => new TaxBreakdown(collect([ + new \Lunar\Base\ValueObjects\Cart\TaxBreakdownAmount( + price: new Price(10, $currency), + identifier: 'VAT', + description: 'VAT', + percentage: 20 + ), + ])), + ]); + + assertDatabaseCount((new OrderLine)->getTable(), 4); + + foreach ($order->refresh()->lines as $line) { + $line->delete(); + } + + assertDatabaseCount(OrderLine::class, 0); + + assertDatabaseHas(Order::class, [ + 'id' => $order->id, + ]); + + $order->delete(); + + assertDatabaseMissing(Order::class, [ + 'id' => $order->id, + ]); +});