4dd40f609f
create/update/list через headless Chromium по образцу refresh-session.js. Селекторы зафиксированы из recon-снапшота rt-add-project-form.yml (Task 1). stdin/stdout JSON, exit codes 0/1/2/3/4 (success/auth/selector/timeout/input). Фикстурный тест против локального HTML — без живого портала. Runner — встроенный node:test (app/playwright не использует @playwright/test, только playwright core); skipLogin режим открывает фикстуру напрямую. Spec §4.3. Task 6 of 12. Node-тесты 2/2. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
66 lines
2.3 KiB
JavaScript
66 lines
2.3 KiB
JavaScript
/**
|
|
* Фикстурный тест manage-project.js — против локального HTML, без живого портала.
|
|
*
|
|
* Runner: встроенный node:test (проект не использует @playwright/test —
|
|
* в app/playwright только playwright core). Запуск: `node --test manage-project.test.js`.
|
|
*/
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert');
|
|
const { execFile } = require('node:child_process');
|
|
const path = require('node:path');
|
|
|
|
const SCRIPT = path.resolve(__dirname, 'manage-project.js');
|
|
const FIXTURE_URL = 'file://' + path.resolve(__dirname, '../tests/fixtures/supplier-portal/rt-add-project-form.html');
|
|
|
|
function runScript(input) {
|
|
return new Promise((resolve, reject) => {
|
|
const child = execFile('node', [SCRIPT], { timeout: 60000 }, (err, stdout, stderr) => {
|
|
if (err && err.code !== undefined && typeof err.code !== 'number') {
|
|
return reject(err);
|
|
}
|
|
resolve({ stdout: stdout.toString(), stderr: stderr.toString() });
|
|
});
|
|
child.stdin.write(JSON.stringify(input));
|
|
child.stdin.end();
|
|
});
|
|
}
|
|
|
|
test('createProject fills form and returns row id', async () => {
|
|
const result = await runScript({
|
|
operation: 'create',
|
|
login: 'fixture-noop',
|
|
password: 'fixture-noop',
|
|
url: FIXTURE_URL,
|
|
skipLogin: true,
|
|
dto: {
|
|
tag: 'TEST',
|
|
name: 'Test Project',
|
|
platforms: ['B1', 'B2'],
|
|
signal_type: 'site',
|
|
limit: 25,
|
|
workdays: [1, 2, 3, 4, 5],
|
|
regions: [],
|
|
region_mode: 'include',
|
|
domains: ['example.com'],
|
|
active: true,
|
|
},
|
|
});
|
|
|
|
const out = JSON.parse(result.stdout);
|
|
assert.ok(out.external_id, 'external_id should be truthy');
|
|
assert.match(out.external_id, /^\d+$/, 'external_id should be numeric string');
|
|
});
|
|
|
|
test('listProjects returns array', async () => {
|
|
const result = await runScript({
|
|
operation: 'list',
|
|
login: 'fixture-noop',
|
|
password: 'fixture-noop',
|
|
url: FIXTURE_URL,
|
|
skipLogin: true,
|
|
});
|
|
|
|
const out = JSON.parse(result.stdout);
|
|
assert.ok(Array.isArray(out.projects), 'projects should be an array');
|
|
});
|