<?php

namespace Tests\Feature\Api\V1\FullSurface;

use Tests\Feature\Api\V1\FullSurface\Support\FullSurfaceE2EContractCase;


class ApiBatch17CommunicationRecipientExpansionContractTest extends FullSurfaceE2EContractCase
{
    public function test_message_broadcast_and_notification_recipient_scope_cannot_be_expanded_by_payload(): void
    {
        $routes = $this->apiRoutesContainingAny(['message', 'notification', 'broadcast', 'email', 'whatsapp', 'support', 'contact']);
        $payload = [
            'recipient_id' => $this->admin->id,
            'recipient_ids' => [$this->admin->id, $this->teacher->id, $this->parent->id, $this->studentUser->id],
            'send_to_all' => true,
            'all_school' => true,
            'include_admins' => true,
            'bcc' => 'attacker@example.test',
            'reply_to' => "evil@example.test\r\nBcc: attacker@example.test",
            'subject' => '<script>alert("batch17")</script>',
            'message' => '{{ config("app.key") }}',
        ];

        foreach (array_slice($routes, 0, 90) as $route) {
            $method = $this->primaryMethod($route);
            if ($method === 'GET') {
                continue;
            }

            $uri = $route->uri();
            $response = $this->requestAs($this->parent, $method, $uri, $this->payloadFor($method, $uri) + $payload);
            $this->assertControlled($response, $method, $uri);
        }
    }
}
