diff --git a/app/Http/Controllers/V3/Azmayesh/AzmayeshSampleController.php b/app/Http/Controllers/V3/Azmayesh/AzmayeshSampleController.php index a6861062..c5f98372 100644 --- a/app/Http/Controllers/V3/Azmayesh/AzmayeshSampleController.php +++ b/app/Http/Controllers/V3/Azmayesh/AzmayeshSampleController.php @@ -69,6 +69,8 @@ class AzmayeshSampleController extends Controller */ public function update(UpdateRequest $request, AzmayeshSample $azmayeshSample) { + $azmayesh = Azmayesh::query()->findOrFail($request->azmayesh_id); + $azmayeshSample->update([ 'azmayesh_id' => $azmayesh->id, 'azmayesh_project_name' => $azmayesh->project_name, diff --git a/database/factories/AzmayeshFactory.php b/database/factories/AzmayeshFactory.php index 78c19dae..e8aa9d2e 100644 --- a/database/factories/AzmayeshFactory.php +++ b/database/factories/AzmayeshFactory.php @@ -19,14 +19,25 @@ class AzmayeshFactory extends Factory public function definition(): array { return [ + 'lat' => $this->faker->numerify, + 'lng' => $this->faker->numerify, 'azmayesh_type_id' => AzmayeshType::factory(), 'azmayesh_type_name' => function (array $attributes) { return AzmayeshType::query()->find($attributes['azmayesh_type_id'])->name; }, 'province_id' => Province::factory(), 'province_name' => function (array $attributes) { - return Province::query()->find($attributes['province_id'])->name; + return Province::query()->find($attributes['province_id'])->name_fa; }, + 'request_date' => $this->faker->date, + 'report_date' => $this->faker->date, + 'request_number' => $this->faker->numerify, + 'employer' => $this->faker->name, + 'contractor' => $this->faker->name, + 'work_number' => $this->faker->numerify, + 'project_name' => $this->faker->name, + 'consultant' => $this->faker->name, + 'applicant' => $this->faker->name, ]; } } diff --git a/database/factories/AzmayeshSampleFactory.php b/database/factories/AzmayeshSampleFactory.php index f4b518a4..c288abf4 100644 --- a/database/factories/AzmayeshSampleFactory.php +++ b/database/factories/AzmayeshSampleFactory.php @@ -19,8 +19,8 @@ class AzmayeshSampleFactory extends Factory { return [ 'azmayesh_id' => Azmayesh::factory(), - 'azmayesh_name' => function (array $attributes) { - return Azmayesh::query()->find($attributes['azmayesh_id'])->name; + 'azmayesh_project_name' => function (array $attributes) { + return Azmayesh::query()->find($attributes['azmayesh_id'])->project_name; }, 'data' => json_encode(['test']), ]; diff --git a/resources/lang/fa/validation.php b/resources/lang/fa/validation.php index 8fc265b8..377a776d 100644 --- a/resources/lang/fa/validation.php +++ b/resources/lang/fa/validation.php @@ -179,6 +179,21 @@ return [ 'new_password' => 'رمز عبور جدید', 'degree' => 'مدرک تحصیلی', 'major' => 'شغل', - 'avatar' => 'آواتار' + 'avatar' => 'آواتار', + 'lat' => 'طول جغرافیایی', + 'lng' => 'عرض جغرافیایی', + 'azmayesh_type_id' => 'نوع آزمایش', + 'request_date' => 'تاریخ درخواست', + 'report_date' => 'تاریخ گزارش', + 'request_number' => 'شماره درخواست', + 'employer' => 'کارفرما', + 'contractor' => 'پیمانکار', + 'work_number' => 'شماره کار', + 'project_name' => 'نام پروژه', + 'consultant' => 'مشاور', + 'applicant' => 'متقاضی', + 'province_id' => 'استان', + 'azmayesh_id' => 'آزمایش', + 'data' => 'داده' ], ]; diff --git a/tests/Feature/V3/Azmayesh/DeleteTest.php b/tests/Feature/V3/Azmayesh/DeleteTest.php new file mode 100644 index 00000000..cafa4f74 --- /dev/null +++ b/tests/Feature/V3/Azmayesh/DeleteTest.php @@ -0,0 +1,44 @@ +create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.delete', [$azmayesh->id])); + + $response->assertOk(); + + $this->assertDatabaseMissing('azmayeshes', [ + 'lat' => $azmayesh->lat, + 'lng' => $azmayesh->lng, + 'azmayesh_type_id' => $azmayesh->azmayesh_type_id, + 'azmayesh_type_name' => $azmayesh->azmayesh_type_name, + 'request_date' => $azmayesh->request_date, + 'report_date' => $azmayesh->report_date, + 'request_number' => $azmayesh->request_number, + 'employer' => $azmayesh->employer, + 'contractor' => $azmayesh->contractor, + 'work_number' => $azmayesh->work_number, + 'project_name' => $azmayesh->project_name, + 'consultant' => $azmayesh->consultant, + 'applicant' => $azmayesh->applicant, + 'province_id' => $azmayesh->province_id, + 'province_name' => $azmayesh->province_name, + ]); + } +} diff --git a/tests/Feature/V3/Azmayesh/IndexTest.php b/tests/Feature/V3/Azmayesh/IndexTest.php new file mode 100644 index 00000000..eae71b0c --- /dev/null +++ b/tests/Feature/V3/Azmayesh/IndexTest.php @@ -0,0 +1,55 @@ +create(); + + Azmayesh::factory(5)->create(); + + $response = $this->actingAs($user)->getJson(route('v3.azmayeshes.index', [ + 'start' => 0, + 'size' => 10, + 'filters' => json_encode([]), + 'sorting' => json_encode([]), + ])); + + $response->assertOk(); + + $response->assertJsonStructure([ + 'data' => [ + '*' => [ + 'id', + 'lat', + 'lng', + 'request_date', + 'report_date', + 'request_number', + 'employer', + 'contractor', + 'work_number', + 'consultant', + 'applicant', + 'project_name', + 'province_id', + ], + ], + "meta" => [ + "totalRowCount" + ] + ]); + } +} diff --git a/tests/Feature/V3/Azmayesh/StoreTest.php b/tests/Feature/V3/Azmayesh/StoreTest.php new file mode 100644 index 00000000..6ee556cf --- /dev/null +++ b/tests/Feature/V3/Azmayesh/StoreTest.php @@ -0,0 +1,305 @@ +create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'lat' => __('validation.required', ['attribute' => 'طول جغرافیایی']) + ]); + } + + public function test_lat_attribute_should_be_string(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'lat' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'lat' => __('validation.string', ['attribute' => 'طول جغرافیایی']) + ]); + } + + public function test_lng_attribute_is_required(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'lng' => __('validation.required', ['attribute' => 'عرض جغرافیایی']) + ]); + } + + public function test_lng_attribute_should_be_string(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'lng' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'lng' => __('validation.string', ['attribute' => 'عرض جغرافیایی']) + ]); + } + + public function test_azmayesh_type_id_attribute_is_required(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'azmayesh_type_id' => __('validation.required', ['attribute' => 'نوع آزمایش']) + ]); + } + + public function test_azmayesh_type_id_attribute_should_exist_on_azmayesh_types_table(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'azmayesh_type_id' => $this->faker->numberBetween(10, 100) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'azmayesh_type_id' => __('validation.exists', ['attribute' => 'نوع آزمایش']) + ]); + } + + public function test_request_date_attribute_should_be_date_type(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'request_date' => $this->faker->lexify + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'request_date' => __('validation.date', ['attribute' => 'تاریخ درخواست']) + ]); + } + + public function test_report_date_attribute_should_be_date_type(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'report_date' => $this->faker->lexify + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'report_date' => __('validation.date', ['attribute' => 'تاریخ گزارش']) + ]); + } + + public function test_request_number_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'request_number' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'request_number' => __('validation.string', ['attribute' => 'شماره درخواست']) + ]); + } + + public function test_employer_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'employer' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'employer' => __('validation.string', ['attribute' => 'کارفرما']) + ]); + } + + public function test_contractor_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'contractor' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'contractor' => __('validation.string', ['attribute' => 'پیمانکار']) + ]); + } + + public function test_work_number_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'work_number' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'work_number' => __('validation.string', ['attribute' => 'شماره کار']) + ]); + } + + public function test_project_name_attribute_is_required(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'project_name' => __('validation.required', ['attribute' => 'نام پروژه']) + ]); + } + + public function test_project_name_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'project_name' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'project_name' => __('validation.string', ['attribute' => 'نام پروژه']) + ]); + } + + public function test_consultant_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'consultant' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'consultant' => __('validation.string', ['attribute' => 'مشاور']) + ]); + } + + public function test_applicant_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'applicant' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'applicant' => __('validation.string', ['attribute' => 'متقاضی']) + ]); + } + + public function test_province_id_attribute_is_required(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'province_id' => __('validation.required', ['attribute' => 'استان']) + ]); + } + + public function test_province_id_attribute_should_exists_on_province_table(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'province_id' => $this->faker->numberBetween(10, 100) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'province_id' => __('validation.exists', ['attribute' => 'استان']) + ]); + } + + public function test_user_can_store_a_new_azmayesh(): void + { + $user = User::factory()->create(); + $province = Province::factory()->create(); + $azmayeshType = AzmayeshType::factory()->create(); + + $data = [ + 'lat' => $this->faker->numerify, + 'lng' => $this->faker->numerify, + 'azmayesh_type_id' => $azmayeshType->id, + 'request_date' => $this->faker->date, + 'report_date' => $this->faker->date, + 'request_number' => $this->faker->numerify, + 'employer' => $this->faker->name, + 'contractor' => $this->faker->name, + 'work_number' => $this->faker->numerify, + 'project_name' => $this->faker->name, + 'consultant' => $this->faker->name, + 'applicant' => $this->faker->name, + 'province_id' => $province->id, + ]; + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), $data); + + $response->assertOk() + ->assertExactJson([ + 'message' => __('messages.successful') + ]); + + $this->assertDatabaseHas('azmayeshes', [ + 'lat' => $data['lat'], + 'lng' => $data['lng'], + 'azmayesh_type_id' => $data['azmayesh_type_id'], + 'request_date' => $data['request_date'], + 'report_date' => $data['report_date'], + 'request_number' => $data['request_number'], + 'employer' => $data['employer'], + 'contractor' => $data['contractor'], + 'work_number' => $data['work_number'], + 'project_name' => $data['project_name'], + 'consultant' => $data['consultant'], + 'applicant' => $data['applicant'], + 'province_id' => $data['province_id'], + ]); + } +} diff --git a/tests/Feature/V3/Azmayesh/UpdateTest.php b/tests/Feature/V3/Azmayesh/UpdateTest.php new file mode 100644 index 00000000..b20a0d8e --- /dev/null +++ b/tests/Feature/V3/Azmayesh/UpdateTest.php @@ -0,0 +1,309 @@ +create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id])); + + $response->assertUnprocessable() + ->assertInvalid([ + 'lat' => __('validation.required', ['attribute' => 'طول جغرافیایی']) + ]); + } + + public function test_lat_attribute_should_be_string(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'lat' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'lat' => __('validation.string', ['attribute' => 'طول جغرافیایی']) + ]); + } + + public function test_lng_attribute_is_required(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id])); + + $response->assertUnprocessable() + ->assertInvalid([ + 'lng' => __('validation.required', ['attribute' => 'عرض جغرافیایی']) + ]); + } + + public function test_lng_attribute_should_be_string(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'lng' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'lng' => __('validation.string', ['attribute' => 'عرض جغرافیایی']) + ]); + } + + public function test_azmayesh_type_id_attribute_is_required(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id])); + + $response->assertUnprocessable() + ->assertInvalid([ + 'azmayesh_type_id' => __('validation.required', ['attribute' => 'نوع آزمایش']) + ]); + } + + public function test_azmayesh_type_id_attribute_should_exist_on_azmayesh_types_table(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'azmayesh_type_id' => $this->faker->numberBetween(10, 100) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'azmayesh_type_id' => __('validation.exists', ['attribute' => 'نوع آزمایش']) + ]); + } + + public function test_request_date_attribute_should_be_date_type(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'request_date' => $this->faker->lexify + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'request_date' => __('validation.date', ['attribute' => 'تاریخ درخواست']) + ]); + } + + public function test_report_date_attribute_should_be_date_type(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'report_date' => $this->faker->lexify + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'report_date' => __('validation.date', ['attribute' => 'تاریخ گزارش']) + ]); + } + + public function test_request_number_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'request_number' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'request_number' => __('validation.string', ['attribute' => 'شماره درخواست']) + ]); + } + + public function test_employer_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'employer' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'employer' => __('validation.string', ['attribute' => 'کارفرما']) + ]); + } + + public function test_contractor_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'contractor' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'contractor' => __('validation.string', ['attribute' => 'پیمانکار']) + ]); + } + + public function test_work_number_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'work_number' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'work_number' => __('validation.string', ['attribute' => 'شماره کار']) + ]); + } + + public function test_project_name_attribute_is_required(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id])); + + $response->assertUnprocessable() + ->assertInvalid([ + 'project_name' => __('validation.required', ['attribute' => 'نام پروژه']) + ]); + } + + public function test_project_name_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'project_name' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'project_name' => __('validation.string', ['attribute' => 'نام پروژه']) + ]); + } + + public function test_consultant_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'consultant' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'consultant' => __('validation.string', ['attribute' => 'مشاور']) + ]); + } + + public function test_applicant_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'applicant' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'applicant' => __('validation.string', ['attribute' => 'متقاضی']) + ]); + } + + public function test_province_id_attribute_is_required(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id])); + + $response->assertUnprocessable() + ->assertInvalid([ + 'province_id' => __('validation.required', ['attribute' => 'استان']) + ]); + } + + public function test_province_id_attribute_should_exists_on_province_table(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'province_id' => $this->faker->numberBetween(10, 100) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'province_id' => __('validation.exists', ['attribute' => 'استان']) + ]); + } + + public function test_user_can_update_the_azmayesh(): void + { + $user = User::factory()->create(); + $province = Province::factory()->create(); + $azmayeshType = AzmayeshType::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $data = [ + 'lat' => $this->faker->numerify, + 'lng' => $this->faker->numerify, + 'azmayesh_type_id' => $azmayeshType->id, + 'request_date' => $this->faker->date, + 'report_date' => $this->faker->date, + 'request_number' => $this->faker->numerify, + 'employer' => $this->faker->name, + 'contractor' => $this->faker->name, + 'work_number' => $this->faker->numerify, + 'project_name' => $this->faker->name, + 'consultant' => $this->faker->name, + 'applicant' => $this->faker->name, + 'province_id' => $province->id, + ]; + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), $data); + + $response->assertOk() + ->assertExactJson([ + 'message' => __('messages.successful') + ]); + } +} diff --git a/tests/Feature/V3/AzmayeshSample/DeleteTest.php b/tests/Feature/V3/AzmayeshSample/DeleteTest.php new file mode 100644 index 00000000..ac901f6e --- /dev/null +++ b/tests/Feature/V3/AzmayeshSample/DeleteTest.php @@ -0,0 +1,32 @@ +create(); + $azmayeshSample = AzmayeshSample::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.delete', [$azmayeshSample->id])); + + $response->assertOk(); + + $this->assertDatabaseMissing('azmayesh_samples', [ + 'azmayesh_id' => $azmayeshSample->azmayesh_id, + 'data' => $azmayeshSample->data, + ]); + } +} diff --git a/tests/Feature/V3/AzmayeshSample/IndexTest.php b/tests/Feature/V3/AzmayeshSample/IndexTest.php new file mode 100644 index 00000000..4a447d99 --- /dev/null +++ b/tests/Feature/V3/AzmayeshSample/IndexTest.php @@ -0,0 +1,86 @@ +create(); + + Azmayesh::factory(5) + ->sequence( + ['id' => 1], + ['id' => 2], + ['id' => 3], + ['id' => 4], + ['id' => 5] + ) + ->create(); + + AzmayeshSample::factory(5) + ->sequence( + [ + 'azmayesh_id' => 1, + 'azmayesh_project_name' => $this->faker->name, + 'data' => json_encode([$this->faker->numerify]), + ], + [ + 'azmayesh_id' => 2, + 'azmayesh_project_name' => $this->faker->name, + 'data' => json_encode([$this->faker->numerify]), + ], + [ + 'azmayesh_id' => 3, + 'azmayesh_project_name' => $this->faker->name, + 'data' => json_encode([$this->faker->numerify]), + ], + [ + 'azmayesh_id' => 4, + 'azmayesh_project_name' => $this->faker->name, + 'data' => json_encode([$this->faker->numerify]), + ], + [ + 'azmayesh_id' => 1, + 'azmayesh_project_name' => $this->faker->name, + 'data' => json_encode([$this->faker->numerify]), + ], + ) + ->create(); + + $response = $this->actingAs($user)->getJson(route('v3.azmayesh_samples.index', [ + 1, + 'start' => 0, + 'size' => 10, + 'filters' => json_encode([]), + 'sorting' => json_encode([]), + ])); + + $response->assertOk(); + + $response->assertJsonStructure([ + 'data' => [ + '*' => [ + 'id', + 'azmayesh_id', + 'azmayesh_project_name', + 'data', + ], + ], + "meta" => [ + "totalRowCount" + ] + ]); + } +} diff --git a/tests/Feature/V3/AzmayeshSample/StoreTest.php b/tests/Feature/V3/AzmayeshSample/StoreTest.php new file mode 100644 index 00000000..28a6e1e0 --- /dev/null +++ b/tests/Feature/V3/AzmayeshSample/StoreTest.php @@ -0,0 +1,79 @@ +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'], + ]); + } +} diff --git a/tests/Feature/V3/AzmayeshSample/UpdateTest.php b/tests/Feature/V3/AzmayeshSample/UpdateTest.php new file mode 100644 index 00000000..c79fef01 --- /dev/null +++ b/tests/Feature/V3/AzmayeshSample/UpdateTest.php @@ -0,0 +1,82 @@ +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'], + ]); + } +} diff --git a/tests/Feature/V3/AzmayeshType/FieldsTest.php b/tests/Feature/V3/AzmayeshType/FieldsTest.php new file mode 100644 index 00000000..b35cfc31 --- /dev/null +++ b/tests/Feature/V3/AzmayeshType/FieldsTest.php @@ -0,0 +1,65 @@ +sequence( + [ + 'id' => 1, + 'name' => $this->faker->name, + 'unit' => $this->faker->name, + 'type' => $this->faker->name, + ], + [ + 'id' => 2, + 'name' => $this->faker->name, + 'unit' => $this->faker->name, + 'type' => $this->faker->name, + ], + [ + 'id' => 3, + 'name' => $this->faker->name, + 'unit' => $this->faker->name, + 'type' => $this->faker->name, + ], + ) + ->create(); + + $azmayeshType = AzmayeshType::factory()->create(); + + $azmayeshType->azmayeshFields()->attach(1); + + $user = User::factory()->create(); + + $response = $this->actingAs($user)->getJson(route('v3.azmayesh_types.fields', [$azmayeshType->id])); + + $response->assertOk(); + + $response->assertJsonStructure([ + 'data' => [ + '*' => [ + 'name', + 'name', + 'unit', + 'type', + 'option' + ], + ] + ]); + } +} diff --git a/tests/Feature/V3/AzmayeshType/IndexTest.php b/tests/Feature/V3/AzmayeshType/IndexTest.php new file mode 100644 index 00000000..e96695f2 --- /dev/null +++ b/tests/Feature/V3/AzmayeshType/IndexTest.php @@ -0,0 +1,35 @@ +create(); + + $user = User::factory()->create(); + + $response = $this->actingAs($user)->getJson(route('v3.azmayesh_types.index')); + + $response->assertOk(); + + $response->assertJsonStructure([ + 'data' => [ + '*' => [ + 'name', + ], + ] + ]); + } +}