|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
|
|
+use App\Jobs\GenerateInstallationPack;
|
|
|
use App\Models\Dictionary\Area;
|
|
use App\Models\Dictionary\Area;
|
|
|
use App\Models\Dictionary\District;
|
|
use App\Models\Dictionary\District;
|
|
|
use App\Models\File;
|
|
use App\Models\File;
|
|
@@ -15,6 +16,7 @@ use App\Models\Role;
|
|
|
use App\Models\User;
|
|
use App\Models\User;
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Http\UploadedFile;
|
|
|
|
|
+use Illuminate\Support\Facades\Bus;
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
use Tests\TestCase;
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
@@ -194,6 +196,25 @@ class OrderControllerTest extends TestCase
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function test_manager_can_update_ready_date(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $order = Order::factory()->create([
|
|
|
|
|
+ 'ready_date' => '2026-04-01',
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ $response = $this->actingAs($this->managerUser)
|
|
|
|
|
+ ->post(route('order.store'), [
|
|
|
|
|
+ 'id' => $order->id,
|
|
|
|
|
+ 'ready_date' => '2026-04-25',
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ $response->assertRedirect();
|
|
|
|
|
+ $this->assertDatabaseHas('orders', [
|
|
|
|
|
+ 'id' => $order->id,
|
|
|
|
|
+ 'ready_date' => '2026-04-25',
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// ==================== Show ====================
|
|
// ==================== Show ====================
|
|
|
|
|
|
|
|
public function test_can_view_order_details(): void
|
|
public function test_can_view_order_details(): void
|
|
@@ -210,6 +231,26 @@ class OrderControllerTest extends TestCase
|
|
|
$response->assertSee($order->object_address);
|
|
$response->assertSee($order->object_address);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function test_order_details_show_area_and_district(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $district = District::factory()->create(['name' => 'Центральный округ']);
|
|
|
|
|
+ $area = Area::factory()->create([
|
|
|
|
|
+ 'district_id' => $district->id,
|
|
|
|
|
+ 'name' => 'Тверской район',
|
|
|
|
|
+ ]);
|
|
|
|
|
+ $order = Order::factory()->create([
|
|
|
|
|
+ 'district_id' => $district->id,
|
|
|
|
|
+ 'area_id' => $area->id,
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ $response = $this->actingAs($this->managerUser)
|
|
|
|
|
+ ->get(route('order.show', $order));
|
|
|
|
|
+
|
|
|
|
|
+ $response->assertOk();
|
|
|
|
|
+ $response->assertSee('Центральный округ');
|
|
|
|
|
+ $response->assertSee('Тверской район');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function test_brigadier_cannot_view_handed_over_order_details(): void
|
|
public function test_brigadier_cannot_view_handed_over_order_details(): void
|
|
|
{
|
|
{
|
|
|
$order = Order::factory()->create([
|
|
$order = Order::factory()->create([
|
|
@@ -236,6 +277,20 @@ class OrderControllerTest extends TestCase
|
|
|
$response->assertViewIs('orders.edit');
|
|
$response->assertViewIs('orders.edit');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function test_manager_can_edit_ready_date_in_order_edit_form(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $order = Order::factory()->create();
|
|
|
|
|
+
|
|
|
|
|
+ $response = $this->actingAs($this->managerUser)
|
|
|
|
|
+ ->get(route('order.edit', $order));
|
|
|
|
|
+
|
|
|
|
|
+ $response->assertOk();
|
|
|
|
|
+ $this->assertMatchesRegularExpression(
|
|
|
|
|
+ '/<input[^>]*name="ready_date"(?:(?!disabled).)*>/s',
|
|
|
|
|
+ $response->getContent()
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// ==================== Destroy ====================
|
|
// ==================== Destroy ====================
|
|
|
|
|
|
|
|
public function test_can_delete_order(): void
|
|
public function test_can_delete_order(): void
|
|
@@ -307,8 +362,39 @@ class OrderControllerTest extends TestCase
|
|
|
->getJson(route('order.search', ['s' => 'Менеджер Поиска']));
|
|
->getJson(route('order.search', ['s' => 'Менеджер Поиска']));
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
$response->assertOk();
|
|
|
- $response->assertJsonPath((string) $matchedOrder->id, $matchedOrder->common_name);
|
|
|
|
|
- $response->assertJsonMissing([$otherOrder->id => $otherOrder->common_name]);
|
|
|
|
|
|
|
+ $response->assertJsonPath((string) $matchedOrder->id, $matchedOrder->move_maf_name);
|
|
|
|
|
+ $response->assertJsonMissing([$otherOrder->id => $otherOrder->move_maf_name]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_order_search_route_includes_site_name_and_excludes_current_order(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $district = District::factory()->create(['name' => 'Северный округ']);
|
|
|
|
|
+ $area = Area::factory()->create([
|
|
|
|
|
+ 'district_id' => $district->id,
|
|
|
|
|
+ 'name' => 'Левобережный',
|
|
|
|
|
+ ]);
|
|
|
|
|
+ $currentOrder = Order::factory()->create([
|
|
|
|
|
+ 'district_id' => $district->id,
|
|
|
|
|
+ 'area_id' => $area->id,
|
|
|
|
|
+ 'name' => 'Текущая площадка',
|
|
|
|
|
+ 'object_address' => 'ул. Проверочная, д. 1',
|
|
|
|
|
+ ]);
|
|
|
|
|
+ $targetOrder = Order::factory()->create([
|
|
|
|
|
+ 'district_id' => $district->id,
|
|
|
|
|
+ 'area_id' => $area->id,
|
|
|
|
|
+ 'name' => 'Площадка назначения',
|
|
|
|
|
+ 'object_address' => 'ул. Проверочная, д. 2',
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ $response = $this->actingAs($this->adminUser)
|
|
|
|
|
+ ->getJson(route('order.search', [
|
|
|
|
|
+ 's' => 'Проверочная',
|
|
|
|
|
+ 'current_order_id' => $currentOrder->id,
|
|
|
|
|
+ ]));
|
|
|
|
|
+
|
|
|
|
|
+ $response->assertOk();
|
|
|
|
|
+ $response->assertJsonPath((string) $targetOrder->id, $targetOrder->move_maf_name);
|
|
|
|
|
+ $response->assertJsonMissing([(string) $currentOrder->id => $currentOrder->move_maf_name]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// ==================== MAF Operations ====================
|
|
// ==================== MAF Operations ====================
|
|
@@ -673,42 +759,69 @@ class OrderControllerTest extends TestCase
|
|
|
$this->assertCount(5, $order->fresh()->documents);
|
|
$this->assertCount(5, $order->fresh()->documents);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function test_can_upload_webp_photo(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ Storage::fake('public');
|
|
|
|
|
+
|
|
|
|
|
+ $order = Order::factory()->create();
|
|
|
|
|
+ $photo = UploadedFile::fake()->create('photo.webp', 100, 'image/webp');
|
|
|
|
|
+
|
|
|
|
|
+ $response = $this->actingAs($this->managerUser)
|
|
|
|
|
+ ->post(route('order.upload-photo', $order), [
|
|
|
|
|
+ 'photo' => [$photo],
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ $response->assertRedirect();
|
|
|
|
|
+ $saved = $order->fresh()->photos->first();
|
|
|
|
|
+ $this->assertNotNull($saved);
|
|
|
|
|
+ $this->assertSame('photo.webp', $saved->original_name);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// ==================== Generation ====================
|
|
// ==================== Generation ====================
|
|
|
|
|
|
|
|
- public function test_generate_installation_pack_requires_correct_status(): void
|
|
|
|
|
|
|
+ public function test_generate_installation_pack_is_allowed_for_any_status_when_data_is_valid(): void
|
|
|
{
|
|
{
|
|
|
|
|
+ Bus::fake();
|
|
|
|
|
+
|
|
|
|
|
+ $product = Product::factory()->create();
|
|
|
|
|
+ $mafOrder = MafOrder::factory()->create(['product_id' => $product->id]);
|
|
|
$order = Order::factory()->create([
|
|
$order = Order::factory()->create([
|
|
|
'order_status_id' => Order::STATUS_NEW,
|
|
'order_status_id' => Order::STATUS_NEW,
|
|
|
]);
|
|
]);
|
|
|
|
|
+ ProductSKU::factory()->create([
|
|
|
|
|
+ 'order_id' => $order->id,
|
|
|
|
|
+ 'product_id' => $product->id,
|
|
|
|
|
+ 'maf_order_id' => $mafOrder->id,
|
|
|
|
|
+ ]);
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->managerUser)
|
|
$response = $this->actingAs($this->managerUser)
|
|
|
->get(route('order.generate-installation-pack', $order));
|
|
->get(route('order.generate-installation-pack', $order));
|
|
|
|
|
|
|
|
$response->assertRedirect(route('order.show', $order));
|
|
$response->assertRedirect(route('order.show', $order));
|
|
|
- $response->assertSessionHas('danger');
|
|
|
|
|
|
|
+ $response->assertSessionHas('success');
|
|
|
|
|
+ Bus::assertDispatched(GenerateInstallationPack::class);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function test_generate_installation_pack_succeeds_with_correct_status(): void
|
|
|
|
|
|
|
+ public function test_generate_installation_pack_still_requires_connected_maf(): void
|
|
|
{
|
|
{
|
|
|
- $product = Product::factory()->create();
|
|
|
|
|
- $mafOrder = MafOrder::factory()->create(['product_id' => $product->id]);
|
|
|
|
|
|
|
+ Bus::fake();
|
|
|
|
|
|
|
|
|
|
+ $product = Product::factory()->create();
|
|
|
$order = Order::factory()->create([
|
|
$order = Order::factory()->create([
|
|
|
- 'order_status_id' => Order::STATUS_READY_TO_MOUNT,
|
|
|
|
|
|
|
+ 'order_status_id' => Order::STATUS_IN_MOUNT,
|
|
|
]);
|
|
]);
|
|
|
-
|
|
|
|
|
- // Create SKU with MAF assigned
|
|
|
|
|
ProductSKU::factory()->create([
|
|
ProductSKU::factory()->create([
|
|
|
'order_id' => $order->id,
|
|
'order_id' => $order->id,
|
|
|
'product_id' => $product->id,
|
|
'product_id' => $product->id,
|
|
|
- 'maf_order_id' => $mafOrder->id,
|
|
|
|
|
|
|
+ 'maf_order_id' => null,
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->managerUser)
|
|
$response = $this->actingAs($this->managerUser)
|
|
|
->get(route('order.generate-installation-pack', $order));
|
|
->get(route('order.generate-installation-pack', $order));
|
|
|
|
|
|
|
|
$response->assertRedirect(route('order.show', $order));
|
|
$response->assertRedirect(route('order.show', $order));
|
|
|
- $response->assertSessionHas('success');
|
|
|
|
|
|
|
+ $response->assertSessionHas('danger');
|
|
|
|
|
+ Bus::assertNotDispatched(GenerateInstallationPack::class);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// ==================== Export ====================
|
|
// ==================== Export ====================
|