create(); $response = $this->postJson(route('permissions.update', $permission)); $response->assertUnauthorized(); } public function test_name_and_name_fa_fields_are_required(): void { $user = User::factory()->create(); $permission = Permission::factory()->create(); $response = $this->actingAs($user)->postJson(route('permissions.update', $permission)); $response->assertUnprocessable() ->assertInvalid([ 'name' => __('validation.required', ['attribute' => 'نام']), 'name_fa' => __('validation.required', ['attribute' => 'نام فارسی']), ]); } public function test_name_and_name_fa_fields_must_be_strings(): void { $user = User::factory()->create(); $permission = Permission::factory()->create(); $response = $this->actingAs($user)->postJson(route('permissions.update', $permission), [ 'name' =>$this->faker->randomDigit(), 'name_fa' => $this->faker->randomDigit(), ]); $response->assertUnprocessable() ->assertInvalid([ 'name' => __('validation.string', ['attribute' => 'نام']), 'name_fa' => __('validation.string', ['attribute' => 'نام فارسی']), ]); } public function test_name_and_name_fa_fields_must_be_unique_except_current(): void { $user = User::factory()->create(); $permission1 = Permission::factory()->create(); $permission2 = Permission::factory()->create(); $response = $this->actingAs($user)->postJson(route('permissions.update', $permission1), [ 'name' => $permission2->name, 'name_fa' => $permission2->name_fa, ]); $response->assertUnprocessable() ->assertInvalid([ 'name' => __('validation.unique', ['attribute' => 'نام']), 'name_fa' => __('validation.unique', ['attribute' => 'نام فارسی']), ]); } public function test_name_and_name_fa_must_not_exceed_max_length(): void { $user = User::factory()->create(); $permission = Permission::factory()->create(); $longString = $this->faker->regexify('[a-zA-Z0-9]{256}'); $response = $this->actingAs($user)->postJson(route('permissions.update', $permission), [ 'name' => $longString, 'name_fa' => $longString, ]); $response->assertUnprocessable() ->assertInvalid([ 'name' => __('validation.max.string', ['attribute' => 'نام', 'max' => 255]), 'name_fa' => __('validation.max.string', ['attribute' => 'نام فارسی', 'max' => 255]), ]); } public function test_valid_permission_is_updated_successfully(): void { $user = User::factory()->create(); $permission = Permission::factory()->create(); $payload = [ 'name' => $this->faker->unique()->slug, 'name_fa' => $this->faker->unique()->words(2, true), ]; $response = $this->actingAs($user)->postJson(route('permissions.update', $permission), $payload); $response->assertOk() ->assertJson([ 'message' => __('messages.successful'), ]); $this->assertDatabaseHas('permissions', [ 'id' => $permission->id, 'name' => $payload['name'], 'name_fa' => $payload['name_fa'], ]); } }