|
|
@@ -4,7 +4,10 @@ namespace Tests\Feature;
|
|
|
|
|
|
use App\Models\Dictionary\Area;
|
|
|
use App\Models\Dictionary\District;
|
|
|
+use App\Models\MafOrder;
|
|
|
use App\Models\Order;
|
|
|
+use App\Models\Product;
|
|
|
+use App\Models\ProductSKU;
|
|
|
use App\Models\Reclamation;
|
|
|
use App\Models\Role;
|
|
|
use App\Models\Schedule;
|
|
|
@@ -281,6 +284,106 @@ class ScheduleControllerTest extends TestCase
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+ public function test_cannot_create_schedule_from_order_when_order_has_unlinked_maf(): void
|
|
|
+ {
|
|
|
+ $product = Product::factory()->create();
|
|
|
+ $order = Order::factory()->readyToMount()->withBrigadier($this->brigadierUser)->create([
|
|
|
+ 'installation_date' => '2026-04-22',
|
|
|
+ 'install_days' => 2,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ ProductSKU::factory()->create([
|
|
|
+ 'order_id' => $order->id,
|
|
|
+ 'product_id' => $product->id,
|
|
|
+ 'maf_order_id' => null,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $response = $this->actingAs($this->adminUser)
|
|
|
+ ->post(route('schedule.create-from-order'), [
|
|
|
+ 'order_id' => $order->id,
|
|
|
+ 'delete_old_records' => '1',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $response->assertRedirect(route('order.show', $order->id));
|
|
|
+ $response->assertSessionHas('danger', function ($messages) {
|
|
|
+ return in_array('МАФ не привязан к заказу', (array) $messages, true);
|
|
|
+ });
|
|
|
+ $this->assertDatabaseCount('schedules', 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function test_cannot_create_schedule_from_order_when_maf_order_number_is_empty(): void
|
|
|
+ {
|
|
|
+ $product = Product::factory()->create();
|
|
|
+ $order = Order::factory()->readyToMount()->withBrigadier($this->brigadierUser)->create([
|
|
|
+ 'installation_date' => '2026-04-22',
|
|
|
+ 'install_days' => 2,
|
|
|
+ ]);
|
|
|
+ $mafOrder = MafOrder::factory()->create([
|
|
|
+ 'product_id' => $product->id,
|
|
|
+ 'order_number' => '',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ ProductSKU::factory()->create([
|
|
|
+ 'order_id' => $order->id,
|
|
|
+ 'product_id' => $product->id,
|
|
|
+ 'maf_order_id' => $mafOrder->id,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ Schedule::factory()->create([
|
|
|
+ 'order_id' => $order->id,
|
|
|
+ 'source' => 'Площадки',
|
|
|
+ 'manual' => false,
|
|
|
+ 'brigadier_id' => $this->brigadierUser->id,
|
|
|
+ 'object_address' => $order->object_address,
|
|
|
+ 'installation_date' => '2026-04-20',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $response = $this->actingAs($this->adminUser)
|
|
|
+ ->post(route('schedule.create-from-order'), [
|
|
|
+ 'order_id' => $order->id,
|
|
|
+ 'delete_old_records' => '1',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $response->assertRedirect(route('order.show', $order->id));
|
|
|
+ $response->assertSessionHas('danger', function ($messages) {
|
|
|
+ return in_array('МАФ не привязан к заказу', (array) $messages, true);
|
|
|
+ });
|
|
|
+ $this->assertDatabaseCount('schedules', 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function test_can_create_schedule_from_order_when_all_mafs_are_linked_to_order_numbers(): void
|
|
|
+ {
|
|
|
+ $product = Product::factory()->create();
|
|
|
+ $order = Order::factory()->readyToMount()->withBrigadier($this->brigadierUser)->create([
|
|
|
+ 'installation_date' => '2026-04-22',
|
|
|
+ 'install_days' => 2,
|
|
|
+ ]);
|
|
|
+ $mafOrder = MafOrder::factory()->create([
|
|
|
+ 'product_id' => $product->id,
|
|
|
+ 'order_number' => 'MO-2026-1',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ ProductSKU::factory()->create([
|
|
|
+ 'order_id' => $order->id,
|
|
|
+ 'product_id' => $product->id,
|
|
|
+ 'maf_order_id' => $mafOrder->id,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $response = $this->actingAs($this->adminUser)
|
|
|
+ ->post(route('schedule.create-from-order'), [
|
|
|
+ 'order_id' => $order->id,
|
|
|
+ 'comment' => '',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $response->assertRedirect(route('schedule.index'));
|
|
|
+ $this->assertDatabaseCount('schedules', 2);
|
|
|
+ $this->assertDatabaseHas('schedules', [
|
|
|
+ 'order_id' => $order->id,
|
|
|
+ 'source' => 'Площадки',
|
|
|
+ 'manual' => false,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
// ==================== Delete ====================
|
|
|
|
|
|
public function test_admin_can_delete_schedule(): void
|