91 lines
2.4 KiB
PHP
91 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Contracts\Directories\OrderDirectory;
|
|
use App\Models\Customer;
|
|
use App\Models\Order;
|
|
use App\Services\OrderService;
|
|
use Domain\Models\ValueObjects\Pagination;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
covers(OrderService::class);
|
|
|
|
describe('OrderService', function () {
|
|
afterEach(function () {
|
|
\Mockery::close();
|
|
});
|
|
|
|
it('paginates orders for a customer', function () {
|
|
// GIVEN
|
|
$orderDirectory = \Mockery::mock(OrderDirectory::class);
|
|
|
|
$customer = new Customer();
|
|
$customer->id = (string) Uuid::uuid7();
|
|
|
|
$pagination = new Pagination(0, 15);
|
|
$paginator = new LengthAwarePaginator([], 0, 15);
|
|
|
|
$orderDirectory->shouldReceive('getPaginatedOrdersOf')
|
|
->with($customer, $pagination, true)
|
|
->once()
|
|
->andReturn($paginator);
|
|
|
|
$service = new OrderService($orderDirectory);
|
|
|
|
// WHEN
|
|
$result = $service->paginateOrdersFor($customer, $pagination);
|
|
|
|
// THEN
|
|
expect($result)->toBe($paginator);
|
|
});
|
|
|
|
it('returns true if order is owned by customer', function () {
|
|
// GIVEN
|
|
$orderDirectory = \Mockery::mock(OrderDirectory::class);
|
|
|
|
$customer = new Customer();
|
|
$customer->id = (string) Uuid::uuid7();
|
|
|
|
$order = new Order();
|
|
$order->id = (string) Uuid::uuid7();
|
|
|
|
$orderDirectory->shouldReceive('findOf')
|
|
->with($customer, $order->id)
|
|
->once()
|
|
->andReturn($order);
|
|
|
|
$service = new OrderService($orderDirectory);
|
|
|
|
// WHEN
|
|
$result = $service->isOrderOwnedBy($order, $customer);
|
|
|
|
// THEN
|
|
expect($result)->toBeTrue();
|
|
});
|
|
|
|
it('returns false if order is not owned by customer', function () {
|
|
// GIVEN
|
|
$orderDirectory = \Mockery::mock(OrderDirectory::class);
|
|
|
|
$customer = new Customer();
|
|
$customer->id = (string) Uuid::uuid7();
|
|
|
|
$order = new Order();
|
|
$order->id = (string) Uuid::uuid7();
|
|
|
|
$orderDirectory->shouldReceive('findOf')
|
|
->with($customer, $order->id)
|
|
->once()
|
|
->andReturn(null);
|
|
|
|
$service = new OrderService($orderDirectory);
|
|
|
|
// WHEN
|
|
$result = $service->isOrderOwnedBy($order, $customer);
|
|
|
|
// THEN
|
|
expect($result)->toBeFalse();
|
|
});
|
|
});
|