import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; const here = dirname(fileURLToPath(import.meta.url)); const source = readFileSync(resolve(here, "../src/features/operator/OperatorQueuePage.tsx"), "utf8"); const translations = readFileSync(resolve(here, "../src/i18n/generatedTranslations.ts"), "utf8"); const backendRouter = readFileSync(resolve(here, "../../src/govoplan_campaign/backend/router.py"), "utf8"); const responseSecurity = readFileSync(resolve(here, "../../src/govoplan_campaign/backend/response_security.py"), "utf8"); assert.match(source, / `\$\{row\.campaign\.id\}:\$\{rowVersionId\(row\)/); assert.match(source, /row\.campaign\.id === selectedCampaignId && rowVersionId\(row\) === selectedVersionParam/); assert.match(source, /retryCampaignJobs[\s\S]*version_id: rowVersionId\(row\)/); assert.match(source, /sendUnattemptedCampaignJobs[\s\S]*version_id: rowVersionId\(row\)/); assert.match(source, /report\?version=\$\{encodeURIComponent\(rowVersionId\(row\)\)\}&send_status=outcome_unknown/); for (const count of ["queued", "claimed", "sending", "completed"]) { assert.match(source, new RegExp(`row\\.${count}`)); assert.match(source, new RegExp(`totals\\.${count}`)); } for (const field of ["campaign_version_id", "entry_id", "entry_index", "queue_status", "send_status", "imap_status", "attempt_count", "queued_at", "sent_at", "updated_at", "last_error"]) { assert.match(source, new RegExp(field)); } assert.match(source, /deliveryResultSummary[\s\S]*send_status[\s\S]*imap_status/); assert.match(source, /durableResultText[\s\S]*slice\(0, 239\)/); assert.match(source, /permissions\.canOpenReport[\s\S]*you_do_not_have_permission/); assert.doesNotMatch(source, /claim_token|eml_local_path|storage_key|smtp_transport_revision|eml_sha256|message_id_header|smtp_response|provider_response|resolved_attachments/); assert.match(backendRouter, /"last_error": public_delivery_result_message\([\s\S]*last_error=job\.last_error/); assert.match(responseSecurity, /Map persisted provider text to a stable business-safe explanation/); assert.match(responseSecurity, /SMTP delivery failed; an operator can inspect restricted diagnostics\./); assert.doesNotMatch(source, /window\.alert\s*\(/); assert.doesNotMatch(source, /function QueuePressureGrid|function OperatorJob/); assert.doesNotMatch(source, /humanize\(/); const localized = new Map([ ["i18n:govoplan-campaign.claimed.83c87884", ["Claimed", "Beansprucht"]], ["i18n:govoplan-campaign.sending.ceafde86", ["Sending", "Im Versand"]], ["i18n:govoplan-campaign.delivery_jobs_for_value0.50a94a70", ["Delivery jobs for {value0}", "Versandaufträge für {value0}"]], ["i18n:govoplan-campaign.open_recipient_report.d6892ee4", ["Open recipient report", "Empfängerbezogenen Bericht öffnen"]], ["i18n:govoplan-campaign.queued_at.1ac179b3", ["Queued at", "Eingereiht am"]], ["i18n:govoplan-campaign.sent_at.a6f45556", ["Sent at", "Gesendet am"]], ["i18n:govoplan-campaign.current.4fc0e2bc", ["Current", "Aktuell"]], ["i18n:govoplan-campaign.historical.bb2fe205", ["Historical", "Historisch"]], ["i18n:govoplan-campaign.pause_all_queued_work_for_this_campaign.64ee23cf", ["Pause all queued work for this Campaign", "Alle eingereihten Aufträge dieser Kampagne pausieren"]] ]); for (const [key, values] of localized) { assert.equal(translations.split(`"${key}"`).length - 1, 2, `${key} occurs once per language`); for (const value of values) assert(translations.includes(`"${key}": ${JSON.stringify(value)}`)); }