MCPcopy Create free account
hub / github.com/error311/FileRise / runGatewayTest

Function runGatewayTest

public/js/adminPanel.js:4576–4632  ·  view source on GitHub ↗
(id)

Source from the content-addressed store, hash-verified

4574 };
4575
4576 const runGatewayTest = async (id) => {
4577 if (!id) return;
4578 try {
4579 setTestOutput(tf('source_test_running', 'Testing...'));
4580 const includeSecrets = !!includeSecretsEl?.checked;
4581 const res = await fetch(withBase('/api/pro/gateways/test.php'), {
4582 method: 'POST',
4583 credentials: 'include',
4584 headers: {
4585 'Content-Type': 'application/json',
4586 'X-CSRF-Token': getCsrf(),
4587 'Accept': 'application/json',
4588 },
4589 body: JSON.stringify({ id, includeSecrets }),
4590 });
4591 const data = await safeJson(res);
4592 if (!res.ok || !data) {
4593 throw new Error(data?.error || tf('gateway_test_failed', 'Gateway test failed.'));
4594 }
4595
4596 const lines = [];
4597 if (data.ok === true) {
4598 lines.push(tf('gateway_test_ok', 'Gateway test passed.'));
4599 } else {
4600 lines.push(tf('gateway_test_failed', 'Gateway test failed.'));
4601 }
4602 const errors = Array.isArray(data.errors) ? data.errors : [];
4603 const warnings = Array.isArray(data.warnings) ? data.warnings : [];
4604 if (errors.length) {
4605 lines.push('');
4606 lines.push('Errors:');
4607 errors.forEach((e) => lines.push(`- ${String(e)}`));
4608 }
4609 if (warnings.length) {
4610 lines.push('');
4611 lines.push('Warnings:');
4612 warnings.forEach((w) => lines.push(`- ${String(w)}`));
4613 }
4614 if (includeSecrets) {
4615 lines.push('');
4616 lines.push(tf('gateway_secrets_warning', 'Warning: snippets may include secrets. Handle output carefully.'));
4617 }
4618 setTestOutput(lines.join('\n'));
4619 state.previewGatewayId = String(id);
4620 state.lastTestResult = data;
4621 refreshSnippetPreview();
4622 if (data.ok === true) {
4623 showToast(tf('gateway_test_ok', 'Gateway test passed.'));
4624 } else {
4625 showToast((errors[0] || tf('gateway_test_failed', 'Gateway test failed.')), 'error');
4626 }
4627 } catch (err) {
4628 const msg = err?.message || tf('gateway_test_failed', 'Gateway test failed.');
4629 setTestOutput(msg);
4630 showToast(msg, 'error');
4631 }
4632 };
4633

Callers 1

initGatewaysSectionFunction · 0.85

Calls 7

setTestOutputFunction · 0.85
withBaseFunction · 0.85
getCsrfFunction · 0.85
refreshSnippetPreviewFunction · 0.85
tfFunction · 0.70
safeJsonFunction · 0.70
showToastFunction · 0.70

Tested by

no test coverage detected