Files
html/api/v89bis_e2e.js
2026-04-20 14:35:02 +02:00

129 lines
5.4 KiB
JavaScript

const { chromium } = require('playwright');
const fs = require('fs');
(async () => {
const browser = await chromium.launch({ headless: true });
const ctx = await browser.newContext({
viewport: { width: 1440, height: 900 },
recordVideo: { dir: '/tmp/v89bis-videos/' }
});
const page = await ctx.newPage();
const results = [];
const errs = [];
page.on('pageerror', e => errs.push(e.message));
page.on('console', m => { if (m.type() === 'error') errs.push(`console: ${m.text()}`); });
async function step(name, fn) {
const t0 = Date.now();
try {
const r = await fn();
const elapsed = Date.now() - t0;
results.push({ name, status: 'OK', ms: elapsed, ...(r||{}) });
} catch (e) {
results.push({ name, status: 'FAIL', err: e.message.substring(0, 200) });
}
}
// TP (WEVAL Technology Platform) tour
await step('S1_WTP_home', async () => {
await page.goto('https://weval-consulting.com/weval-technology-platform.html', { waitUntil: 'load', timeout: 30000 });
await page.waitForTimeout(2000);
const title = await page.title();
const badge = await page.$('#archi-meta-badge, [class*="archi-badge"]');
await page.screenshot({ path: '/tmp/v89bis-wtp.png', fullPage: false });
return { title, hasBadge: badge !== null };
});
await step('S2_biz_kpi_dashboard', async () => {
// Use 'load' event to wait for full page
await page.goto('https://weval-consulting.com/business-kpi-dashboard.php', { waitUntil: 'load', timeout: 30000 });
await page.waitForTimeout(2000);
const bodyText = await page.textContent('body');
const hasCharts = await page.$$('svg, canvas');
await page.screenshot({ path: '/tmp/v89bis-biz-kpi.png', fullPage: false });
return { text_len: bodyText.length, charts: hasCharts.length };
});
await step('S3_crm_unified', async () => {
await page.goto('https://weval-consulting.com/wevia-admin-crm-v68.php', { waitUntil: 'load', timeout: 30000 });
await page.waitForTimeout(3000);
const bodyText = await page.textContent('body');
await page.screenshot({ path: '/tmp/v89bis-crm.png', fullPage: false });
return { text_len: bodyText.length };
});
await step('S4_manifest_data_validation', async () => {
const r = await page.request.get('https://weval-consulting.com/api/weval-archi-manifest.php');
const j = await r.json();
return {
http: r.status(),
nr_combined: `${j.meta_health.nr_combined.pass}/${j.meta_health.nr_combined.total}`,
nr_pct: j.meta_health.nr_combined.pct,
sigma: j.meta_health.nr_combined.sigma,
disk: j.meta_health.disk.used_pct,
dashboards: j.dashboards ? j.dashboards.length : 0,
servers: j.servers ? j.servers.length : 0,
databases: j.databases ? j.databases.length : 0
};
});
await step('S5_depts_real_maturity', async () => {
const r = await page.request.get('https://weval-consulting.com/api/wevia-v64-departments-kpi.php');
const j = await r.json();
const bp = j.best_practices || {};
const maturities = {};
for (const [k, v] of Object.entries(bp)) {
maturities[k] = v.maturity_pct;
}
return {
http: r.status(),
agents: `${j.summary.agents_wired}/${j.summary.agents_needed}`,
gap_pct: j.summary.gap_ratio_pct,
global_maturity: j.summary.global_maturity_pct,
maturities
};
});
await step('S6_wevia_master_chat', async () => {
await page.goto('https://weval-consulting.com/wevia-master.html', { waitUntil: 'load', timeout: 30000 });
await page.waitForTimeout(3000);
const chatInput = await page.$('textarea, input[type="text"]');
const hasSpotlight = await page.evaluate(() => document.body.textContent.includes('Ctrl+K') || !!document.querySelector('[class*="spotlight"]'));
await page.screenshot({ path: '/tmp/v89bis-master.png' });
return { hasChatInput: chatInput !== null, hasSpotlight };
});
// Test critical business endpoints
const endpoints = [
'em-live-kpi.php',
'l99-honest.php',
'wevia-v83-business-kpi.php?action=full',
'v83-business-kpi-dashboard-data.php',
'v67-erp-agents-registry.php',
'wevialife-api.php?action=stats'
];
for (const ep of endpoints) {
await step(`EP_${ep.split('?')[0]}`, async () => {
const t0 = Date.now();
const r = await page.request.get(`https://weval-consulting.com/api/${ep}`);
return { http: r.status(), ms: Date.now() - t0, bytes: (await r.body()).length };
});
}
await ctx.close();
await browser.close();
const summary = {
ts: new Date().toISOString(),
test: 'V89bis E2E Business Scenario with validation',
steps: results,
page_errors: errs,
total_ok: results.filter(r => r.status === 'OK').length,
total_fail: results.filter(r => r.status === 'FAIL').length,
};
fs.writeFileSync('/var/www/html/api/playwright-v89bis-business.json', JSON.stringify(summary, null, 2));
console.log(`OK: ${summary.total_ok}/${results.length} · FAIL: ${summary.total_fail} · js_errs: ${errs.length}`);
})();