create(); $response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.store')); $response->assertUnprocessable() ->assertInvalid([ 'azmayesh_id' => __('validation.required', ['attribute' => 'آزمایش']) ]); } public function test_azmayesh_id_attribute_should_exists_on_azmayeshes_table(): void { $user = User::factory()->create(); $response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.store'), [ '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(); $response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.store')); $response->assertUnprocessable() ->assertInvalid([ 'data' => __('validation.required', ['attribute' => 'داده']) ]); } public function test_user_can_store_a_new_azmayesh_sample(): void { $user = User::factory()->create(); $azmayesh = Azmayesh::factory()->create(); $data = [ 'azmayesh_id' => $azmayesh->id, 'data' => json_encode([$this->faker->numerify]), ]; $response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.store'), $data); $response->assertOk() ->assertExactJson([ 'message' => __('messages.successful') ]); $this->assertDatabaseHas('azmayesh_samples', [ 'azmayesh_id' => $data['azmayesh_id'], 'data' => $data['data'], ]); } }