Skip to content

Commit

Permalink
Add test to delete an order (#1839)
Browse files Browse the repository at this point in the history
Attempting to reproduce #1786

Co-authored-by: Glenn Jacobs <[email protected]>
  • Loading branch information
alecritson and glennjacobs authored Jul 5, 2024
1 parent 041823e commit 74dd68f
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/core/Unit/Models/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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,
]);
});

0 comments on commit 74dd68f

Please sign in to comment.