improve 4 test
This commit is contained in:
@@ -5,7 +5,6 @@ namespace Tests\Feature\Call;
|
||||
use App\Enums\CallEvents;
|
||||
use App\Models\Call;
|
||||
use App\Models\Category;
|
||||
use App\Models\Event;
|
||||
use App\Models\Permission;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
@@ -16,6 +15,55 @@ class UpdateTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase, WithFaker;
|
||||
|
||||
public function test_operator_is_not_authenticated(): void
|
||||
{
|
||||
$response = $this->postJson(route('calls.update', ['call' => 1]));
|
||||
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
|
||||
public function test_operator_without_unappropriated_permission_is_forbidden_to_access_calls_data(): void
|
||||
{
|
||||
$telephoneId = 'tel-' . $this->faker->unique()->numerify('###');
|
||||
|
||||
$user = User::factory()
|
||||
->create([
|
||||
'telephone_id' => $telephoneId,
|
||||
]);
|
||||
|
||||
$call = Call::factory()->create([
|
||||
'telephone_id' => $telephoneId,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('calls.update', ['call' => $call->id]));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_operator_can_not_access_to_other_operators_calls(): void
|
||||
{
|
||||
|
||||
$telephoneId = 'tel-' . $this->faker->unique()->numerify('###');
|
||||
|
||||
$user = User::factory()
|
||||
->create([
|
||||
'telephone_id' => $telephoneId,
|
||||
]);
|
||||
|
||||
$another_operator = User::factory([
|
||||
'id' => $this->faker->randomNumber(2, true)
|
||||
])->create();
|
||||
|
||||
$call = Call::factory([
|
||||
'telephone_id' => $another_operator->telephone_id
|
||||
])->create();
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('calls.update', ['call' => $call->id]));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
|
||||
public function test_non_owner_user_cannot_update_call(): void
|
||||
{
|
||||
$callOwner = User::factory()->create([
|
||||
@@ -26,14 +74,12 @@ class UpdateTest extends TestCase
|
||||
'telephone_id' => $callOwner->telephone_id,
|
||||
]);
|
||||
|
||||
$unauthorizedUser = User::factory()->create(); // no permission
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($unauthorizedUser);
|
||||
|
||||
$response = $this->postJson(route('calls.update', $call->id), [
|
||||
'category_id' => 1,
|
||||
'subcategory_id' => 2,
|
||||
'description' => '...',
|
||||
$response = $this->actingAs($user)->postJson(route('calls.update', $call->id), [
|
||||
'category_id' => $this->faker->randomNumber(),
|
||||
'subcategory_id' => $this->faker->randomNumber(),
|
||||
'description' => $this->faker->sentence
|
||||
]);
|
||||
|
||||
$response->assertForbidden();
|
||||
@@ -56,9 +102,7 @@ class UpdateTest extends TestCase
|
||||
'telephone_id' => $telephoneId,
|
||||
]);
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = $this->postJson(route('calls.update', $call->id), []);
|
||||
$response = $this->actingAs($user)->postJson(route('calls.update', $call->id), []);
|
||||
|
||||
$response->assertUnprocessable()
|
||||
->assertInvalid([
|
||||
@@ -81,15 +125,13 @@ class UpdateTest extends TestCase
|
||||
]);
|
||||
|
||||
$call = Call::factory()->create([
|
||||
'telephone_id' => $telephoneId,
|
||||
'telephone_id' =>$user->telephone_id,
|
||||
]);
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = $this->postJson(route('calls.update', $call->id), [
|
||||
'category_id' => 'not-an-int',
|
||||
'subcategory_id' => 'also-string',
|
||||
'description' => 'توضیح',
|
||||
$response = $this->actingAs($user)->postJson(route('calls.update', $call->id), [
|
||||
'category_id' =>$this->faker->sentence(3),
|
||||
'subcategory_id' => $this->faker->sentence(3),
|
||||
'description' => $this->faker->sentence,
|
||||
]);
|
||||
|
||||
$response->assertUnprocessable()
|
||||
@@ -116,12 +158,12 @@ class UpdateTest extends TestCase
|
||||
'telephone_id' => $telephoneId,
|
||||
]);
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = $this->postJson(route('calls.update', $call->id), [
|
||||
'category_id' => 1,
|
||||
'subcategory_id' => 2,
|
||||
'description' => ['not', 'a', 'string'],
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('calls.update', $call->id), [
|
||||
'category_id' => $this->faker->randomNumber(),
|
||||
'subcategory_id' => $this->faker->randomNumber(),
|
||||
'description' => $this->faker->randomNumber(),
|
||||
]);
|
||||
|
||||
$response->assertUnprocessable()
|
||||
@@ -147,12 +189,12 @@ class UpdateTest extends TestCase
|
||||
'telephone_id' => $telephoneId,
|
||||
]);
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = $this->postJson(route('calls.update', $call->id), [
|
||||
'category_id' => 12345,
|
||||
'subcategory_id' => 67890,
|
||||
'description' => '...',
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('calls.update', $call->id), [
|
||||
'category_id' => $this->faker->randomNumber(),
|
||||
'subcategory_id' => $this->faker->randomNumber(),
|
||||
'description' => $this->faker->sentence,
|
||||
]);
|
||||
|
||||
$response->assertUnprocessable()
|
||||
@@ -179,14 +221,12 @@ class UpdateTest extends TestCase
|
||||
]);
|
||||
|
||||
$category = Category::factory()->create();
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = $this->postJson(route('calls.update', $call->id), [
|
||||
$description = $this->faker->sentence;
|
||||
$response = $this->actingAs($user)->postJson(route('calls.update', $call->id), [
|
||||
'category_id' => $category->category_id,
|
||||
'subcategory_id' => $category->subcategory_id,
|
||||
'description' => 'توضیحات تستی',
|
||||
]);
|
||||
'description' => $description,
|
||||
]);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
@@ -197,8 +237,8 @@ class UpdateTest extends TestCase
|
||||
'id' => $call->id,
|
||||
'category_id' => $category->category_id,
|
||||
'subcategory_id' => $category->subcategory_id,
|
||||
'description' => 'توضیحات تستی',
|
||||
]);
|
||||
'description' => $description,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('call_histories', [
|
||||
'call_id' => $call->id,
|
||||
|
||||
Reference in New Issue
Block a user