fix(statement): не отправлять поля шапки, равные текущим (I-2, #43)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BJKMLHdxMwSUeYcdkwqX4W
This commit is contained in:
Andrey Epifancev 2026-10-18 14:03:33 +04:00
parent 8d2deb97a3
commit 6556e3d58d
2 changed files with 20 additions and 2 deletions

View File

@ -116,7 +116,20 @@ describe('колонки', () => {
describe('шапка', () => {
it('organization_name обрезается', () => {
expect(bodyOf({ header: { organization_name: ' ООО Ромашка ' } })?.header).toEqual({ organization_name: 'ООО Ромашка' });
expect(bodyOf({ header: { organization_name: ' ООО Ромашка-2 ' } })?.header).toEqual({ organization_name: 'ООО Ромашка-2' });
});
it('значение, равное текущему (после обрезки), не отправляется', () => {
expect(bodyOf({ header: { organization_name: ' ООО Ромашка ' } })).toBeNull();
expect(bodyOf({ header: { inn: '7700000000', units: ' тыс. руб. ' } })).toBeNull();
});
it('введено и стёрто — тела нет', () => {
expect(bodyOf({ header: { inn: ' ', organization_name: '' } })).toBeNull();
});
it('дата из needs_review_fields с тем же значением — подтверждение, уходит', () => {
expect(bodyOf({ header: { report_date: '2025-09-30' } })?.header).toEqual({ report_date: '2025-09-30' });
const noReview = { rows, header: { ...statement.header, needs_review_fields: [] } };
const res = buildStatementPatch(draftOf({ header: { report_date: '2025-09-30' } }), noReview);
expect(res).toEqual({ ok: true, body: null });
});
it('длиннее 1000 символов — ошибка header', () => {
expect(errorsOf({ header: { organization_name: 'я'.repeat(1001) } })[0]).toMatchObject({ kind: 'header', key: 'organization_name' });

View File

@ -115,7 +115,12 @@ export function buildStatementPatch(
const header: NonNullable<StatementPatch['header']> = {};
for (const field of ['organization_name', 'inn', 'report_date', 'units'] as const) {
const text = draft.header[field]?.trim();
if (text) header[field] = text;
if (!text) continue;
const current = field === 'organization_name' ? ctx.header.organization_name : ctx.header[field].value;
// То же значение не шлём; исключение — дата из needs_review_fields: там то же значение и есть подтверждение (P6-11)
const confirmsDate = field === 'report_date' && (ctx.header.needs_review_fields ?? []).includes('report_date');
if (text === current?.trim() && !confirmsDate) continue;
header[field] = text;
}
if (draft.header.confirm_report_date && !header.report_date && ctx.header.report_date.value) {
header.report_date = ctx.header.report_date.value;