<?php

it('exposes superuser cron status, history, manual run, and config routes', function (): void {
    $content = file_get_contents(app_path('routes/cronRoute.php'));

    expect($content)->not->toBeFalse();
    expect($content)->toContain('/superuser/cron');
    expect($content)->toContain('/superuser/cron/runs');
    expect($content)->toContain('/superuser/cron/run');
    expect($content)->toContain('/superuser/cron/config');
    expect($content)->toContain('new cron_scheduler()');
    expect($content)->toContain('queueTaskRun(');
    expect($content)->toContain('$response->success($run, 202)');
    expect($content)->toContain('CRON_JOB_QUEUED');
    expect($content)->toContain("requireClassicSuperuserPermission('superuser_cron_view')");
    expect($content)->toContain("requireClassicSuperuserPermission('SUPERUSER_RUN_CRON')");
    expect($content)->toContain("requireClassicSuperuserPermission('superuser_cron_manage')");
});

it('does not include caller-controlled cron php files', function (): void {
    $content = file_get_contents(app_path('routes/cronRoute.php'));

    expect($content)->not->toContain("WD . '/cron/'");
    expect($content)->not->toContain("file_exists(WD . '/cron/'");
    expect($content)->not->toContain("require_once WD . '/cron/'");
});

it('keeps the legacy cron post endpoint as a scheduler bridge', function (): void {
    $content = file_get_contents(app_path('routes/cronRoute.php'));

    expect($content)->toContain('runTask($job, \'manual\'');
    expect($content)->toContain("runDue('manual')");
    expect($content)->toContain('Cron job ran successfully');
});
