Simplify saved register reads and tests #84
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@hledger-reports/web': patch
|
||||
---
|
||||
|
||||
Carry validated account access and row counts through saved register reads so readers do not repeat those checks. Browsing behavior and the saved report format are unchanged.
|
||||
@@ -2,13 +2,11 @@ import type { AccountConfig } from '@hledger-reports/config';
|
||||
import {
|
||||
readAccountPage,
|
||||
readAccountTransaction,
|
||||
readReportPublication
|
||||
readReportPublication,
|
||||
type StoredAccount
|
||||
} from '@hledger-reports/snapshots';
|
||||
import { beforeEach, expect, it, vi } from 'vitest';
|
||||
import {
|
||||
preparedAccountRows,
|
||||
preparedOverview
|
||||
} from '../../../../../../../packages/db/src/reports/data.fixture.js';
|
||||
import { preparedAccountRows } from '../../../../../../../packages/db/src/reports/data.fixture.js';
|
||||
import { testConfig } from '#lib/server/application.fixture.js';
|
||||
import { savedReportFixture } from '#lib/server/reports.fixture.js';
|
||||
import { readRowBatch, readTransactionDetails } from './register.js';
|
||||
@@ -25,16 +23,22 @@ vi.mock('@hledger-reports/hledger', () => {
|
||||
const accountId = 'abcd1234';
|
||||
const name = 'assets:cash';
|
||||
const request = { accountId, transactionIndex: 7 };
|
||||
const readyAccount = {
|
||||
id: accountId,
|
||||
name,
|
||||
access: 'ready',
|
||||
rowCount: 1,
|
||||
summary: { status: 'undated' }
|
||||
} satisfies StoredAccount;
|
||||
const publication = savedReportFixture({
|
||||
journal: testConfig.journal,
|
||||
accounts: [{ id: accountId, name, access: 'ready', rowCount: 1, summary: { status: 'undated' } }],
|
||||
overview: preparedOverview()
|
||||
accounts: [readyAccount]
|
||||
});
|
||||
const row = preparedAccountRows(1, 'Fictional payee', request.transactionIndex)[0];
|
||||
const batchRequest = { accountId, order: 'desc' as const, batchStart: 250 };
|
||||
const batchPublication = savedReportFixture({
|
||||
...publication,
|
||||
accounts: publication.accounts.map((account) => ({ ...account, rowCount: 500 }))
|
||||
accounts: [{ ...readyAccount, rowCount: 500 }]
|
||||
});
|
||||
|
||||
function locals(
|
||||
|
||||
@@ -3,13 +3,11 @@ import {
|
||||
readInvestmentActivityCount,
|
||||
readInvestmentActivityPage,
|
||||
readReportPublication,
|
||||
type AccountInvestmentActivityPage
|
||||
type AccountInvestmentActivityPage,
|
||||
type StoredAccount
|
||||
} from '@hledger-reports/snapshots';
|
||||
import { beforeEach, expect, it, vi } from 'vitest';
|
||||
import {
|
||||
preparedAccountRows,
|
||||
preparedOverview
|
||||
} from '../../../../../../../packages/db/src/reports/data.fixture.js';
|
||||
import { preparedAccountRows } from '../../../../../../../packages/db/src/reports/data.fixture.js';
|
||||
import { testConfig } from '#lib/server/application.fixture.js';
|
||||
import { savedReportFixture } from '#lib/server/reports.fixture.js';
|
||||
import type { RegisterLocals } from '../account-access.js';
|
||||
@@ -27,10 +25,16 @@ vi.mock('@hledger-reports/hledger', () => {
|
||||
const accountId = 'abcd1234';
|
||||
const name = 'assets:cash';
|
||||
const request = { accountId, order: 'desc' as const, batchStart: 50 };
|
||||
const readyAccount = {
|
||||
id: accountId,
|
||||
name,
|
||||
access: 'ready',
|
||||
rowCount: 1,
|
||||
summary: { status: 'undated' }
|
||||
} satisfies StoredAccount;
|
||||
const publication = savedReportFixture({
|
||||
journal: testConfig.journal,
|
||||
accounts: [{ id: accountId, name, access: 'ready', rowCount: 1, summary: { status: 'undated' } }],
|
||||
overview: preparedOverview()
|
||||
accounts: [readyAccount]
|
||||
});
|
||||
const row = preparedAccountRows(1, 'Fictional payee', 7)[0];
|
||||
const selectedPosting = row.transaction.postings[0];
|
||||
@@ -174,7 +178,7 @@ it('rejects a start past the saved posting count without another count read', as
|
||||
it('permits only batch zero for empty accounts and checks the saved page', async () => {
|
||||
vi.mocked(readReportPublication).mockResolvedValue({
|
||||
...publication,
|
||||
accounts: publication.accounts.map((account) => ({ ...account, rowCount: 0 }))
|
||||
accounts: [{ ...readyAccount, rowCount: 0 }]
|
||||
});
|
||||
vi.mocked(readInvestmentActivityPage).mockResolvedValue({
|
||||
...page,
|
||||
@@ -211,7 +215,7 @@ it('sanitizes missing, foreign and unreadable publications before activity reads
|
||||
it('reports a saved count read failure for a declared-empty account', async () => {
|
||||
vi.mocked(readReportPublication).mockResolvedValue({
|
||||
...publication,
|
||||
accounts: publication.accounts.map((account) => ({ ...account, rowCount: 0 }))
|
||||
accounts: [{ ...readyAccount, rowCount: 0 }]
|
||||
});
|
||||
vi.mocked(readInvestmentActivityCount).mockRejectedValue(
|
||||
new Error('Unable to read account activity')
|
||||
|
||||
@@ -25,6 +25,5 @@ export function selectPreparedAccount(
|
||||
if (!stored) error(404, 'Account not found in the prepared reports.');
|
||||
const account = { publication, id: stored.id, name: stored.name };
|
||||
if (stored.access === 'ambiguous') return { ...account, access: 'ambiguous' };
|
||||
// The validated publication catalog only permits a null count for ambiguous accounts.
|
||||
return { ...account, access: 'ready', rowCount: stored.rowCount! };
|
||||
return { ...account, access: 'ready', rowCount: stored.rowCount };
|
||||
}
|
||||
@@ -171,26 +171,29 @@ export const preparedAccountRowsFromExports = (
|
||||
)
|
||||
})
|
||||
);
|
||||
export const ready = (name = 'assets:cash', rowCount = 1): PreparedAccountSummary => ({
|
||||
name,
|
||||
access: 'ready',
|
||||
rowCount,
|
||||
summary: {
|
||||
status: 'ready',
|
||||
balances: rowCount === 0 ? [] : [{ commodity: 'TEST', quantity: '2.000' }],
|
||||
valuation: {
|
||||
amounts: rowCount === 0 ? [] : [{ commodity: 'TEST', quantity: '2.000' }],
|
||||
unconverted: rowCount === 0 ? [] : ['TEST']
|
||||
export const ready = (name = 'assets:cash', rowCount = 1) =>
|
||||
({
|
||||
name,
|
||||
access: 'ready',
|
||||
rowCount,
|
||||
summary: {
|
||||
status: 'ready',
|
||||
balances: rowCount === 0 ? [] : [{ commodity: 'TEST', quantity: '2.000' }],
|
||||
valuation: {
|
||||
amounts: rowCount === 0 ? [] : [{ commodity: 'TEST', quantity: '2.000' }],
|
||||
unconverted: rowCount === 0 ? [] : ['TEST']
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
export const ambiguous = (name = 'ambiguous'): PreparedAccountSummary => ({
|
||||
name,
|
||||
access: 'ambiguous',
|
||||
rowCount: null,
|
||||
summary: { status: 'ambiguous' }
|
||||
});
|
||||
export const undated = (name: string): PreparedAccountSummary => ({
|
||||
...ready(name, 0),
|
||||
summary: { status: 'undated' }
|
||||
});
|
||||
}) satisfies PreparedAccountSummary;
|
||||
export const ambiguous = (name = 'ambiguous') =>
|
||||
({
|
||||
name,
|
||||
access: 'ambiguous',
|
||||
rowCount: null,
|
||||
summary: { status: 'ambiguous' }
|
||||
}) satisfies PreparedAccountSummary;
|
||||
export const undated = (name: string) =>
|
||||
({
|
||||
...ready(name, 0),
|
||||
summary: { status: 'undated' }
|
||||
}) satisfies PreparedAccountSummary;
|
||||
@@ -1,21 +1,27 @@
|
||||
import type {
|
||||
OverviewData,
|
||||
PreparedAccountSummary,
|
||||
PreparedAccountRow,
|
||||
PreparedBalance
|
||||
} from '@hledger-reports/hledger';
|
||||
import type { OverviewData, PreparedAccountRow, PreparedBalance } from '@hledger-reports/hledger';
|
||||
|
||||
const accountIdPattern = /^[a-z0-9]{8}(?![\s\S])/;
|
||||
|
||||
export interface StoredAccount {
|
||||
id: string;
|
||||
interface SavedAccountDetails {
|
||||
name: string;
|
||||
access: 'ready' | 'ambiguous';
|
||||
rowCount: number | null;
|
||||
/** Native balance and valuation at the saved overview's as-of date. */
|
||||
summary: PreparedBalance;
|
||||
}
|
||||
|
||||
interface ReadyAccountSummary extends SavedAccountDetails {
|
||||
access: 'ready';
|
||||
rowCount: number;
|
||||
}
|
||||
|
||||
interface AmbiguousAccountSummary extends SavedAccountDetails {
|
||||
access: 'ambiguous';
|
||||
rowCount: null;
|
||||
}
|
||||
|
||||
type SavedAccountSummary = ReadyAccountSummary | AmbiguousAccountSummary;
|
||||
|
||||
export type StoredAccount = SavedAccountSummary & { id: string };
|
||||
|
||||
export interface StoredReportData {
|
||||
overview: OverviewData;
|
||||
/** Private journal identity; never expose this in page data. */
|
||||
@@ -118,7 +124,10 @@ type AccountContext = Pick<
|
||||
'isSplit' | 'otherAccounts' | 'change' | 'balance' | 'accountPostingIndexes' | 'investment'
|
||||
>;
|
||||
|
||||
export function hasAccountContextContainers(value: unknown): value is AccountContext {
|
||||
export function hasAccountContextForPostings(
|
||||
value: unknown,
|
||||
postingCount: number
|
||||
): value is AccountContext {
|
||||
return (
|
||||
isObject(value) &&
|
||||
typeof value.isSplit === 'boolean' &&
|
||||
@@ -127,6 +136,9 @@ export function hasAccountContextContainers(value: unknown): value is AccountCon
|
||||
Array.isArray(value.change) &&
|
||||
Array.isArray(value.balance) &&
|
||||
Array.isArray(value.accountPostingIndexes) &&
|
||||
value.accountPostingIndexes.every(
|
||||
(index) => Number.isSafeInteger(index) && index >= 0 && index < postingCount
|
||||
) &&
|
||||
isObject(value.investment) &&
|
||||
Array.isArray(value.investment.securities) &&
|
||||
isObject(value.investment.cash) &&
|
||||
@@ -157,16 +169,10 @@ export function hasAccountRowContainers(value: unknown): value is PreparedAccoun
|
||||
)
|
||||
)
|
||||
return false;
|
||||
const postingCount = value.transaction.postings.length;
|
||||
return (
|
||||
hasAccountContextContainers(value) &&
|
||||
value.accountPostingIndexes.every(
|
||||
(index) => Number.isSafeInteger(index) && index >= 0 && index < postingCount
|
||||
)
|
||||
);
|
||||
return hasAccountContextForPostings(value, value.transaction.postings.length);
|
||||
}
|
||||
|
||||
export function isAccountSummary(value: unknown): value is PreparedAccountSummary {
|
||||
export function isStorableAccountSummary(value: unknown): value is SavedAccountSummary {
|
||||
if (!isObject(value) || typeof value.name !== 'string' || !isObject(value.summary)) return false;
|
||||
if (value.access === 'ambiguous')
|
||||
return value.rowCount === null && value.summary.status === 'ambiguous';
|
||||
@@ -185,7 +191,7 @@ export function isAccountSummary(value: unknown): value is PreparedAccountSummar
|
||||
);
|
||||
}
|
||||
|
||||
export function summaryMatchesDate(account: PreparedAccountSummary, asOf: string | null): boolean {
|
||||
export function summaryMatchesDate(account: SavedAccountSummary, asOf: string | null): boolean {
|
||||
if (account.access === 'ambiguous') return account.summary.status === 'ambiguous';
|
||||
return account.summary.status === (asOf === null ? 'undated' : 'ready');
|
||||
}
|
||||
@@ -207,7 +213,8 @@ export function isAccountCatalog(value: unknown): value is StoredAccount[] {
|
||||
const names = new Set<string>();
|
||||
const ids = new Set<string>();
|
||||
for (const account of value) {
|
||||
if (!isAccountSummary(account) || !('id' in account) || !isAccountId(account.id)) return false;
|
||||
if (!isStorableAccountSummary(account) || !('id' in account) || !isAccountId(account.id))
|
||||
return false;
|
||||
if (names.has(account.name) || ids.has(account.id)) return false;
|
||||
names.add(account.name);
|
||||
ids.add(account.id);
|
||||
|
||||
@@ -4,7 +4,7 @@ export {
|
||||
hasStoredReportData,
|
||||
isAccountCatalog,
|
||||
isAccountId,
|
||||
isAccountSummary,
|
||||
isStorableAccountSummary,
|
||||
isObject,
|
||||
storedSummary,
|
||||
summaryMatchesDate
|
||||
|
||||
@@ -409,10 +409,31 @@ it('reads date-ordered pages with native ties and exact account scope', async ()
|
||||
);
|
||||
});
|
||||
|
||||
it('decodes only the requested page and rejects invalid posting references', async () => {
|
||||
it('decodes only the requested page and rejects damaged saved row contexts', async () => {
|
||||
const database = await createDatabase();
|
||||
const exports = accountTransactionExportsFixture(51);
|
||||
const secondPageOffset = 50;
|
||||
const invalidPostingOrdinal = secondPageOffset;
|
||||
const malformedContextOrdinal = secondPageOffset + 1;
|
||||
const exports = accountTransactionExportsFixture(malformedContextOrdinal + 1);
|
||||
const nativeEntry = JSON.parse(exports[0].originalJson);
|
||||
const [cashPosting, ...counterpartPostings] = nativeEntry.tpostings;
|
||||
const conversionPosting = {
|
||||
...cashPosting,
|
||||
paccount: 'equity:conversion',
|
||||
ptags: [['_conversion-posting', '']]
|
||||
};
|
||||
const transactedPostings = [...counterpartPostings, cashPosting];
|
||||
const originalPostings = [conversionPosting, ...transactedPostings];
|
||||
exports[0] = {
|
||||
originalJson: JSON.stringify({ ...nativeEntry, tpostings: originalPostings }),
|
||||
transactedJson: JSON.stringify({ ...nativeEntry, tpostings: transactedPostings })
|
||||
};
|
||||
const rows = preparedAccountRowsFromExports(exports);
|
||||
const cashPostingIndex = originalPostings.indexOf(cashPosting);
|
||||
rows[0].accountPostingIndexes = [cashPostingIndex];
|
||||
rows[0].investment.cashPostingIndexes = [cashPostingIndex];
|
||||
const invalidPostingRow = rows[invalidPostingOrdinal];
|
||||
const invalidPostingIndexes = [invalidPostingRow.transaction.postings.length];
|
||||
const account = { id: 'cash0001', ...ready('assets:cash', rows.length) };
|
||||
await writeReportData(database, { journal, overview: preparedOverview(), accounts: [account] });
|
||||
await writeAccountActivitySummaries(
|
||||
@@ -422,6 +443,11 @@ it('decodes only the requested page and rejects invalid posting references', asy
|
||||
const transaction = await database.startTransaction().execute();
|
||||
try {
|
||||
await importTransactions(transaction, exports);
|
||||
await expect(
|
||||
writeAccountRows(transaction, account.name, invalidPostingOrdinal, [
|
||||
{ ...invalidPostingRow, accountPostingIndexes: invalidPostingIndexes }
|
||||
])
|
||||
).rejects.toThrow('Invalid account rows.');
|
||||
await writeAccountRows(transaction, account.name, 0, rows);
|
||||
await writeRegisterRowsAndPostingCount(transaction, account.name, rows.length);
|
||||
await transaction.commit().execute();
|
||||
@@ -434,18 +460,16 @@ it('decodes only the requested page and rejects invalid posting references', asy
|
||||
// Valid SQLite/JSON is not sufficient: saved posting references must still be usable.
|
||||
const native = new DatabaseSync(path);
|
||||
try {
|
||||
const saved = native
|
||||
.prepare('SELECT context_json FROM account_activity WHERE ordinal = 50')
|
||||
.get();
|
||||
const badContext = {
|
||||
...JSON.parse(String(saved!.context_json)),
|
||||
accountPostingIndexes: [rows[50].transaction.postings.length]
|
||||
};
|
||||
native
|
||||
.prepare(
|
||||
'UPDATE account_activity SET context_json = ? WHERE account_name = ? AND ordinal = 50'
|
||||
"UPDATE account_activity SET context_json = json_set(context_json, '$.accountPostingIndexes', json(?)) WHERE account_name = ? AND ordinal = ?"
|
||||
)
|
||||
.run(JSON.stringify(badContext), account.name);
|
||||
.run(JSON.stringify(invalidPostingIndexes), account.name, invalidPostingOrdinal);
|
||||
native
|
||||
.prepare(
|
||||
"UPDATE account_activity SET context_json = json_set(context_json, '$.otherAccounts', 'not an array') WHERE account_name = ? AND ordinal = ?"
|
||||
)
|
||||
.run(account.name, malformedContextOrdinal);
|
||||
} finally {
|
||||
native.close();
|
||||
}
|
||||
@@ -454,10 +478,17 @@ it('decodes only the requested page and rejects invalid posting references', asy
|
||||
databases.add(reader);
|
||||
expect((await readReportData(reader)).accounts).toEqual([account]);
|
||||
expect(await readCashRegisterPage(reader, account, 'asc', 0)).toEqual({
|
||||
rows: rows.slice(0, 50),
|
||||
rows: rows.slice(0, secondPageOffset),
|
||||
summary: preparedActivitySummary(rows)
|
||||
});
|
||||
await expect(readCashRegisterPage(reader, account, 'asc', 50)).rejects.toThrow();
|
||||
await expect(readCashRegisterPage(reader, account, 'asc', secondPageOffset)).rejects.toThrow(
|
||||
'Invalid account data.'
|
||||
);
|
||||
for (const ordinal of [invalidPostingOrdinal, malformedContextOrdinal]) {
|
||||
await expect(
|
||||
readAccountActivityDetail(reader, account, rows[ordinal].transaction.index)
|
||||
).rejects.toThrow('Invalid account data.');
|
||||
}
|
||||
});
|
||||
|
||||
it('rejects an orphaned Cash row without shifting later rows', async () => {
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
type AccountActivitySummary
|
||||
} from './account-activity-summary.js';
|
||||
import {
|
||||
hasAccountContextContainers,
|
||||
hasAccountContextForPostings,
|
||||
hasAccountRowContainers,
|
||||
hasStoredReportData,
|
||||
type StoredAccount,
|
||||
@@ -236,6 +236,7 @@ function decodeAccountRow(record: StoredActivityRow, rowCount: number): Prepared
|
||||
!Number.isSafeInteger(record.ordinal) ||
|
||||
record.ordinal < 0 ||
|
||||
record.ordinal >= rowCount ||
|
||||
typeof record.account_date !== 'string' ||
|
||||
!Number.isSafeInteger(record.native_transaction_index) ||
|
||||
record.native_transaction_index <= 0 ||
|
||||
record.canonical_native_index !== record.native_transaction_index ||
|
||||
@@ -244,7 +245,6 @@ function decodeAccountRow(record: StoredActivityRow, rowCount: number): Prepared
|
||||
)
|
||||
throw new Error('Invalid account data.');
|
||||
const context = decodePayload(record.context_json);
|
||||
if (!hasAccountContextContainers(context)) throw new Error('Invalid account data.');
|
||||
const original = decodeNativeTransaction(record.original_json);
|
||||
const transacted = decodeNativeTransaction(record.transacted_json);
|
||||
if (
|
||||
@@ -252,7 +252,10 @@ function decodeAccountRow(record: StoredActivityRow, rowCount: number): Prepared
|
||||
transacted.tindex !== record.native_transaction_index
|
||||
)
|
||||
throw new Error('Invalid account data.');
|
||||
const row = {
|
||||
const transaction = prepareTransaction(original, transacted);
|
||||
if (!hasAccountContextForPostings(context, transaction.postings.length))
|
||||
throw new Error('Invalid account data.');
|
||||
return {
|
||||
accountDate: record.account_date,
|
||||
isSplit: context.isSplit,
|
||||
otherAccounts: context.otherAccounts,
|
||||
@@ -260,10 +263,8 @@ function decodeAccountRow(record: StoredActivityRow, rowCount: number): Prepared
|
||||
balance: context.balance,
|
||||
accountPostingIndexes: context.accountPostingIndexes,
|
||||
investment: context.investment,
|
||||
transaction: prepareTransaction(original, transacted)
|
||||
transaction
|
||||
};
|
||||
if (!hasAccountRowContainers(row)) throw new Error('Invalid account data.');
|
||||
return row;
|
||||
}
|
||||
|
||||
function decodeActivitySummary(
|
||||
@@ -316,24 +317,13 @@ export async function readAccountActivityDetail(
|
||||
if (!Number.isSafeInteger(nativeIndex) || nativeIndex <= 0)
|
||||
throw new Error('Invalid account transaction.');
|
||||
await assertStoredAccount(database, account);
|
||||
if (account.access === 'ambiguous') {
|
||||
if (account.rowCount !== null) throw new Error('Invalid account data.');
|
||||
return null;
|
||||
}
|
||||
const rowCount = account.rowCount;
|
||||
if (
|
||||
account.access !== 'ready' ||
|
||||
rowCount === null ||
|
||||
!Number.isSafeInteger(rowCount) ||
|
||||
rowCount < 0
|
||||
)
|
||||
throw new Error('Invalid account data.');
|
||||
if (account.access === 'ambiguous') return null;
|
||||
const record = await selectAccountRowsWithTransactions(database)
|
||||
.where('account_activity.account_name', '=', account.name)
|
||||
.where('account_activity.native_transaction_index', '=', nativeIndex)
|
||||
.limit(1)
|
||||
.executeTakeFirst();
|
||||
return record ? decodeAccountRow(record, rowCount) : null;
|
||||
return record ? decodeAccountRow(record, account.rowCount) : null;
|
||||
}
|
||||
|
||||
async function readAccountPageContext(
|
||||
@@ -351,7 +341,7 @@ async function readAccountPageContext(
|
||||
.where('account_name', '=', account.name)
|
||||
.executeTakeFirst();
|
||||
if (account.access === 'ambiguous') {
|
||||
if (account.rowCount !== null || storedSummary) throw new Error('Invalid account activity.');
|
||||
if (storedSummary) throw new Error('Invalid account activity.');
|
||||
const activity = await database
|
||||
.selectFrom('account_activity')
|
||||
.select('ordinal')
|
||||
@@ -361,17 +351,9 @@ async function readAccountPageContext(
|
||||
if (activity) throw new Error('Invalid account data.');
|
||||
return null;
|
||||
}
|
||||
const rowCount = account.rowCount;
|
||||
if (
|
||||
account.access !== 'ready' ||
|
||||
rowCount === null ||
|
||||
!Number.isSafeInteger(rowCount) ||
|
||||
rowCount < 0
|
||||
)
|
||||
throw new Error('Invalid account data.');
|
||||
if (!storedSummary) throw new Error('Missing account activity summary.');
|
||||
return {
|
||||
rowCount,
|
||||
rowCount: account.rowCount,
|
||||
postingRowCount: storedSummary.posting_row_count,
|
||||
summary: decodeActivitySummary(storedSummary)
|
||||
};
|
||||
|
||||
@@ -712,6 +712,13 @@ it('distinguishes empty-ready accounts from ambiguous access without requiring e
|
||||
{ account_name: 'empty callback', posting_row_count: 0 }
|
||||
]);
|
||||
const publication = await selected();
|
||||
expect(
|
||||
publication.accounts.map(({ name, access, rowCount }) => ({ name, access, rowCount }))
|
||||
).toEqual([
|
||||
{ name: 'empty', access: 'ready', rowCount: 0 },
|
||||
{ name: 'empty callback', access: 'ready', rowCount: 0 },
|
||||
{ name: 'ambiguous', access: 'ambiguous', rowCount: null }
|
||||
]);
|
||||
for (const account of publication.accounts) {
|
||||
const page = await readAccountPage(publication, account.id, {
|
||||
order: 'asc',
|
||||
@@ -905,14 +912,25 @@ it('keeps the stage until a failed connection close can be retried', async () =>
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ condition: 'incorrect row counts', summary: ready('assets:cash', 2) },
|
||||
{ condition: 'written rows declared ambiguous', summary: ambiguous('assets:cash') }
|
||||
])('rejects $condition without replacing the saved report', async ({ summary }) => {
|
||||
{ condition: 'incorrect row counts', summary: ready('assets:cash', 2), writeActivity: true },
|
||||
{
|
||||
condition: 'written rows declared ambiguous',
|
||||
summary: ambiguous('assets:cash'),
|
||||
writeActivity: true
|
||||
},
|
||||
{
|
||||
condition: 'an ambiguous account declaring a numeric count',
|
||||
summary: { ...ambiguous('assets:cash'), rowCount: 0 },
|
||||
writeActivity: false
|
||||
}
|
||||
])('rejects $condition without replacing the saved report', async ({ summary, writeActivity }) => {
|
||||
await publish();
|
||||
const pinned = await selected();
|
||||
const stage = await createReportStage(snapshots, newer, pinned.accounts);
|
||||
await importNativeExports(stage);
|
||||
await stage.writeRows('assets:cash', rows());
|
||||
if (writeActivity) {
|
||||
await importNativeExports(stage);
|
||||
await stage.writeRows('assets:cash', rows());
|
||||
}
|
||||
await expect(stage.publish(fixture(), [summary], journal)).rejects.toSatisfy(
|
||||
safeError('Unable to prepare reports')
|
||||
);
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
hasOverviewContainers,
|
||||
isAccountCatalog,
|
||||
isAccountId,
|
||||
isAccountSummary,
|
||||
isStorableAccountSummary,
|
||||
findRegisterFocusLocation,
|
||||
readCashRegisterPage,
|
||||
readAccountActivityDetail,
|
||||
@@ -478,7 +478,7 @@ export async function createReportStage(
|
||||
const activitySummaries = new Map<string, AccountActivitySummary>();
|
||||
for (const account of accounts) {
|
||||
if (
|
||||
!isAccountSummary(account) ||
|
||||
!isStorableAccountSummary(account) ||
|
||||
!summaryMatchesDate(account, overview.asOf) ||
|
||||
names.has(account.name)
|
||||
)
|
||||
@@ -495,10 +495,8 @@ export async function createReportStage(
|
||||
activitySummaries.set(account.name, summaryBuilder.build());
|
||||
}
|
||||
catalog.push({
|
||||
...account,
|
||||
id: writtenAccount?.id ?? accountId(account.name),
|
||||
name: account.name,
|
||||
access: account.access,
|
||||
rowCount: account.rowCount,
|
||||
summary: storedSummary(account.summary)
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user