فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A04): assert late financial validation rolls back all native company restore writes
davoodmehraban89 committed
Oct 16, 2026 at 21:40 UTC
8073a8f5f2ddd3abd150c727ffa885d8342835d1
1 file changed
+63
tests/windows-vm-encrypted-company-backup-browser.js
+63
@@ -164,11 +164,74 @@
164
if (!audits.length) {
165
throw Error('Company restore did not create a corresponding audit event');
166
}
167
+ // A04 late-validation rollback: the first contact and a fake posted sale
168
+ // are staged INSIDE the same real IndexedDB transaction. Validation of the
169
+ // nonexistent posted journal must abort the entire transaction, including
170
+ // the earlier contact write and any audit receipt.
171
+ const rollbackContactId = 'vm-only-late-rollback-contact';
172
+ const rollbackInvoiceId = 'vm-only-late-rollback-invoice';
173
+ const auditCountBeforeLateRollback = (await store.getAll('audit_events')).length;
174
+ const corruptFinancialSnapshot = {
175
+ app: 'Factor-easyPro',
176
+ scope: 'company',
177
+ schemaVersion: 7,
178
+ companyId: company.id,
179
+ data: {
180
+ contacts: [{
181
+ id: rollbackContactId,
182
+ companyId: company.id,
183
+ ownerUserId: actor.id,
184
+ name: 'VM-ONLY aborted restore record'
185
+ }],
186
+ invoices: [{
187
+ id: rollbackInvoiceId,
188
+ companyId: company.id,
189
+ kind: 'sale',
190
+ financePosted: true,
191
+ journalId: 'vm-only-nonexistent-posted-journal',
192
+ grandTotal: 1000
193
+ }]
194
+ }
195
+ };
196
+ restoreFile(JSON.stringify(corruptFinancialSnapshot));
197
+ await window.SettingsView.restoreBackup();
198
+ if (await store.get('contacts', rollbackContactId) ||
199
+ await store.get('invoices', rollbackInvoiceId)) {
200
+ throw Error('Late ledger validation failed to roll back all staged rows');
201
+ }
202
+ if ((await store.getAll('audit_events')).length !== auditCountBeforeLateRollback) {
203
+ throw Error('Aborted restore incorrectly committed an audit receipt');
204
+ }
205
+ if ((await store.get('contacts', contactId))?.name !== synthetic) {
206
+ throw Error('Aborted restore modified an existing recovered contact');
207
+ }
208
+ const validationMessage = 'ارجاع دفتر کل سند مالی بازیابیشده نامعتبر است';
209
+ if (capturedErrors.length !== 3 ||
210
+ !capturedErrors[2].includes(validationMessage)) {
211
+ throw Error('Late validation failure was not exposed through Settings UI');
212
+ }
213
+ const rollbackToasts = [...document.querySelectorAll('.toast-error')];
214
+ if (rollbackToasts.length !== 1 ||
215
+ !rollbackToasts[0].textContent.includes(validationMessage)) {
216
+ throw Error('Late validation did not show exactly one expected error');
217
+ }
218
+ const rollbackDismiss = rollbackToasts[0].querySelector('.toast-close');
219
+ if (!rollbackDismiss) throw Error('Late validation error cannot be dismissed');
220
+ rollbackDismiss.click();
221
+ if (document.querySelector('.toast-error') || !document.getElementById('restoreFile')) {
222
+ throw Error('Late rollback left an unexpected error or closed its form');
223
+ }
224
+ FINORA.Modal.close();
225
+ if (document.querySelector('.modal-backdrop')) {
226
+ throw Error('Aborted restore form remained open');
227
+ }
228
+
229
return {
230
encryptedEnvelope: true,
231
filenameSuffix: '.fbackup',
232
wrongPasswordRejected: true,
233
tamperedCiphertextRejectedWithoutWrites: true,
234
+ lateFinancialValidationRolledBack: true,
235
sameCompanyRestore: true,
236
restoredContact: true,
237
restoreAudited: true,