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('Адрес только прочее'); } }