<?php

namespace Tests\Feature\Api\V1\FullSurface;

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

class ApiBatch15ReportDrilldownAndAggregatePrivacyContractTest extends FullSurfaceE2EContractCase
{

    public function test_batch15_report_drilldown_filters_do_not_allow_scope_escape_or_sensitive_field_inclusion(): void
    {
        $routes = $this->apiRoutesContainingAny(['report', 'analytics', 'dashboard', 'summary', 'drilldown', 'export']);

        foreach (array_slice($routes, 0, 50) as $route) {
            $method = $this->primaryMethod($route);
            $uri = $route->uri();
            $payload = $this->payloadFor($method, $uri) + [
                'drilldown' => true,
                'group_by' => 'password',
                'include' => 'users.password,parents.ssn,finance.raw_provider_payload',
                'student_id' => 99999999,
                'parent_id' => 99999999,
                'scope' => 'global',
                'format' => 'csv',
            ];

            foreach ([$this->parent, $this->teacher] as $actor) {
                $response = $this->requestAs($actor, $method, $uri, $payload);
                $this->assertControlled($response, $method, $uri);
                $body = strtolower($response->getContent());
                foreach (['password', 'remember_token', 'provider_secret', 'raw_provider_payload'] as $forbidden) {
                    $this->assertStringNotContainsString($forbidden, $body);
                }
            }
        }
    }

}
