| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace Tests\Feature;
- use App\Models\ChatMessage;
- use App\Models\Order;
- use App\Models\Reclamation;
- use App\Models\Role;
- use App\Models\User;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- use Tests\TestCase;
- class ChatMessageControllerTest extends TestCase
- {
- use RefreshDatabase;
- protected $seed = true;
- public function test_brigadier_can_send_order_chat_message_without_manual_recipient_selection(): void
- {
- $admin = User::factory()->create(['role' => Role::ADMIN]);
- $manager = User::factory()->create(['role' => Role::MANAGER]);
- $brigadier = User::factory()->create(['role' => Role::BRIGADIER]);
- $order = Order::factory()->create([
- 'user_id' => $manager->id,
- 'brigadier_id' => $brigadier->id,
- 'order_status_id' => Order::STATUS_IN_MOUNT,
- ]);
- $response = $this->actingAs($brigadier)
- ->post(route('order.chat-messages.store', $order), [
- 'message' => 'Сообщение бригадира по площадке',
- 'notification_type' => ChatMessage::NOTIFICATION_RESPONSIBLES,
- ]);
- $response->assertRedirect();
- $response->assertSessionHas('success');
- $message = ChatMessage::query()->where('order_id', $order->id)->first();
- $this->assertNotNull($message);
- $this->assertSame(ChatMessage::NOTIFICATION_RESPONSIBLES, $message->notification_type);
- $recipientIds = $message->notifiedUsers->pluck('id')->all();
- $this->assertContains($admin->id, $recipientIds);
- $this->assertContains($manager->id, $recipientIds);
- $this->assertNotContains($brigadier->id, $recipientIds);
- }
- public function test_brigadier_can_send_reclamation_chat_message_without_manual_recipient_selection(): void
- {
- $admin = User::factory()->create(['role' => Role::ADMIN]);
- $manager = User::factory()->create(['role' => Role::MANAGER]);
- $brigadier = User::factory()->create(['role' => Role::BRIGADIER]);
- $reclamation = Reclamation::factory()->create([
- 'user_id' => $manager->id,
- 'brigadier_id' => $brigadier->id,
- 'status_id' => Reclamation::STATUS_IN_WORK,
- ]);
- $response = $this->actingAs($brigadier)
- ->post(route('reclamations.chat-messages.store', $reclamation), [
- 'message' => 'Сообщение бригадира по рекламации',
- 'notification_type' => ChatMessage::NOTIFICATION_RESPONSIBLES,
- ]);
- $response->assertRedirect();
- $response->assertSessionHas('success');
- $message = ChatMessage::query()->where('reclamation_id', $reclamation->id)->first();
- $this->assertNotNull($message);
- $this->assertSame(ChatMessage::NOTIFICATION_RESPONSIBLES, $message->notification_type);
- $recipientIds = $message->notifiedUsers->pluck('id')->all();
- $this->assertContains($admin->id, $recipientIds);
- $this->assertContains($manager->id, $recipientIds);
- $this->assertNotContains($brigadier->id, $recipientIds);
- }
- }
|