transfer all api's from v2 road items to v3
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace Tests\Feature\V3\RoadItemsProject;
|
||||
|
||||
use App\Models\City;
|
||||
use App\Models\CMMSMachine;
|
||||
use App\Models\EdarateOstani;
|
||||
use App\Models\EdarateShahri;
|
||||
use App\Models\InfoItem;
|
||||
@@ -336,9 +337,44 @@ class StoreTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_cmms_machine_id_is_required(): void
|
||||
{
|
||||
$user = User::factory()
|
||||
->has(Permission::factory([
|
||||
'name' => 'create-road-item'
|
||||
]))
|
||||
->create();
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('v3.road_items.store'));
|
||||
|
||||
$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()
|
||||
->has(Permission::factory([
|
||||
'name' => 'create-road-item'
|
||||
]))
|
||||
->create();
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [
|
||||
'cmms_machine_id' => $this->faker->numberBetween(10, 100)
|
||||
]);
|
||||
|
||||
$response->assertUnprocessable()
|
||||
->assertInvalid([
|
||||
'cmms_machine_id' => __('validation.exists', ['attribute' => 'cmms machine id'])
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_province_user_is_prohibited_to_access(): void
|
||||
{
|
||||
$edarateOstani = EdarateOstani::factory()->create();
|
||||
$cmmsMachine = CMMSMachine::factory()->create();
|
||||
|
||||
$user = User::factory()
|
||||
->has(Permission::factory([
|
||||
@@ -356,7 +392,8 @@ class StoreTest extends TestCase
|
||||
'activity_date' => $this->faker->date(),
|
||||
'activity_time' => $this->faker->date('H:i'),
|
||||
'before_image' => UploadedFile::fake()->create('image.jpg', 10),
|
||||
'after_image' => UploadedFile::fake()->create('image.jpg', 10)
|
||||
'after_image' => UploadedFile::fake()->create('image.jpg', 10),
|
||||
'cmms_machine_id' => $cmmsMachine->id
|
||||
];
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data);
|
||||
@@ -370,6 +407,7 @@ class StoreTest extends TestCase
|
||||
public function test_user_should_have_edarate_shahri_id(): void
|
||||
{
|
||||
$city = City::factory()->create();
|
||||
$cmmsMachine = CMMSMachine::factory()->create();
|
||||
|
||||
$user = User::factory()
|
||||
->has(Permission::factory([
|
||||
@@ -387,7 +425,8 @@ class StoreTest extends TestCase
|
||||
'activity_date' => $this->faker->date(),
|
||||
'activity_time' => $this->faker->date('H:i'),
|
||||
'before_image' => UploadedFile::fake()->create('image.jpg', 10),
|
||||
'after_image' => UploadedFile::fake()->create('image.jpg', 10)
|
||||
'after_image' => UploadedFile::fake()->create('image.jpg', 10),
|
||||
'cmms_machine_id' => $cmmsMachine->id
|
||||
];
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data);
|
||||
@@ -402,6 +441,7 @@ class StoreTest extends TestCase
|
||||
{
|
||||
$city = City::factory()->create();
|
||||
$edarateShari = EdarateShahri::factory()->create();
|
||||
$cmmsMachine = CMMSMachine::factory()->create();
|
||||
|
||||
$user = User::factory()
|
||||
->has(Permission::factory([
|
||||
@@ -420,7 +460,8 @@ class StoreTest extends TestCase
|
||||
'activity_date' => $this->faker->date(),
|
||||
'activity_time' => $this->faker->date('H:i'),
|
||||
'before_image' => UploadedFile::fake()->create('image.jpg', 10),
|
||||
'after_image' => UploadedFile::fake()->create('image.jpg', 10)
|
||||
'after_image' => UploadedFile::fake()->create('image.jpg', 10),
|
||||
'cmms_machine_id' => $cmmsMachine->id
|
||||
];
|
||||
|
||||
InfoItem::factory()->create([
|
||||
@@ -441,6 +482,7 @@ class StoreTest extends TestCase
|
||||
{
|
||||
$city = City::factory()->create();
|
||||
$edarateShari = EdarateShahri::factory()->create();
|
||||
$cmmsMachine = CMMSMachine::factory()->create();
|
||||
|
||||
$user = User::factory()
|
||||
->has(Permission::factory([
|
||||
@@ -458,6 +500,7 @@ class StoreTest extends TestCase
|
||||
'amount' => $this->faker->numberBetween(1, 10),
|
||||
'activity_date' => $this->faker->date(),
|
||||
'activity_time' => $this->faker->date('H:i'),
|
||||
'cmms_machine_id' => $cmmsMachine->id
|
||||
];
|
||||
|
||||
InfoItem::factory()->create([
|
||||
@@ -478,6 +521,7 @@ class StoreTest extends TestCase
|
||||
{
|
||||
$city = City::factory()->create();
|
||||
$edarateShari = EdarateShahri::factory()->create();
|
||||
$cmmsMachine = CMMSMachine::factory()->create();
|
||||
|
||||
$user = User::factory()
|
||||
->has(Permission::factory([
|
||||
@@ -495,6 +539,7 @@ class StoreTest extends TestCase
|
||||
'amount' => $this->faker->numberBetween(1, 10),
|
||||
'activity_date' => $this->faker->date(),
|
||||
'activity_time' => $this->faker->date('H:i'),
|
||||
'cmms_machine_id' => $cmmsMachine->id
|
||||
];
|
||||
|
||||
InfoItem::factory()->create([
|
||||
@@ -516,6 +561,7 @@ class StoreTest extends TestCase
|
||||
$city = City::factory()->create();
|
||||
$province = Province::factory()->create();
|
||||
$edarateShari = EdarateShahri::factory()->create();
|
||||
$cmmsMachine = CMMSMachine::factory()->create();
|
||||
|
||||
LogList::factory()->create([
|
||||
'log_unique_code' => 1154
|
||||
@@ -548,7 +594,8 @@ class StoreTest extends TestCase
|
||||
'activity_date' => $this->faker->date(),
|
||||
'activity_time' => $this->faker->date('H:i'),
|
||||
'before_image' => UploadedFile::fake()->create('image.jpg', 10),
|
||||
'after_image' => UploadedFile::fake()->create('image.jpg', 10)
|
||||
'after_image' => UploadedFile::fake()->create('image.jpg', 10),
|
||||
'cmms_machine_id' => $cmmsMachine->id
|
||||
];
|
||||
|
||||
$infoItem = InfoItem::factory()->create([
|
||||
@@ -577,6 +624,14 @@ class StoreTest extends TestCase
|
||||
'status' => 0,
|
||||
'status_fa' => 'در حال بررسی',
|
||||
'edarat_id' => $user->edarate_shahri_id,
|
||||
'cmms_machine_id' => $cmmsMachine->id,
|
||||
'cmms_machine_code' => $cmmsMachine->machine_code
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('user_activity_logs', [
|
||||
'user_id' => $user->id,
|
||||
'username' => $user->username,
|
||||
'log_unique_code' => 1154,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
158
tests/Feature/V3/RoadItemsProject/UpdateTest.php
Normal file
158
tests/Feature/V3/RoadItemsProject/UpdateTest.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?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'])
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user