mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
New UI to show YD Order Tracking infomation - Testing
This commit is contained in:
Vendored
+1
-1
@@ -70,7 +70,7 @@ pipeline {
|
||||
),
|
||||
string(credentialsId: 'shipping-portal-dev-db-host', variable: 'DB_HOST')
|
||||
]) {
|
||||
// sh 'vendor/bin/phpunit --filter ListOrderTrackingLogicTest'
|
||||
sh 'vendor/bin/phpunit --filter ListOrderTrackingLogicTest'
|
||||
}
|
||||
script{
|
||||
currentBuild.description = 'Step 4 of 6 Completed'
|
||||
|
||||
@@ -2,19 +2,26 @@
|
||||
|
||||
namespace Tests\Unit\App\Classes\Modules\Orders\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\Modules\Orders\ControllersLogic\ListOrderTrackingLogic;
|
||||
use App\Classes\Modules\Orders\Services\ListsOrderTracking;
|
||||
use App\Models\Order;
|
||||
use App\Models\PackingList;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Mockery;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Tests\TestCaseChild;
|
||||
|
||||
class ListOrderTrackingLogicTest extends TestCaseChild
|
||||
{
|
||||
|
||||
protected $listsOrderTrackingMock;
|
||||
protected $listOrderTrackingLogic;
|
||||
|
||||
@@ -32,6 +39,7 @@ class ListOrderTrackingLogicTest extends TestCaseChild
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
|
||||
public function test_logic_with_valid_tracking_number()
|
||||
{
|
||||
// Arrange
|
||||
@@ -66,32 +74,58 @@ class ListOrderTrackingLogicTest extends TestCaseChild
|
||||
$this->listsOrderTrackingMock->shouldReceive('execute')
|
||||
->andReturn(collect([]));
|
||||
|
||||
$fakeRequest = Request::create('/tracking', 'GET', ['filters' => json_encode(['tracking_no' => $trackingNo])]);
|
||||
$fakeRequest = Request::create('/tracking', 'GET', ['filters' => json_encode(['tracking_no' => Crypt::encryptString($trackingNo)])]);
|
||||
|
||||
// Act
|
||||
$response = $this->listOrderTrackingLogic->logic($fakeRequest);
|
||||
|
||||
Log::info("response 1: " . json_encode($response));
|
||||
|
||||
// Assert
|
||||
$this->assertInstanceOf(JsonResponse::class, $response);
|
||||
}
|
||||
|
||||
public function test_logic_with_invalid_tracking_number()
|
||||
public function test_logic_with_invalid_tracking_number_for_admin()
|
||||
{
|
||||
// Arrange
|
||||
Artisan::shouldReceive('call')->never();
|
||||
// Arrange
|
||||
$user = (object) ['type' => ['ADMIN']];
|
||||
Auth::shouldReceive('user')->andReturn($user);
|
||||
|
||||
$this->listsOrderTrackingMock->shouldReceive('deserializeFilters')
|
||||
->andReturn(['tracking_no' => 'invalid']);
|
||||
->andReturn(['tracking_no' => Crypt::encryptString('invalid')]);
|
||||
|
||||
$this->listsOrderTrackingMock->shouldReceive('execute')
|
||||
->andReturn(collect([]));
|
||||
|
||||
$request = Request::create('/tracking', 'GET', ['filters' => json_encode(['tracking_no' => 'invalid'])]);
|
||||
$request = Request::create('/tracking', 'GET', ['filters' => json_encode(['tracking_no' => Crypt::encryptString('invalid')])]);
|
||||
|
||||
Artisan::shouldReceive('call')
|
||||
->once()
|
||||
->withArgs(['process-yd-by-traking-no-data-command', ['trackingNo' => 'invalid']])
|
||||
->andReturn(0);
|
||||
|
||||
// Act
|
||||
$fakeRequest = $this->listOrderTrackingLogic->logic($request);
|
||||
$data = $fakeRequest->getData(true); // returns array
|
||||
|
||||
// Assert
|
||||
$this->assertTrue(empty($data['original']['payload']['data']));
|
||||
$this->assertInstanceOf(JsonResponse::class, $fakeRequest);
|
||||
}
|
||||
|
||||
public function test_it_throws_404_when_decryption_fails_for_non_admin()
|
||||
{
|
||||
// Arrange
|
||||
$user = (object) ['type' => ['REGULAR_USER']];
|
||||
Auth::shouldReceive('user')->andReturn($user);
|
||||
|
||||
Crypt::shouldReceive('decryptString')->andThrow(DecryptException::class);
|
||||
$request = Request::create('/tracking', 'GET', ['filters' => json_encode(['tracking_no' => 'test'])]);
|
||||
|
||||
// Assert
|
||||
$this->expectException(NotFoundHttpException::class);
|
||||
|
||||
// Act
|
||||
$this->listOrderTrackingLogic->logic($request);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user