write tests for azmayesh resources
This commit is contained in:
82
tests/Feature/V3/AzmayeshSample/UpdateTest.php
Normal file
82
tests/Feature/V3/AzmayeshSample/UpdateTest.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\V3\AzmayeshSample;
|
||||
|
||||
use App\Models\Azmayesh;
|
||||
use App\Models\AzmayeshSample;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UpdateTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase, WithFaker;
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*/
|
||||
public function test_azmayesh_id_attribute_is_required(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$azmayeshSample = AzmayeshSample::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.update', [$azmayeshSample->id]));
|
||||
|
||||
$response->assertUnprocessable()
|
||||
->assertInvalid([
|
||||
'azmayesh_id' => __('validation.required', ['attribute' => 'آزمایش'])
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_azmayesh_id_attribute_should_exists_on_azmayeshes_table(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$azmayeshSample = AzmayeshSample::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.update', [$azmayeshSample->id]), [
|
||||
'azmayesh_id' => $this->faker->numberBetween(10, 100)
|
||||
]);
|
||||
|
||||
$response->assertUnprocessable()
|
||||
->assertInvalid([
|
||||
'azmayesh_id' => __('validation.exists', ['attribute' => 'آزمایش'])
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_data_attribute_is_required(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$azmayeshSample = AzmayeshSample::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.update', [$azmayeshSample->id]));
|
||||
|
||||
$response->assertUnprocessable()
|
||||
->assertInvalid([
|
||||
'data' => __('validation.required', ['attribute' => 'داده'])
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_user_can_update_the_azmayesh_sample(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$azmayesh = Azmayesh::factory()->create();
|
||||
$azmayeshSample = AzmayeshSample::factory()->create();
|
||||
|
||||
$data = [
|
||||
'azmayesh_id' => $azmayesh->id,
|
||||
'data' => json_encode([$this->faker->numerify]),
|
||||
];
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.update', [$azmayeshSample->id]), $data);
|
||||
|
||||
$response->assertOk()
|
||||
->assertExactJson([
|
||||
'message' => __('messages.successful')
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('azmayesh_samples', [
|
||||
'azmayesh_id' => $data['azmayesh_id'],
|
||||
'data' => $data['data'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user