Initial commit
Some checks failed
Deploy / deploy (push) Has been cancelled

This commit is contained in:
ssww23
2026-03-10 00:55:37 +03:00
parent fc0f28d830
commit 93a655235a
155 changed files with 24768 additions and 0 deletions

View File

@@ -0,0 +1,134 @@
<?php
namespace Tests\Feature;
use App\Models\Category;
use App\Models\Product;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class AdminProductImageUploadTest extends TestCase
{
use RefreshDatabase;
public function test_admin_can_create_product_with_main_and_gallery_images(): void
{
Storage::fake('public');
$admin = User::factory()->create([
'is_admin' => true,
]);
$category = Category::query()->create([
'name' => 'Видеокарты',
'slug' => 'video-cards',
'is_active' => true,
]);
$response = $this
->actingAs($admin)
->post(route('admin.products.store'), [
'category_id' => $category->id,
'name' => 'RTX 5090',
'slug' => '',
'sku' => 'RTX-5090',
'price' => '199999.99',
'old_price' => '209999.99',
'stock' => 3,
'short_description' => 'Флагманская видеокарта',
'description' => 'Описание товара',
'image' => UploadedFile::fake()->create('main.jpg', 120, 'image/jpeg'),
'gallery_images' => [
UploadedFile::fake()->create('gallery-1.jpg', 120, 'image/jpeg'),
UploadedFile::fake()->create('gallery-2.webp', 120, 'image/webp'),
],
'is_active' => '1',
]);
$response
->assertRedirect(route('admin.products.index'))
->assertSessionDoesntHaveErrors();
$product = Product::query()->where('name', 'RTX 5090')->firstOrFail();
$this->assertSame('video-cards', $product->category->slug);
$this->assertNotNull($product->image_path);
$this->assertIsArray($product->gallery_paths);
$this->assertCount(2, $product->gallery_paths);
$this->assertStringStartsWith('products/', $product->image_path);
Storage::disk('public')->assertExists($product->image_path);
foreach ($product->gallery_paths as $path) {
$this->assertStringStartsWith('products/', $path);
Storage::disk('public')->assertExists($path);
}
}
public function test_admin_can_remove_product_images_from_edit_form(): void
{
Storage::fake('public');
$admin = User::factory()->create([
'is_admin' => true,
]);
$category = Category::query()->create([
'name' => 'Ноутбуки',
'slug' => 'laptops',
'is_active' => true,
]);
Storage::disk('public')->put('products/main.jpg', 'main-image');
Storage::disk('public')->put('products/gallery-1.jpg', 'gallery-one');
Storage::disk('public')->put('products/gallery-2.webp', 'gallery-two');
$product = Product::query()->create([
'category_id' => $category->id,
'name' => 'Lenovo Legion',
'slug' => 'lenovo-legion',
'sku' => 'LEGION-01',
'price' => '159999.99',
'old_price' => '169999.99',
'stock' => 5,
'short_description' => 'Игровой ноутбук',
'description' => 'Описание ноутбука',
'image_path' => 'products/main.jpg',
'gallery_paths' => ['products/gallery-1.jpg', 'products/gallery-2.webp'],
'is_active' => true,
]);
$response = $this
->actingAs($admin)
->put(route('admin.products.update', $product), [
'category_id' => $category->id,
'name' => 'Lenovo Legion',
'slug' => 'lenovo-legion',
'sku' => 'LEGION-01',
'price' => '159999.99',
'old_price' => '169999.99',
'stock' => 5,
'short_description' => 'Игровой ноутбук',
'description' => 'Описание ноутбука',
'remove_image' => '1',
'remove_gallery_paths' => ['products/gallery-1.jpg'],
'is_active' => '1',
]);
$response
->assertRedirect(route('admin.products.index'))
->assertSessionDoesntHaveErrors();
$product->refresh();
$this->assertSame('products/gallery-2.webp', $product->image_path);
$this->assertSame([], $product->gallery_paths ?? []);
Storage::disk('public')->assertMissing('products/main.jpg');
Storage::disk('public')->assertMissing('products/gallery-1.jpg');
Storage::disk('public')->assertExists('products/gallery-2.webp');
}
}

View File

@@ -0,0 +1,115 @@
<?php
namespace Tests\Feature;
use App\Models\ChatConversation;
use App\Models\ChatMessage;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use Tests\TestCase;
class ChatConversationClosingTest extends TestCase
{
use RefreshDatabase;
public function test_admin_can_close_chat_conversation(): void
{
$admin = User::factory()->create([
'is_admin' => true,
]);
$customer = User::factory()->create();
$conversation = ChatConversation::query()->create([
'user_id' => $customer->id,
'visitor_token' => (string) Str::uuid(),
'status' => ChatConversation::STATUS_OPEN,
'last_message_at' => now(),
]);
$response = $this
->actingAs($admin)
->patch(route('admin.chats.status', $conversation), [
'status' => ChatConversation::STATUS_CLOSED,
]);
$response->assertRedirect(route('admin.chats.index', ['conversation' => $conversation->id]));
$this->assertSame(ChatConversation::STATUS_CLOSED, $conversation->fresh()->status);
}
public function test_customer_message_after_chat_closure_starts_new_conversation(): void
{
$customer = User::factory()->create();
$closedConversation = ChatConversation::query()->create([
'user_id' => $customer->id,
'visitor_token' => (string) Str::uuid(),
'status' => ChatConversation::STATUS_CLOSED,
'last_message_at' => now(),
]);
$closedConversation->messages()->create([
'sender' => 'customer',
'body' => 'Старый вопрос',
'is_read' => true,
]);
$this
->actingAs($customer)
->getJson(route('chat.messages'))
->assertOk()
->assertJsonPath('conversation.id', $closedConversation->id)
->assertJsonPath('conversation.is_closed', true);
$this
->actingAs($customer)
->postJson(route('chat.send'), [
'message' => 'Новый вопрос',
])
->assertOk()
->assertJsonPath('conversation.is_closed', false);
$this->assertSame(ChatConversation::STATUS_CLOSED, $closedConversation->fresh()->status);
$this->assertSame(2, ChatConversation::query()->where('user_id', $customer->id)->count());
$newConversation = ChatConversation::query()
->where('user_id', $customer->id)
->latest('id')
->firstOrFail();
$this->assertNotSame($closedConversation->id, $newConversation->id);
$this->assertSame(ChatConversation::STATUS_OPEN, $newConversation->status);
$this->assertSame('Новый вопрос', $newConversation->messages()->firstOrFail()->body);
}
public function test_admin_can_delete_chat_conversation_with_messages(): void
{
$admin = User::factory()->create([
'is_admin' => true,
]);
$customer = User::factory()->create();
$conversation = ChatConversation::query()->create([
'user_id' => $customer->id,
'visitor_token' => (string) Str::uuid(),
'status' => ChatConversation::STATUS_OPEN,
'last_message_at' => now(),
]);
$message = $conversation->messages()->create([
'sender' => 'customer',
'body' => 'Нужно удалить этот чат',
'is_read' => false,
]);
$response = $this
->actingAs($admin)
->delete(route('admin.chats.destroy', $conversation));
$response->assertRedirect(route('admin.chats.index'));
$this->assertDatabaseMissing('chat_conversations', ['id' => $conversation->id]);
$this->assertDatabaseMissing('chat_messages', ['id' => $message->id]);
$this->assertSame(0, ChatConversation::query()->count());
$this->assertSame(0, ChatMessage::query()->count());
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ExampleTest extends TestCase
{
use RefreshDatabase;
/**
* A basic test example.
*/
public function test_the_application_returns_a_successful_response(): void
{
$response = $this->get('/');
$response->assertStatus(200);
}
}