not->toBeFalse(); expect($content)->toContain("get_internal_department_ids"); expect($content)->toContain("get_internal_department_goal_progress_webhook_url"); }); it('posts to the dedicated internal goal progress webhook when all goal departments are internal', function (): void { $content = file_get_contents(app_path('cron/Cron.php')); expect($content)->not->toBeFalse(); // The new branch should be guarded by an "all internal" check. expect($content)->toContain('$allInternal'); expect($content)->toContain('count(array_diff($goalDeptIds, $internalDepartmentIds)) === 0'); // It should call send_webhook_message with the dedicated internal URL. expect($content)->toContain("send_webhook_message((string)goals_progress_alert_renderer::render(\$criteria), \$internalWebhook)"); // It should log a confirmation line referencing the goal id and the // department list so an operator can verify the message actually went // somewhere. expect($content)->toContain('internal goal progress webhook'); expect($content)->toContain('departments: '); }); it('logs a diagnostic and falls back to per-department webhooks when the internal goal progress webhook is empty', function (): void { $content = file_get_contents(app_path('cron/Cron.php')); expect($content)->not->toBeFalse(); expect($content)->toContain('internal_department_goal_progress_webhook_url is empty'); expect($content)->toContain('falling back to per-department webhooks'); // The per-department fallback should still run after the internal-webhook // branch is skipped. expect($content)->toContain('$dept->slack_webhook->value()'); }); it('skips the internal goal progress webhook for goals that include any non-internal department', function (): void { $content = file_get_contents(app_path('cron/Cron.php')); expect($content)->not->toBeFalse(); // The internal-webhook branch must be guarded by the all-internal check; // otherwise external customers' goal alerts would be silently redirected // to the internal Slack channel. expect($content)->toContain('if ($allInternal) {'); expect($content)->toContain('send_webhook_message((string)goals_progress_alert_renderer::render($criteria), $internalWebhook)'); // The per-department loop must still be reachable for mixed/external goals. expect($content)->toContain('$sentToDept = false;'); expect($content)->toContain('$dept->slack_webhook->value()'); });