Files
Investidor-V2/tests/frontend/technical-incident-notices.test.mjs
T

103 lines
3.6 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {
harness,
props,
reference,
text,
} from './helpers/technical-incident-handling.mjs';
const label = 'Marcar aviso como consultado',
retry = 'Repetir confirma\u00e7\u00e3o de consulta';
const initial = (patch = {}) => props({ notice: { unread: true }, ...patch });
const receipt = (patch = {}) => ({
actor_id: 1,
reference,
read: true,
...patch,
});
test('consultation acknowledgement sends once without a treatment command or another leave guard', async () => {
const h = harness(initial());
h.change('SYNTHETIC prepared treatment');
const req = h.click(label);
h.click(label);
assert.equal(h.sent.length, 1);
assert.equal(
req.url,
`/suporte-tecnico/incidentes/${reference}/consultado`,
);
assert.deepEqual(req.data, {});
await h.reply(receipt());
assert.equal(h.note, 'SYNTHETIC prepared treatment');
assert.match(text(h.tree), /Aviso consultado por si/);
assert.deepEqual(h.reloads[0].only, [
'incidents',
'profileAccess',
'notice',
]);
assert.equal(h.leave(), true);
assert.equal(h.confirmCalls, 1);
});
test('an uncertain read acknowledgement can be explicitly repeated with the same empty command', async () => {
const h = harness(initial());
const first = h.click(label);
await h.fail();
assert.ok(h.button(retry));
h.click(retry);
assert.equal(h.sent[1].url, first.url);
assert.deepEqual(h.sent[1].data, first.data);
await h.reply(receipt());
assert.equal(h.button(retry), undefined);
});
test('a receipt for another actor, root or read state cannot acknowledge this notice', async () => {
for (const patch of [
{ actor_id: 2 },
{ reference: 'other' },
{ read: false },
]) {
const h = harness(initial());
h.click(label);
await h.reply(receipt(patch));
assert.ok(h.button(retry));
assert.equal(h.reloads.length, 0);
}
});
test('late replies cannot change the notice or draft after changing accounts', async () => {
const h = harness(initial());
const old = h.click(label);
h.render(initial({ actorId: 2 }));
h.change('New actor treatment preparation');
await h.reply(receipt(), old);
assert.ok(h.button(label));
assert.equal(h.note, 'New actor treatment preparation');
assert.equal(h.reloads.length, 0);
});
test('a refreshed own acknowledgement wins over a late failed POST and older unread props', async () => {
const h = harness(initial());
const old = h.click(label);
h.render(initial({ notice: { unread: false } }));
await h.fail(null, old);
assert.match(text(h.tree), /Aviso consultado por si/);
assert.doesNotMatch(text(h.tree), /poss\u00edvel confirmar/);
h.render(initial());
assert.equal(h.button(label), undefined);
assert.equal(h.button(retry), undefined);
});
test('known acknowledgement remains confirmed if the subsequent preview has no response', async () => {
const h = harness(initial());
h.click(label);
await h.reply(receipt());
assert.equal(h.sent.length, 1);
assert.equal(h.button(label), undefined);
assert.equal(h.leave(), false);
assert.equal(h.confirmCalls, 0);
});
test('revoked access preserves the treatment preparation and exposes no server exception text', async () => {
const h = harness(initial());
h.change('PRIVATE SYNTHETIC treatment draft');
h.click(label);
await h.fail(403);
assert.equal(h.note, 'PRIVATE SYNTHETIC treatment draft');
assert.ok(h.button(retry));
assert.doesNotMatch(text(h.tree), /SYNTHETIC HTTP/);
});