-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from dystcz/feat/add-cart-checked-out-event
Feat: Add cart checked out event
- Loading branch information
Showing
6 changed files
with
89 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Dystore\Api\Domain\Carts\Events; | ||
|
||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Lunar\Models\Contracts\Cart as CartContract; | ||
use Lunar\Models\Contracts\Order as OrderContract; | ||
|
||
class CartCheckedOut | ||
{ | ||
use Dispatchable; | ||
|
||
public function __construct( | ||
public CartContract $cart, | ||
public OrderContract $order, | ||
) {} | ||
} |
50 changes: 50 additions & 0 deletions
50
tests/api/Feature/Domain/Cart/Events/CartCheckedOutTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
use Dystore\Api\Domain\Carts\Actions\CheckoutCart; | ||
use Dystore\Api\Domain\Carts\Contracts\CheckoutCart as CheckoutCartContract; | ||
use Dystore\Api\Domain\Carts\Events\CartCheckedOut; | ||
use Dystore\Api\Domain\Carts\Factories\CartFactory; | ||
use Dystore\Api\Domain\Carts\Models\Cart; | ||
use Dystore\Api\Domain\Users\Models\User; | ||
use Dystore\Tests\Api\TestCase; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Facades\App; | ||
use Illuminate\Support\Facades\Event; | ||
use Lunar\Base\CartSessionInterface; | ||
use Lunar\Managers\CartSessionManager; | ||
|
||
uses(TestCase::class, RefreshDatabase::class) | ||
->group('carts', 'carts.events', 'events'); | ||
|
||
it('dispatches cart checked out event after checkout', function () { | ||
/** @var TestUser $this */ | ||
Event::fake([ | ||
CartCheckedOut::class, | ||
]); | ||
|
||
$user = User::factory()->create(); | ||
|
||
/** @var CartFactory $cartFactory */ | ||
$cartFactory = Cart::factory(); | ||
|
||
/** @var Cart $cart */ | ||
$cart = $cartFactory | ||
->withAddresses() | ||
->withLines() | ||
->create(); | ||
|
||
/** @var CartSessionManager $cartSession */ | ||
$cartSession = App::make(CartSessionInterface::class); | ||
$cartSession->use($cart); | ||
|
||
/** @var CheckoutCart $checkoutAction */ | ||
$checkoutAction = App::make(CheckoutCartContract::class); | ||
|
||
$order = $checkoutAction->handle($cart); | ||
|
||
Event::assertDispatched( | ||
CartCheckedOut::class, | ||
fn (CartCheckedOut $event) => $event->cart->getKey() === $cart->getKey() | ||
&& $event->order->getKey() === $order->getKey(), | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters