mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-30 09:54:04 +00:00
162 lines
6.3 KiB
PHP
162 lines
6.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Orders\Processors;
|
|
|
|
use App\Classes\Modules\Orders\Processors\CreateOrderProcessor;
|
|
use App\Classes\Modules\Orders\Processors\CreateOrderRolesProcessor;
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\ValueObjects\Constants\BusinessType;
|
|
use App\Classes\ValueObjects\Constants\OrderType;
|
|
use App\Classes\ValueObjects\Constants\WarehouseReferences;
|
|
use App\Models\Address;
|
|
use App\Models\Company;
|
|
use App\Models\CompanyModule;
|
|
use App\Models\Order;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Tests\TestCaseChild;
|
|
|
|
use PHPUnit\Framework\Attributes\Group;
|
|
|
|
#[Group('feature')]
|
|
#[Group('orders')]
|
|
#[Group('processors')]
|
|
#[Group('ok_to_run')]
|
|
class CreateOrderTest extends TestCaseChild
|
|
{
|
|
// use DatabaseTransactions;
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
/**
|
|
* @return void
|
|
*/
|
|
public function test_it_can_create_an_order_via_processor()
|
|
{
|
|
// A R R A N G E
|
|
|
|
// 1. Create CIEF Company (Supervisor required by CreateOrderRolesProcessor)
|
|
$cief = new Company();
|
|
$cief->name = 'CIEF';
|
|
$cief->reference = 'CIEF';
|
|
$cief->status = ApprovalStatus::APPROVED;
|
|
$cief->save();
|
|
|
|
$ciefFreightForwarder = new CompanyModule();
|
|
$ciefFreightForwarder->company_id = $cief->id;
|
|
$ciefFreightForwarder->type = BusinessType::FREIGHT_FORWARDER;
|
|
$ciefFreightForwarder->status = ApprovalStatus::APPROVED;
|
|
$ciefFreightForwarder->name = 'CIEF Freight Forwarder';
|
|
$ciefFreightForwarder->reference = 'CIEF';
|
|
$ciefFreightForwarder->unity_hash_id = 'CIEF-HASH-' . uniqid();
|
|
$ciefFreightForwarder->unity_signature = 'CIEF-SIG-' . uniqid();
|
|
$ciefFreightForwarder->save();
|
|
|
|
// 2. Create Destination Warehouse (required by CreateOrderRolesProcessor)
|
|
$destWarehouseCompany = new Company();
|
|
$destWarehouseCompany->name = 'Destination Warehouse Company';
|
|
$destWarehouseCompany->reference = 'DWC-' . uniqid();
|
|
$destWarehouseCompany->status = ApprovalStatus::APPROVED;
|
|
$destWarehouseCompany->save();
|
|
|
|
$destWarehouseModule = new CompanyModule();
|
|
$destWarehouseModule->company_id = $destWarehouseCompany->id;
|
|
$destWarehouseModule->reference = WarehouseReferences::YD_DESTINATION_WAREHOUSE;
|
|
$destWarehouseModule->type = BusinessType::WAREHOUSE;
|
|
$destWarehouseModule->status = ApprovalStatus::APPROVED;
|
|
$destWarehouseModule->name = 'Destination Warehouse Module';
|
|
$destWarehouseModule->unity_hash_id = 'DWM-HASH-' . uniqid();
|
|
$destWarehouseModule->unity_signature = 'DWM-SIG-' . uniqid();
|
|
$destWarehouseModule->save();
|
|
|
|
// 3. Create Origin Warehouse and its Freight Forwarder (required by CreateOrderRolesProcessor)
|
|
$originWarehouseCompany = new Company();
|
|
$originWarehouseCompany->name = 'Origin Warehouse Company';
|
|
$originWarehouseCompany->reference = 'OWC-' . uniqid();
|
|
$originWarehouseCompany->status = ApprovalStatus::APPROVED;
|
|
$originWarehouseCompany->save();
|
|
|
|
$originWarehouse = new CompanyModule();
|
|
$originWarehouse->company_id = $originWarehouseCompany->id;
|
|
$originWarehouse->reference = WarehouseReferences::YD_GUANG_ZHOU;
|
|
$originWarehouse->type = BusinessType::WAREHOUSE;
|
|
$originWarehouse->status = ApprovalStatus::APPROVED;
|
|
$originWarehouse->name = 'Origin Warehouse Module';
|
|
$originWarehouse->unity_hash_id = 'OWM-HASH-' . uniqid();
|
|
$originWarehouse->unity_signature = 'OWM-SIG-' . uniqid();
|
|
$originWarehouse->save();
|
|
|
|
$originFreightForwarder = new CompanyModule();
|
|
$originFreightForwarder->company_id = $originWarehouseCompany->id;
|
|
$originFreightForwarder->type = BusinessType::FREIGHT_FORWARDER;
|
|
$originFreightForwarder->status = ApprovalStatus::APPROVED;
|
|
$originFreightForwarder->name = 'Origin Freight Forwarder';
|
|
$originFreightForwarder->reference = 'OFF-' . uniqid();
|
|
$originFreightForwarder->unity_hash_id = 'OFF-HASH-' . uniqid();
|
|
$originFreightForwarder->unity_signature = 'OFF-SIG-' . uniqid();
|
|
$originFreightForwarder->save();
|
|
|
|
// 4. Create Importer Company
|
|
$importerCompany = new Company();
|
|
$importerCompany->name = 'Test Importer';
|
|
$importerCompany->reference = '123456789';
|
|
$importerCompany->status = ApprovalStatus::APPROVED;
|
|
$importerCompany->save();
|
|
|
|
$importerModule = new CompanyModule();
|
|
$importerModule->company_id = $importerCompany->id;
|
|
$importerModule->type = BusinessType::IMPORTER;
|
|
$importerModule->status = ApprovalStatus::APPROVED;
|
|
$importerModule->name = 'Test Importer Module';
|
|
$importerModule->reference = 'TEST-IMP-' . uniqid();
|
|
$importerModule->unity_hash_id = 'IM-HASH-' . uniqid();
|
|
$importerModule->unity_signature = 'IM-SIG-' . uniqid();
|
|
$importerModule->save();
|
|
|
|
// 5. Create Input Address
|
|
$address = new Address();
|
|
$address->street_one = '123 Test St';
|
|
$address->country_id = 1;
|
|
$address->district_id = 1;
|
|
$address->state_id = 1;
|
|
$address->postcode = '12345';
|
|
$address->type = 1;
|
|
$address->owner_type = Company::class;
|
|
$address->owner_id = $importerCompany->id;
|
|
$address->save();
|
|
|
|
/** @var CreateOrderProcessor $processor */
|
|
$processor = app(CreateOrderProcessor::class);
|
|
|
|
$orderNumber = mt_rand(100000, 999999);
|
|
|
|
// A C T
|
|
$order = $processor->execute(
|
|
$importerCompany,
|
|
$originWarehouse,
|
|
$address,
|
|
$orderNumber
|
|
);
|
|
|
|
// A S S E R T
|
|
$this->assertInstanceOf(Order::class, $order);
|
|
$this->assertEquals($orderNumber, $order->reference);
|
|
$this->assertEquals(OrderType::SHARED_CONTAINER, $order->type);
|
|
|
|
// Verify Order Address was created
|
|
$this->assertCount(1, $order->addresses);
|
|
$this->assertEquals($address->street_one, $order->addresses->first()->street_one);
|
|
|
|
// Verify Roles (at least basic ones)
|
|
$this->assertDatabaseHas('order_roles', [
|
|
'order_id' => $order->id,
|
|
'company_module_id' => $originWarehouse->id,
|
|
]);
|
|
|
|
$this->assertDatabaseHas('orders', [
|
|
'id' => $order->id,
|
|
'reference' => $orderNumber
|
|
]);
|
|
}
|
|
}
|