159 lines
5.0 KiB
PHP
159 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\V3\RoadItemsProject;
|
|
|
|
use App\Models\Permission;
|
|
use App\Models\RoadItemsProject;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Tests\TestCase;
|
|
|
|
class UpdateTest extends TestCase
|
|
{
|
|
use RefreshDatabase, WithFaker;
|
|
|
|
public function test_start_point_is_required(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$road_item = RoadItemsProject::factory()->create();
|
|
|
|
$response = $this->actingAs($user)->postJson(route("v3.road_items.update", [$road_item->id]));
|
|
|
|
dd($response);
|
|
|
|
$response->assertUnprocessable()
|
|
->assertInvalid([
|
|
'start_point' => __('validation.required', ['attribute' => 'start point'])
|
|
]);
|
|
}
|
|
|
|
public function test_amount_is_required(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$road_item = RoadItemsProject::factory()->create();
|
|
|
|
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]));
|
|
|
|
$response->assertUnprocessable()
|
|
->assertInvalid([
|
|
'amount' => __('validation.required', ['attribute' => 'amount'])
|
|
]);
|
|
}
|
|
|
|
public function test_amount_should_be_numeric(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$road_item = RoadItemsProject::factory()->create();
|
|
|
|
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
|
|
'amount' => $this->faker->name
|
|
]);
|
|
|
|
$response->assertUnprocessable()
|
|
->assertInvalid([
|
|
'amount' => __('validation.numeric', ['attribute' => 'amount'])
|
|
]);
|
|
}
|
|
|
|
public function test_before_image_should_be_image(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$road_item = RoadItemsProject::factory()->create();
|
|
|
|
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
|
|
'before_image' => $this->faker->name
|
|
]);
|
|
|
|
$response->assertUnprocessable()
|
|
->assertInvalid([
|
|
'before_image' => __('validation.image', ['attribute' => 'before image'])
|
|
]);
|
|
}
|
|
|
|
public function test_before_image_should_be_less_than_4096kb(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$image = UploadedFile::fake()->create('image.jpg', 5096);
|
|
$road_item = RoadItemsProject::factory()->create();
|
|
|
|
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
|
|
'before_image' => $image
|
|
]);
|
|
|
|
$response->assertUnprocessable()
|
|
->assertInvalid([
|
|
'before_image' => __('validation.max.file', ['attribute' => 'before image', 'max' => 4096])
|
|
]);
|
|
}
|
|
|
|
public function test_after_image_should_be_image(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$road_item = RoadItemsProject::factory()->create();
|
|
|
|
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
|
|
'after_image' => $this->faker->randomNumber()
|
|
]);
|
|
|
|
$response->assertUnprocessable()
|
|
->assertInvalid([
|
|
'after_image' => __('validation.image', ['attribute' => 'after image'])
|
|
]);
|
|
}
|
|
|
|
public function test_after_image_should_be_less_than_4096kb(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$image = UploadedFile::fake()->create('image.jpg', 5096);
|
|
$road_item = RoadItemsProject::factory()->create();
|
|
|
|
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
|
|
'after_image' => $image
|
|
]);
|
|
|
|
$response->assertUnprocessable()
|
|
->assertInvalid([
|
|
'after_image' => __('validation.max.file', ['attribute' => 'after image', 'max' => 4096])
|
|
]);
|
|
}
|
|
|
|
public function test_cmms_machine_id_is_required(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$road_item = RoadItemsProject::factory()->create();
|
|
|
|
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]));
|
|
|
|
$response->assertUnprocessable()
|
|
->assertInvalid([
|
|
'cmms_machine_id' => __('validation.required', ['attribute' => 'cmms machine id'])
|
|
]);
|
|
}
|
|
|
|
public function test_cmms_machine_id_should_already_exists_on_the_table(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$road_item = RoadItemsProject::factory()->create();
|
|
|
|
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
|
|
'cmms_machine_id' => $this->faker->numberBetween(10, 100)
|
|
]);
|
|
|
|
$response->assertUnprocessable()
|
|
->assertInvalid([
|
|
'cmms_machine_id' => __('validation.exists', ['attribute' => 'cmms machine id'])
|
|
]);
|
|
}
|
|
}
|