fix: add null type guards to buildRows to prevent crashes on missing types
This commit is contained in:
@@ -72,4 +72,32 @@ describe('buildRows', () => {
|
|||||||
const rows = buildRows(team() as any, '2026-08-01', '2026-08-31');
|
const rows = buildRows(team() as any, '2026-08-01', '2026-08-31');
|
||||||
expect(rows).toEqual([]);
|
expect(rows).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('skips transactions with null type and includes valid ones', () => {
|
||||||
|
const rows = buildRows(
|
||||||
|
team({
|
||||||
|
transactions: [
|
||||||
|
{ date: '2026-08-05T00:00:00.000Z', amount: 100, note: 'Valid credit', type: { name: 'credit' } },
|
||||||
|
{ date: '2026-08-06T00:00:00.000Z', amount: 50, note: 'Null type team wallet', type: null },
|
||||||
|
],
|
||||||
|
players: [
|
||||||
|
{
|
||||||
|
firstName: 'Bob',
|
||||||
|
lastName: 'Smith',
|
||||||
|
transactions: [
|
||||||
|
{ date: '2026-08-07T00:00:00.000Z', amount: 20, note: 'Valid payment', type: { name: 'payment' } },
|
||||||
|
{ date: '2026-08-08T00:00:00.000Z', amount: 30, note: 'Null type player', type: null },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}) as any,
|
||||||
|
'2026-08-01',
|
||||||
|
'2026-08-31',
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(rows).toEqual([
|
||||||
|
{ date: '2026-08-05T00:00:00.000Z', type: 'credit', who: 'Teamkasse', note: 'Valid credit', amount: 100, runningTotal: 100 },
|
||||||
|
{ date: '2026-08-07T00:00:00.000Z', type: 'payment', who: 'Bob Smith', note: 'Valid payment', amount: 20, runningTotal: 120 },
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ export function buildRows(team: Team, from: string, to: string): CashboxExportRo
|
|||||||
const raw: RawRow[] = [];
|
const raw: RawRow[] = [];
|
||||||
|
|
||||||
for (const transaction of team.transactions ?? []) {
|
for (const transaction of team.transactions ?? []) {
|
||||||
|
if (!transaction.type) continue;
|
||||||
raw.push({
|
raw.push({
|
||||||
date: transaction.date,
|
date: transaction.date,
|
||||||
type: transaction.type.name,
|
type: transaction.type.name,
|
||||||
@@ -35,7 +36,7 @@ export function buildRows(team: Team, from: string, to: string): CashboxExportRo
|
|||||||
|
|
||||||
for (const player of team.players ?? []) {
|
for (const player of team.players ?? []) {
|
||||||
for (const transaction of player.transactions ?? []) {
|
for (const transaction of player.transactions ?? []) {
|
||||||
if (transaction.type.name !== 'payment') continue;
|
if (!transaction.type || transaction.type.name !== 'payment') continue;
|
||||||
raw.push({
|
raw.push({
|
||||||
date: transaction.date,
|
date: transaction.date,
|
||||||
type: transaction.type.name,
|
type: transaction.type.name,
|
||||||
|
|||||||
Reference in New Issue
Block a user