// A refused QA administrative destination must retain the ordinary investor session. const { start, BASE, assert, sanitized, } = require('./portal-visual-qa-lib.cjs'); void (async () => { const q = await start('qa-report-access-chromium-20261010'); let page; try { q.phase( 'QA21 forbidden report, visible return to dashboard, session recovery', ); const { page: p, ctx } = await q.context('promoter'); page = p; await q.open(page, '/qa-auditoria/legado-piloto-qa'); assert.equal(new URL(page.url()).pathname, '/login'); await q.login(page, 'promoter'); const denied = await q.open(page, '/qa-auditoria/legado-piloto-qa'); assert.equal(denied.status(), 403); await page .getByRole('heading', { name: 'Relatório reservado à gestão e auditoria', }) .waitFor(); assert( await page .getByText('A sua sessão está autenticada.', { exact: false }) .isVisible(), ); await q.shot(page, 'refused-report-with-return'); await page .getByRole('link', { name: 'Abrir o painel', exact: true }) .click(); await page.waitForURL(BASE + '/dashboard'); await page.locator('main').first().waitFor(); assert.equal((await q.open(page, '/investimentos')).status(), 200); assert.equal((await page.reload()).status(), 200); q.proof.checks = { report_remains_forbidden: true, visible_dashboard_return: true, session_retained_investments_reload: true, account18_not_retested: true, }; await q.logout(page); await ctx.close(); q.proof.result = 'passed'; } catch (e) { q.proof.result = 'failed'; q.proof.error = sanitized(e); } finally { q.proof.finished_at = new Date().toISOString(); q.save(); await q.browser.close(); console.log( JSON.stringify({ result: q.proof.result, checks: q.proof.checks, receipt: q.receipt, }), ); if (q.proof.result !== 'passed') process.exitCode = 1; } })();