ProductionOrderReclamationControllerTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. declare(strict_types=1);
  3. namespace Tests\Feature;
  4. use App\Models\CommonCatalogItem;
  5. use App\Models\ProductionOrder;
  6. use App\Models\ProductionOrderItem;
  7. use App\Models\Reclamation;
  8. use App\Models\ReclamationType;
  9. use App\Models\User;
  10. use Illuminate\Foundation\Testing\RefreshDatabase;
  11. use Tests\TestCase;
  12. class ProductionOrderReclamationControllerTest extends TestCase
  13. {
  14. use RefreshDatabase;
  15. protected bool $seed = true;
  16. public function test_admin_can_create_other_reclamation_for_selected_order_items(): void
  17. {
  18. $admin = User::factory()->admin()->create();
  19. $manager = User::factory()->manager()->create();
  20. $order = ProductionOrder::factory()->create([
  21. 'customer_name' => 'Заказчик рекламации',
  22. 'object_address' => 'Адрес производственного заказа',
  23. 'manager_id' => $manager->id,
  24. ]);
  25. $catalogItem = CommonCatalogItem::factory()->create(['article' => 'РЕКЛ-МАФ-1']);
  26. $item = ProductionOrderItem::factory()->create([
  27. 'production_order_id' => $order->id,
  28. 'common_catalog_item_id' => $catalogItem->id,
  29. 'order_item_number' => 'ПОЗ-1',
  30. 'factory_number' => 'ЗАВ-1',
  31. 'manufacture_date' => '2026-08-30',
  32. ]);
  33. $response = $this->actingAs($admin)->post(
  34. route('schedule.orders.reclamations.store', $order),
  35. ['item_ids' => [$item->id]],
  36. );
  37. $reclamation = Reclamation::query()->where('production_order_id', $order->id)->firstOrFail();
  38. $response->assertRedirectContains('/reclamations/show/'.$reclamation->id.'?nav=');
  39. $this->assertNull($reclamation->order_id);
  40. $this->assertSame($manager->id, $reclamation->user_id);
  41. $this->assertSame(
  42. ReclamationType::CODE_OTHER,
  43. $reclamation->reclamationType()->value('code'),
  44. );
  45. $this->assertDatabaseHas('production_order_item_reclamation', [
  46. 'reclamation_id' => $reclamation->id,
  47. 'production_order_item_id' => $item->id,
  48. ]);
  49. $this->actingAs($admin)
  50. ->get(route('reclamations.show', $reclamation))
  51. ->assertOk()
  52. ->assertSee('Заказчик рекламации')
  53. ->assertSee('Адрес производственного заказа')
  54. ->assertSee('РЕКЛ-МАФ-1')
  55. ->assertSee('ПОЗ-1')
  56. ->assertSee('ЗАВ-1')
  57. ->assertDontSee('Пакет документов на оплату')
  58. ->assertDontSee('Пакет документов рекламации');
  59. }
  60. public function test_reclamation_items_must_belong_to_selected_production_order(): void
  61. {
  62. $admin = User::factory()->admin()->create();
  63. $manager = User::factory()->manager()->create();
  64. $order = ProductionOrder::factory()->create(['manager_id' => $manager->id]);
  65. $otherOrder = ProductionOrder::factory()->create(['manager_id' => $manager->id]);
  66. $otherItem = ProductionOrderItem::factory()->create([
  67. 'production_order_id' => $otherOrder->id,
  68. ]);
  69. $this->actingAs($admin)
  70. ->post(route('schedule.orders.reclamations.store', $order), [
  71. 'item_ids' => [$otherItem->id],
  72. ])
  73. ->assertSessionHasErrors('item_ids.0');
  74. $this->assertDatabaseMissing('reclamations', ['production_order_id' => $order->id]);
  75. }
  76. public function test_other_reclamation_is_visible_in_all_tab_and_excluded_from_dkr_tab(): void
  77. {
  78. $admin = User::factory()->admin()->create();
  79. $manager = User::factory()->manager()->create();
  80. $order = ProductionOrder::factory()->create([
  81. 'customer_name' => 'Заказчик только прочее',
  82. 'object_address' => 'Адрес только прочее',
  83. 'manager_id' => $manager->id,
  84. ]);
  85. $reclamation = Reclamation::query()->create([
  86. 'order_id' => null,
  87. 'production_order_id' => $order->id,
  88. 'reclamation_type_id' => ReclamationType::idForCode(ReclamationType::CODE_OTHER),
  89. 'user_id' => $manager->id,
  90. 'status_id' => Reclamation::STATUS_NEW,
  91. 'create_date' => now(),
  92. 'finish_date' => now()->addDays(30),
  93. ]);
  94. $this->actingAs($admin)
  95. ->get(route('reclamations.index'))
  96. ->assertOk()
  97. ->assertSee((string) $reclamation->id)
  98. ->assertSee('Адрес только прочее');
  99. $this->actingAs($admin)
  100. ->get(route('reclamations.index', ['tab' => ReclamationType::CODE_DKR]))
  101. ->assertOk()
  102. ->assertDontSee('Адрес только прочее');
  103. }
  104. }