mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-23 22:44:08 +00:00
68 lines
2.5 KiB
PHP
68 lines
2.5 KiB
PHP
<?php
|
|
/**
|
|
* Original controller logic file:
|
|
* app/Classes/Modules/Segments/ControllersLogic/UpdateConstantLogic.php
|
|
*/
|
|
|
|
namespace Tests\Feature\Segments\ControllersLogic;
|
|
|
|
use App\Classes\ValueObjects\Constants\SegmentConstants;
|
|
use PHPUnit\Framework\Attributes\Group;
|
|
|
|
#[Group('feature')]
|
|
#[Group('segments')]
|
|
#[Group('controllers_logic')]
|
|
#[Group('ok_to_run')]
|
|
class UpdateConstantLogicTest extends SegmentsControllerLogicTestCase
|
|
{
|
|
public function test_it_can_update_an_existing_constant_via_controller_logic()
|
|
{
|
|
// A R R A N G E
|
|
$segment = $this->createSegment('update_constant_logic_existing');
|
|
$this->createConstant($segment, 'update_constant_logic_existing_reference', [
|
|
1 => ['rate' => 10],
|
|
]);
|
|
$payload = [
|
|
'reference' => 'update_constant_logic_existing_reference',
|
|
'id' => 2,
|
|
'rate' => ['rate' => 15],
|
|
];
|
|
|
|
// A C T
|
|
$response = $this->actingAsAdmin()
|
|
->putJson("/api/v1/segment/{$segment->id}/constant/update", $payload);
|
|
|
|
// A S S E R T
|
|
$response->assertStatus(200);
|
|
$response->assertJsonPath('payload.data.reference', 'update_constant_logic_existing_reference');
|
|
$constant = $segment->constants()->where('reference', 'update_constant_logic_existing_reference')->first();
|
|
$this->assertEquals(['rate' => 15], $constant->value[2] ?? $constant->value['2'] ?? null);
|
|
}
|
|
|
|
public function test_it_can_create_a_missing_constant_via_controller_logic()
|
|
{
|
|
// A R R A N G E
|
|
$segment = $this->createSegment('update_constant_logic_missing');
|
|
$payload = [
|
|
'reference' => 'update_constant_logic_missing_reference',
|
|
'id' => 8,
|
|
'value' => ['rate' => 44],
|
|
];
|
|
|
|
// A C T
|
|
$response = $this->actingAsAdmin()
|
|
->putJson("/api/v1/segment/{$segment->id}/constant/update", $payload);
|
|
|
|
// A S S E R T
|
|
$response->assertStatus(200);
|
|
$response->assertJsonPath('payload.data.reference', 'update_constant_logic_missing_reference');
|
|
$constant = $segment->constants()->where('reference', 'update_constant_logic_missing_reference')->first();
|
|
$this->assertEquals(['rate' => 44], $constant->value[8] ?? $constant->value['8'] ?? null);
|
|
|
|
$this->assertDatabaseHas('segment_constants', [
|
|
'segment_id' => $segment->id,
|
|
'reference' => 'update_constant_logic_missing_reference',
|
|
]);
|
|
}
|
|
}
|