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); } }