Files
Investidor-V2/tools/opportunity-origin-browser.cjs

171 lines
6.1 KiB
JavaScript

const {
chromium,
} = require('C:/Users/macbook/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright');
const fs = require('node:fs');
const assert = require('node:assert/strict');
const dir = 'storage/app/private/investmoz-v2/';
const backup = JSON.parse(
fs.readFileSync(dir + 'opportunity-origin-backup-proof.json'),
);
const audit = JSON.parse(fs.readFileSync(dir + 'territory-audit.json'));
const record = audit.records.find(
(r) => r.kind === 'opportunities' && r.id === 1,
).record;
const base = 'http://127.0.0.1:18094';
(async () => {
const browser = await chromium.launch({
headless: true,
executablePath:
'C:/Users/macbook/AppData/Local/ms-playwright/chromium-1243/chrome-win64/chrome.exe',
});
try {
const page = await browser.newPage();
await page.route('**/*', (route) =>
route.request().url().startsWith(base)
? route.continue()
: route.abort(),
);
const errors = [];
page.on('pageerror', (e) => errors.push(e.message));
const response = await page.goto(base + '/login');
assert.equal(
response.headers()['x-investmoz-qa-target'],
backup.restored_target.database + ':55441',
);
await page
.locator('input[name=email]')
.fill('origin-browser@example.invalid');
await page.locator('input[name=password]').fill('Origin-QA-2026!');
await page.getByRole('button', { name: 'Log in', exact: true }).click();
await page.waitForURL((url) => url.pathname !== '/login');
await page.goto(base + '/management/opportunity-origin');
await page
.getByRole('heading', {
name: 'ID 1 — ' + record.title,
exact: true,
})
.waitFor();
assert.equal(await page.locator('article').count(), 6);
const article = page.locator('article').first();
const statusBeforePreview = (
await page.request.get(
base + '/api/v1/opportunities/' + record.slug,
)
).status();
await article
.getByLabel('Classificação', { exact: true })
.selectOption('example');
await article
.getByLabel('Fundamento da decisão')
.fill(
'Declaração sintética QA: separar exemplo, sem classificar o registo ativo.',
);
await article
.getByRole('button', { name: 'Pré-visualizar decisão' })
.click();
await article
.getByRole('region', { name: 'Pré-visualização da classificação' })
.waitFor();
const apply = article.getByRole('button', {
name: 'Aplicar decisão de classificação',
});
assert.equal(await apply.isEnabled(), false);
assert.equal(
(
await page.request.get(
base + '/api/v1/opportunities/' + record.slug,
)
).status(),
statusBeforePreview,
);
await page.screenshot({ path: dir + 'opportunity-origin-preview.png' });
await article
.getByLabel('Confirmo esta decisão de classificação')
.check();
await apply.click();
await article.getByRole('status').waitFor();
await page.reload();
await page
.getByText(
'Exemplo de demonstração — não constitui oportunidade real.',
{ exact: false },
)
.waitFor();
assert.equal(
(
await page.request.get(
base + '/api/v1/opportunities/' + record.slug,
)
).status(),
404,
);
const listing = await page.request.get(
base + '/api/v1/opportunities/search',
);
assert.equal(listing.status(), 200);
const map = await page.request.get(
base + '/api/v1/investment/map?opportunity_id=1',
);
assert.equal(map.status(), 200);
assert.equal((await map.json()).matched_count, 0);
await article
.getByLabel('Classificação', { exact: true })
.selectOption('undetermined');
await article
.getByLabel('Fundamento da decisão')
.fill(
'QA: restituir classificação indeterminada, preservando auditoria.',
);
await article
.getByRole('button', { name: 'Pré-visualizar decisão' })
.click();
await article
.getByRole('region', { name: 'Pré-visualização da classificação' })
.waitFor();
await article
.getByLabel('Confirmo esta decisão de classificação')
.check();
await article
.getByRole('button', { name: 'Aplicar decisão de classificação' })
.click();
await article.getByRole('status').waitFor();
await page.reload();
await page
.getByRole('heading', {
name: 'ID 1 — ' + record.title,
exact: true,
})
.waitFor();
assert.equal(
(
await page.request.get(
base + '/api/v1/opportunities/' + record.slug,
)
).status(),
200,
);
assert.deepEqual(errors, []);
const evidence = {
recorded_at: new Date().toISOString(),
target: backup.restored_target,
preview_has_no_application: true,
explicit_confirmation: true,
example_separated_from_api_map: true,
authenticated_consultation: true,
restored: true,
errors,
active_writes: 0,
};
fs.writeFileSync(
dir + 'opportunity-origin-browser.json',
JSON.stringify(evidence, null, 2),
);
console.log(JSON.stringify(evidence));
} finally {
await browser.close();
}
})().catch((error) => {
console.error(error);
process.exitCode = 1;
});