| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- declare(strict_types=1);
- namespace Tests\Feature;
- use App\Models\CommonCatalogItem;
- use App\Models\ProductionOrder;
- use App\Models\ProductionOrderItem;
- use App\Models\Reclamation;
- use App\Models\ReclamationType;
- use App\Models\User;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- use Tests\TestCase;
- class ProductionOrderReclamationControllerTest extends TestCase
- {
- use RefreshDatabase;
- protected bool $seed = true;
- public function test_admin_can_create_other_reclamation_for_selected_order_items(): void
- {
- $admin = User::factory()->admin()->create();
- $manager = User::factory()->manager()->create();
- $order = ProductionOrder::factory()->create([
- 'customer_name' => 'Заказчик рекламации',
- 'object_address' => 'Адрес производственного заказа',
- 'manager_id' => $manager->id,
- ]);
- $catalogItem = CommonCatalogItem::factory()->create(['article' => 'РЕКЛ-МАФ-1']);
- $item = ProductionOrderItem::factory()->create([
- 'production_order_id' => $order->id,
- 'common_catalog_item_id' => $catalogItem->id,
- 'order_item_number' => 'ПОЗ-1',
- 'factory_number' => 'ЗАВ-1',
- 'manufacture_date' => '2026-08-30',
- ]);
- $response = $this->actingAs($admin)->post(
- route('schedule.orders.reclamations.store', $order),
- ['item_ids' => [$item->id]],
- );
- $reclamation = Reclamation::query()->where('production_order_id', $order->id)->firstOrFail();
- $response->assertRedirectContains('/reclamations/show/'.$reclamation->id.'?nav=');
- $this->assertNull($reclamation->order_id);
- $this->assertSame($manager->id, $reclamation->user_id);
- $this->assertSame(
- ReclamationType::CODE_OTHER,
- $reclamation->reclamationType()->value('code'),
- );
- $this->assertDatabaseHas('production_order_item_reclamation', [
- 'reclamation_id' => $reclamation->id,
- 'production_order_item_id' => $item->id,
- ]);
- $this->actingAs($admin)
- ->get(route('reclamations.show', $reclamation))
- ->assertOk()
- ->assertSee('Заказчик рекламации')
- ->assertSee('Адрес производственного заказа')
- ->assertSee('РЕКЛ-МАФ-1')
- ->assertSee('ПОЗ-1')
- ->assertSee('ЗАВ-1')
- ->assertDontSee('Пакет документов на оплату')
- ->assertDontSee('Пакет документов рекламации');
- }
- public function test_reclamation_items_must_belong_to_selected_production_order(): void
- {
- $admin = User::factory()->admin()->create();
- $manager = User::factory()->manager()->create();
- $order = ProductionOrder::factory()->create(['manager_id' => $manager->id]);
- $otherOrder = ProductionOrder::factory()->create(['manager_id' => $manager->id]);
- $otherItem = ProductionOrderItem::factory()->create([
- 'production_order_id' => $otherOrder->id,
- ]);
- $this->actingAs($admin)
- ->post(route('schedule.orders.reclamations.store', $order), [
- 'item_ids' => [$otherItem->id],
- ])
- ->assertSessionHasErrors('item_ids.0');
- $this->assertDatabaseMissing('reclamations', ['production_order_id' => $order->id]);
- }
- public function test_other_reclamation_is_visible_in_all_tab_and_excluded_from_dkr_tab(): void
- {
- $admin = User::factory()->admin()->create();
- $manager = User::factory()->manager()->create();
- $order = ProductionOrder::factory()->create([
- 'customer_name' => 'Заказчик только прочее',
- 'object_address' => 'Адрес только прочее',
- 'manager_id' => $manager->id,
- ]);
- $reclamation = Reclamation::query()->create([
- 'order_id' => null,
- 'production_order_id' => $order->id,
- 'reclamation_type_id' => ReclamationType::idForCode(ReclamationType::CODE_OTHER),
- 'user_id' => $manager->id,
- 'status_id' => Reclamation::STATUS_NEW,
- 'create_date' => now(),
- 'finish_date' => now()->addDays(30),
- ]);
- $this->actingAs($admin)
- ->get(route('reclamations.index'))
- ->assertOk()
- ->assertSee((string) $reclamation->id)
- ->assertSee('Адрес только прочее');
- $this->actingAs($admin)
- ->get(route('reclamations.index', ['tab' => ReclamationType::CODE_DKR]))
- ->assertOk()
- ->assertDontSee('Адрес только прочее');
- }
- }
|