57 lines
2.2 KiB
JavaScript
57 lines
2.2 KiB
JavaScript
import test from 'node:test';
|
||
import assert from 'node:assert/strict';
|
||
import { harness, props, text } from './helpers/resource-incident-form.mjs';
|
||
const reasonLabel = 'Motivo (20–1000 caracteres)',
|
||
title = 'Título';
|
||
test('an upload incident response preserves the actual form fields, selected file and creation command without retrying', async () => {
|
||
const h = harness();
|
||
h.choose('Documentos');
|
||
h.change(title, 'SYNTHETIC document title');
|
||
h.change(reasonLabel, 'SYNTHETIC preserved upload reason');
|
||
const file = { name: 'synthetic.pdf' };
|
||
h.attach(file);
|
||
const request = h.submit();
|
||
await h.reply(503, {
|
||
message: 'Incidente técnico registado. Referência: SYNTHETIC-REFERENCE',
|
||
reference: 'SYNTHETIC-REFERENCE',
|
||
incident_recorded: true,
|
||
});
|
||
assert.equal(h.sent.length, 1);
|
||
assert.equal(h.reloads.length, 0);
|
||
assert.equal(h.value(title), 'SYNTHETIC document title');
|
||
assert.equal(h.value(reasonLabel), 'SYNTHETIC preserved upload reason');
|
||
assert.match(text(h.tree), /SYNTHETIC-REFERENCE/);
|
||
const retry = h.submit();
|
||
assert.equal(retry.form.get('file'), file);
|
||
assert.equal(
|
||
retry.form.get('creation_key'),
|
||
request.form.get('creation_key'),
|
||
);
|
||
assert.equal(retry.form.get('etag'), request.form.get('etag'));
|
||
});
|
||
test('reading the recorded upload incident adds its own operation label without resetting the preparation', () => {
|
||
const h = harness();
|
||
h.choose('Documentos');
|
||
h.change(title, 'SYNTHETIC draft');
|
||
h.change(reasonLabel, 'SYNTHETIC retained reason');
|
||
const file = { name: 'retained.pdf' };
|
||
h.attach(file);
|
||
h.render(
|
||
props({
|
||
technicalIncidents: [
|
||
{
|
||
reference: 'SYNTHETIC-REFERENCE',
|
||
operation: 'upload_document',
|
||
version: 4,
|
||
occurred_at: '2026-11-03',
|
||
error_code: 'database_failure',
|
||
},
|
||
],
|
||
}),
|
||
);
|
||
assert.match(text(h.tree), /Carregamento de documento/);
|
||
assert.equal(h.value(title), 'SYNTHETIC draft');
|
||
assert.equal(h.value(reasonLabel), 'SYNTHETIC retained reason');
|
||
assert.equal(h.submit().form.get('file'), file);
|
||
});
|