mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 08:53:13 +00:00
fix(costs): read an expense entered in the display currency as it was typed (#2525)
A euro trip read in dollars books a bill entered in dollars at the rate of the day, from the euro's quote: 12,345.67 USD at 1.1398 is 10,831.44 EUR. The Costs screen and the settlement then turned those euros back into dollars with the dollar's own quote, 1 / 0.87732. Frankfurter rounds the two quotes separately, so they are not exact inverses, and the bill read $12,346.05 the moment it was saved, a $250.00 one $250.01. The error grows with the amount, which is why the large rows showed it first. Paying back what settle-up offered for such a bill left the trip open with the debt flipped the other way. Both sides now convert trip money to the display currency with the trip currency's own quote, the one every entry rate is frozen from. On the server, settlement() fetches that quote for the REST route and for the MCP get_settlement_summary tool, which now makes the same call, and a legacy transfer without a currency reads back through the same factor. On the client, useExchangeRates takes the trip currency as an anchor and converts through its cached quote, falling back to the display currency's while it is missing, so it works offline from cache and needs no change to the settlement response. The final budget builds each row from the unrounded trip amount, because a euro cent is worth more than a dollar cent and 10,831.44 EUR came back as 12,345.68; the balances and settle-up still net whole trip cents. A same-day bill in the display currency now reads exactly as typed on the row, the payer chip, the day header, the totals, Outstanding and the final budget, on both shells and on the shared trip page, and paying the amount settle-up offers leaves both balances at zero. When the rate really moved, the row keeps the value the totals count, with what was entered and the euros it was booked at underneath, "$801.76 -> 685,26 EUR". One helper builds that line for the desktop list, the phone list, payments, the final budget breakdown and the shared page; it prints nothing for an amount of 0 or a bill that reads as typed. The expense editors share one module for their preview. The split summary puts the share the row lends or borrows next to the entered one, "$400.88 -> $390.53 each", and an expense saved without a currency still opens in the trip currency. Both CSV exports add the amount in the trip currency when it differs from the display currency. Kept from before: the desktop totals recompute when rates arrive, a booking's linked costs are labelled in the trip currency (every linked row, the link picker and the phone's linked costs), a legacy transfer is read in the display currency, the shared page reads the frozen rate in whole cents, a booking import keeps the currency it was quoted in at a rate frozen before the write (REST and plugin RPC), and the MCP trip summary, the budget-overview prompt and the per-person summary add every row up in trip cents at its frozen rate. The packing-list prompt reads the trip title directly instead of building the whole summary, which could wait on a rates fetch.
This commit is contained in:
@@ -4,10 +4,10 @@ import type { TripMember } from '../../../../src/components/Budget/BudgetPanelMe
|
||||
import { clearExchangeRateCache } from '../../../../src/hooks/useExchangeRates'
|
||||
import { useTripStore, type TripStoreState } from '../../../../src/store/tripStore'
|
||||
import type { BudgetItem, BudgetItemMember } from '../../../../src/types'
|
||||
import { buildBudgetItem } from '../../../helpers/factories'
|
||||
import { buildBudgetItem, buildTrip } from '../../../helpers/factories'
|
||||
import { localToday } from '../../../../src/components/Planner/today'
|
||||
import { resetAllStores } from '../../../helpers/store'
|
||||
import { act, fireEvent, render, screen, waitFor } from '../../../helpers/render'
|
||||
import { act, fireEvent, render, screen, waitFor, within } from '../../../helpers/render'
|
||||
|
||||
// FE-MOB-COSTSH-001 to FE-MOB-COSTSH-030
|
||||
// The sheet reads its copy from useTranslation(), so assertions are English.
|
||||
@@ -648,6 +648,66 @@ describe('MCostSheet', () => {
|
||||
})))
|
||||
})
|
||||
|
||||
it('FE-MOB-COSTSH-035: an expense saved without a currency reopens in the trip currency (#2525)', async () => {
|
||||
// No currency on the row means the trip's own. Seeding the display currency
|
||||
// instead labelled 100 euro as 100 dollars, and a plain save stored it so.
|
||||
localStorage.setItem('trek_fx_USD', JSON.stringify({ rates: { USD: 1, EUR: 0.8 }, ts: Date.now() }))
|
||||
useTripStore.setState({ trip: buildTrip({ id: 1, currency: 'EUR' }) } as unknown as Partial<TripStoreState>)
|
||||
const editing = buildBudgetItem({
|
||||
id: 12, name: 'Tram pass', category: 'transport', currency: null, total_price: 100,
|
||||
members: [member(1, null)],
|
||||
payers: [{ user_id: 1, amount: 100 }],
|
||||
})
|
||||
renderSheet({ base: 'USD', editing })
|
||||
|
||||
expect(totalField()).toHaveValue('100,00')
|
||||
expect(screen.getByRole('button', { name: 'EUR €' })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'USD $' })).toBeNull()
|
||||
|
||||
fireEvent.click(saveBtn())
|
||||
await waitFor(() => expect(updateBudgetItem).toHaveBeenCalledWith(1, 12, expect.objectContaining({
|
||||
total_price: 100,
|
||||
currency: 'EUR',
|
||||
})))
|
||||
})
|
||||
|
||||
it('FE-MOB-COSTSH-036: editing a booked bill previews the rate the save keeps (#2525)', () => {
|
||||
// A euro trip read in dollars, the bill entered in dollars at 1.17 to the euro.
|
||||
// Same currency as the list, so the sheet said nothing, while the list showed the
|
||||
// booked euros at today's rate beside the 801.76 typed here.
|
||||
localStorage.setItem('trek_fx_USD', JSON.stringify({ rates: { USD: 1, EUR: 0.865706 }, ts: Date.now() }))
|
||||
localStorage.setItem('trek_fx_EUR', JSON.stringify({ rates: { EUR: 1, USD: 1.1551 }, ts: Date.now() }))
|
||||
useTripStore.setState({ trip: buildTrip({ id: 1, currency: 'EUR' }) } as unknown as Partial<TripStoreState>)
|
||||
const editing = buildBudgetItem({
|
||||
id: 13, name: 'Aparthotel Silver', category: 'accommodation', currency: 'USD', exchange_rate: 1.17, total_price: 801.76,
|
||||
members: [member(1, null), member(2, null)],
|
||||
payers: [{ user_id: 1, amount: 801.76 }],
|
||||
})
|
||||
renderSheet({ base: 'USD', editing })
|
||||
|
||||
const hint = screen.getByText(/live rate/).parentElement as HTMLElement
|
||||
expect(within(hint).getByText('$801.76')).toBeInTheDocument()
|
||||
expect(within(hint).getByText(/^685,26\s€$/)).toBeInTheDocument()
|
||||
expect(within(hint).getByText('$791.55')).toBeInTheDocument()
|
||||
// Each share next to what it counts as, the figure the row's "you lent" is made of.
|
||||
expect(screen.getByText(/Split 2 ways · \$400\.88 → \$395\.77 each/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-MOB-COSTSH-037: a bill booked at today\'s rate has nothing to preview (#2525)', () => {
|
||||
localStorage.setItem('trek_fx_USD', JSON.stringify({ rates: { USD: 1, EUR: 0.87732 }, ts: Date.now() }))
|
||||
localStorage.setItem('trek_fx_EUR', JSON.stringify({ rates: { EUR: 1, USD: 1.1398 }, ts: Date.now() }))
|
||||
useTripStore.setState({ trip: buildTrip({ id: 1, currency: 'EUR' }) } as unknown as Partial<TripStoreState>)
|
||||
const editing = buildBudgetItem({
|
||||
id: 14, name: 'Villa', category: 'accommodation', currency: 'USD', exchange_rate: 1.1398, total_price: 12345.67,
|
||||
members: [member(1, null), member(2, null)],
|
||||
payers: [{ user_id: 1, amount: 12345.67 }],
|
||||
})
|
||||
renderSheet({ base: 'USD', editing })
|
||||
|
||||
expect(screen.queryByText(/live rate/)).toBeNull()
|
||||
expect(screen.queryByText(/→/)).toBeNull()
|
||||
})
|
||||
|
||||
it('FE-MOB-COSTSH-030: a currency without a known symbol falls back to its code', () => {
|
||||
localStorage.setItem('trek_fx_XTS', JSON.stringify({ rates: { XTS: 1 }, ts: Date.now() }))
|
||||
renderSheet({ base: 'XTS' })
|
||||
|
||||
@@ -639,7 +639,8 @@ describe('MCostsTab', () => {
|
||||
expect(mine).toHaveAttribute('aria-expanded', 'false')
|
||||
expect(within(card).getAllByText('+$58.00')).toHaveLength(2)
|
||||
expect(within(card).queryByText(/60\.00/)).not.toBeInTheDocument()
|
||||
expect(within(card).getByText('Museum')).toBeInTheDocument()
|
||||
// Named by what Bob entered, as the list names it (#2525), never re-converted.
|
||||
expect(within(card).getByText('Museum · £30.00')).toBeInTheDocument()
|
||||
|
||||
fireEvent.click(bob)
|
||||
expect(bob).toHaveAttribute('aria-expanded', 'false')
|
||||
@@ -725,6 +726,74 @@ describe('MCostsTab', () => {
|
||||
expect(update).toHaveBeenCalledWith(7, 505, { from_user_id: 1, to_user_id: 2, amount: 10, currency: 'GBP', settled_at: '2026-04-28' })
|
||||
})
|
||||
|
||||
it('FE-MOB-COSTT-045: a bill whose rate moved shows what was entered and what it was booked at (#2525)', async () => {
|
||||
// A euro trip read in dollars, the bill entered in dollars at a frozen 1.17 to the
|
||||
// euro while today the euro buys 1.1551. It is 685.26 EUR of trip money, $791.55
|
||||
// today, and that is what settle-up offers too; the row now says where the
|
||||
// 801.76 that was entered went instead of hiding it. Converted with the euro's own
|
||||
// quote, not the dollar's separately rounded one.
|
||||
seedStore(useSettingsStore, { settings: { ...useSettingsStore.getState().settings, default_currency: 'USD' } })
|
||||
localStorage.setItem('trek_fx_USD', JSON.stringify({ rates: { USD: 1, EUR: 0.865706 }, ts: Date.now() }))
|
||||
localStorage.setItem('trek_fx_EUR', JSON.stringify({ rates: { EUR: 1, USD: 1.1551 }, ts: Date.now() }))
|
||||
const hotel = {
|
||||
id: 21, trip_id: 7, name: 'Aparthotel Silver', category: 'accommodation', total_price: 801.76, currency: 'USD', exchange_rate: 1.17,
|
||||
expense_date: '2026-05-01', note: null,
|
||||
members: [
|
||||
{ user_id: 1, paid: 1, username: 'Me', amount: null, avatar_url: null },
|
||||
{ user_id: 2, paid: 0, username: 'Ada', amount: null, avatar_url: null },
|
||||
],
|
||||
payers: [{ user_id: 1, amount: 801.76, username: 'Me' }],
|
||||
} as unknown as BudgetItem
|
||||
serveSettlement({
|
||||
...SETTLEMENT,
|
||||
settlements: [
|
||||
{ id: 601, from_user_id: 2, to_user_id: 1, amount: 400.88, currency: 'USD', exchange_rate: 1.17, settled_at: '2026-05-02', created_at: '2026-05-02T09:00:00Z' },
|
||||
// A transfer from before they carried a currency was entered in the display currency.
|
||||
{ id: 602, from_user_id: 3, to_user_id: 1, amount: 30, currency: null, settled_at: '2026-05-03', created_at: '2026-05-03T09:00:00Z' },
|
||||
],
|
||||
})
|
||||
await renderTab(planner({ trip: { ...TRIP, currency: 'EUR' } as Trip, budgetItems: [hotel] }))
|
||||
|
||||
const card = cardOf('Aparthotel Silver')
|
||||
expect(within(card).getByText(/^\$801\.76 → 685,26\s€$/)).toBeInTheDocument()
|
||||
expect(within(card).getByText('$791.55')).toBeInTheDocument()
|
||||
// Each share is half of the booked euros, the figure the balances net.
|
||||
expect(within(card).getAllByText('$395.77')).toHaveLength(2)
|
||||
expect(within(card).queryByText('$400.88')).toBeNull()
|
||||
expect(up(screen.getByText('costs.totalSpend'), 1).textContent).toContain('$791.55')
|
||||
expect(screen.getByText('costs.spent:$791.55')).toBeInTheDocument()
|
||||
|
||||
expect(screen.getAllByText('costs.payment')).toHaveLength(2)
|
||||
const paid = up(screen.getByText('Ada → costs.you'), 2)
|
||||
expect(within(paid).getByText(/^\$400\.88 → 342,63\s€$/)).toBeInTheDocument()
|
||||
expect(within(up(screen.getByText('Bob → costs.you'), 2)).getByText('$30.00')).toBeInTheDocument()
|
||||
expect(screen.queryByText('$34.65')).toBeNull()
|
||||
})
|
||||
|
||||
it('FE-MOB-COSTT-046: a bill booked at today\'s rate reads exactly as typed (#2525)', async () => {
|
||||
seedStore(useSettingsStore, { settings: { ...useSettingsStore.getState().settings, default_currency: 'USD' } })
|
||||
localStorage.setItem('trek_fx_USD', JSON.stringify({ rates: { USD: 1, EUR: 0.87732 }, ts: Date.now() }))
|
||||
localStorage.setItem('trek_fx_EUR', JSON.stringify({ rates: { EUR: 1, USD: 1.1398 }, ts: Date.now() }))
|
||||
const villa = {
|
||||
id: 22, trip_id: 7, name: 'Villa', category: 'accommodation', total_price: 12345.67, currency: 'USD', exchange_rate: 1.1398,
|
||||
expense_date: '2026-05-01', note: null,
|
||||
members: [
|
||||
{ user_id: 1, paid: 1, username: 'Me', amount: null, avatar_url: null },
|
||||
{ user_id: 2, paid: 0, username: 'Ada', amount: null, avatar_url: null },
|
||||
],
|
||||
payers: [{ user_id: 1, amount: 12345.67, username: 'Me' }],
|
||||
} as unknown as BudgetItem
|
||||
serveSettlement(SETTLEMENT)
|
||||
await renderTab(planner({ trip: { ...TRIP, currency: 'EUR' } as Trip, budgetItems: [villa] }))
|
||||
|
||||
const card = cardOf('Villa')
|
||||
// Through the dollar's own quote it read $12,346.05.
|
||||
expect(within(card).getByText('$12,345.67')).toBeInTheDocument()
|
||||
expect(within(card).queryByText(/^\$12,345\.67 →/)).toBeNull()
|
||||
expect(screen.getByText('costs.spent:$12,345.67')).toBeInTheDocument()
|
||||
expect(up(screen.getByText('costs.totalSpend'), 1).textContent).toContain('$12,345.67')
|
||||
})
|
||||
|
||||
it('FE-MOB-COSTT-044: a payment cannot be saved without a day', async () => {
|
||||
// Cleared, the server would store NULL and the ledger would quietly fall
|
||||
// back to the day the payment was recorded on.
|
||||
|
||||
@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { http, HttpResponse } from 'msw'
|
||||
import MLinkedCosts from '../../../../src/mobile/screens/trip/sheets/MLinkedCosts'
|
||||
import { useTripStore } from '../../../../src/store/tripStore'
|
||||
import { useSettingsStore } from '../../../../src/store/settingsStore'
|
||||
import { formatMoney } from '../../../../src/utils/formatters'
|
||||
import type { BudgetItem } from '../../../../src/types'
|
||||
import { buildBudgetItem, buildTrip } from '../../../helpers/factories'
|
||||
@@ -9,7 +10,7 @@ import { server } from '../../../helpers/msw/server'
|
||||
import { resetAllStores, seedStore } from '../../../helpers/store'
|
||||
import { fireEvent, render, screen, waitFor, within } from '../../../helpers/render'
|
||||
|
||||
// FE-MOB-LINKCOST-001 to FE-MOB-LINKCOST-014
|
||||
// FE-MOB-LINKCOST-001 to FE-MOB-LINKCOST-015
|
||||
// MLinkedCosts reads the real translations (it is shared by three sheets), so
|
||||
// the assertions use the English copy rather than echoed keys.
|
||||
|
||||
@@ -208,4 +209,16 @@ describe('MLinkedCosts', () => {
|
||||
seedStore(useTripStore, { budgetItems: [souvenirs] })
|
||||
expect(await screen.findByText('Saves the place, then opens the Costs editor.')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-MOB-LINKCOST-015: an expense without a currency reads in the trip currency, not the display one (#2525)', () => {
|
||||
const deposit = buildBudgetItem({ id: 15, trip_id: 1, name: 'Hotel deposit', total_price: 120, currency: null, category: 'accommodation', reservation_id: 9 })
|
||||
const tram = buildBudgetItem({ id: 16, trip_id: 1, name: 'Tram pass', total_price: 9, currency: null, category: 'transport' })
|
||||
seedStore(useTripStore, { budgetItems: [deposit, tram] })
|
||||
seedStore(useSettingsStore, { settings: { default_currency: 'USD' } })
|
||||
setup()
|
||||
expect(within(rowOf('Hotel deposit')).getByText(money(120, 'EUR'))).toBeInTheDocument()
|
||||
expect(screen.queryByText(money(120, 'USD'))).not.toBeInTheDocument()
|
||||
fireEvent.click(linkPill())
|
||||
expect(screen.getByText('Tram pass').closest('button')).toHaveTextContent(money(9, 'EUR'))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -842,6 +842,18 @@ describe('MTransportFormSheet', () => {
|
||||
expect((addFile.mock.calls[0][1] as FormData).get('description')).toBe('Rental car')
|
||||
})
|
||||
|
||||
it('FE-MOB-TRFRM-029b: a parsed price keeps the currency it was quoted in (#2525)', async () => {
|
||||
const handleSaveTransport = makeSave()
|
||||
const planner = makePlanner({
|
||||
transportPrefill: { type: 'train', title: 'Amtrak', metadata: { price: 117, priceCurrency: 'USD' }, endpoints: [] },
|
||||
handleSaveTransport,
|
||||
})
|
||||
renderSheet(planner)
|
||||
await submit()
|
||||
// Sent without it, the server stored 117 in the trip currency.
|
||||
expect(handleSaveTransport.mock.calls[0][0].create_budget_entry).toEqual({ total_price: 117, category: 'transport', currency: 'USD' })
|
||||
})
|
||||
|
||||
it('FE-MOB-TRFRM-030: a prefill without a price and with the budget addon off skips the cost entry', async () => {
|
||||
seedStore(useAddonStore, { addons: [] })
|
||||
const handleSaveTransport = makeSave()
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
groupByDay,
|
||||
groupLedgerByDay,
|
||||
isUnfinished,
|
||||
lineOf,
|
||||
memberShareOf,
|
||||
myPaidOf,
|
||||
myShareOf,
|
||||
@@ -32,6 +33,7 @@ const ctx: CostsCtx = {
|
||||
me: 1,
|
||||
// lower case on purpose — currencyOf has to normalise it
|
||||
tripCurrency: 'eur',
|
||||
displayCurrency: 'EUR',
|
||||
convert: (amount, currency) => amount * (RATES[(currency || 'EUR').toUpperCase()] ?? 1),
|
||||
};
|
||||
|
||||
@@ -306,6 +308,86 @@ describe('costsModel — list filters and grouping', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('costsModel: a bill entered in the display currency (#2525)', () => {
|
||||
// A euro trip read in dollars, converted with the euro's own quote the way
|
||||
// useExchangeRates(base, tripCurrency) converts: one euro buys 1.1551 dollars today.
|
||||
const usdCtx: CostsCtx = {
|
||||
me: 1,
|
||||
tripCurrency: 'EUR',
|
||||
displayCurrency: 'usd',
|
||||
convert: (amount, currency) => {
|
||||
const perEuro = ({ USD: 1.1551, EUR: 1, SEK: 10 } as Record<string, number>)[(currency || 'USD').toUpperCase()] ?? 1
|
||||
return (amount / perEuro) * 1.1551
|
||||
},
|
||||
};
|
||||
const hotel = (rate = 1.17) => expense({
|
||||
total_price: 801.76, currency: 'USD', exchange_rate: rate,
|
||||
payers: [payer(1, 801.76)], members: [member(1), member(2)],
|
||||
});
|
||||
|
||||
it('FE-MOB-CMOD-038: a bill booked at a rate that has moved since counts as its euros at today\'s rate', () => {
|
||||
// 685.26 EUR, which the balances net and settle-up offers; the row, the payer's
|
||||
// figure and the share read the same, or a payback of the row's half reopens the trip.
|
||||
expect(baseTotal(hotel(), usdCtx)).toBeCloseTo(791.55, 2);
|
||||
expect(myPaidOf(hotel(), usdCtx)).toBeCloseTo(791.55, 2);
|
||||
expect(myShareOf(hotel(), usdCtx)).toBeCloseTo(395.77, 2);
|
||||
// Under it, what was entered and the euros it was booked at, no third step.
|
||||
const line = lineOf(801.76, hotel(), usdCtx, baseTotal(hotel(), usdCtx))!;
|
||||
expect(line.entered).toEqual({ amount: 801.76, currency: 'USD' });
|
||||
expect(line.into.currency).toBe('EUR');
|
||||
expect(line.into.amount).toBeCloseTo(685.26, 2);
|
||||
});
|
||||
|
||||
it('FE-MOB-CMOD-039: booked at today\'s rate, the bill reads exactly as typed and needs no line', () => {
|
||||
const big = expense({ total_price: 12345.67, currency: 'USD', exchange_rate: 1.1551, payers: [payer(1, 12345.67)], members: [member(1), member(2)] });
|
||||
const unpaid = expense({ total_price: 250, currency: 'USD', exchange_rate: 1.1551 });
|
||||
expect(Math.round(baseTotal(big, usdCtx) * 100)).toBe(1234567);
|
||||
expect(Math.round(baseTotal(unpaid, usdCtx) * 100)).toBe(25000);
|
||||
expect(lineOf(12345.67, big, usdCtx, baseTotal(big, usdCtx))).toBeNull();
|
||||
const t = computeTotals([big, unpaid], [], usdCtx);
|
||||
expect(Math.round(t.totalSpend * 100)).toBe(1259567);
|
||||
expect(Math.round(t.outstanding * 100)).toBe(25000);
|
||||
});
|
||||
|
||||
it('FE-MOB-CMOD-040: other currencies go through the trip currency at their booked rate', () => {
|
||||
// 1000 SEK booked at 10 per euro is 100 euro, and 100 euro is 115.51 dollars today.
|
||||
const sek = expense({ total_price: 1000, currency: 'SEK', exchange_rate: 10 })
|
||||
expect(baseTotal(sek, usdCtx)).toBeCloseTo(115.51, 2);
|
||||
expect(lineOf(1000, sek, usdCtx, baseTotal(sek, usdCtx))).toEqual({ entered: { amount: 1000, currency: 'SEK' }, into: { amount: 100, currency: 'EUR' } });
|
||||
// A row in the trip currency goes straight to the dollars.
|
||||
const eur = expense({ total_price: 100, currency: null })
|
||||
expect(baseTotal(eur, usdCtx)).toBeCloseTo(115.51, 2);
|
||||
expect(lineOf(100, eur, usdCtx, 115.51)).toEqual({ entered: { amount: 100, currency: 'EUR' }, into: { amount: 115.51, currency: 'USD' } });
|
||||
});
|
||||
|
||||
it('FE-MOB-CMOD-041: there is nothing to explain when nothing was converted', () => {
|
||||
// An amount of 0, a row written before the freeze, and any row when the viewer
|
||||
// reads the trip currency itself.
|
||||
const zero = expense({ total_price: 0, currency: 'USD', exchange_rate: 1.17 });
|
||||
expect(lineOf(0, zero, usdCtx, 0)).toBeNull();
|
||||
const legacy = expense({ total_price: 50, currency: 'USD', exchange_rate: 1 });
|
||||
expect(baseTotal(legacy, usdCtx)).toBe(50);
|
||||
expect(lineOf(50, legacy, usdCtx, 50)).toBeNull();
|
||||
const inEur = { ...usdCtx, displayCurrency: 'EUR', convert: (a: number) => a };
|
||||
expect(lineOf(801.76, hotel(), inEur, 685.26)).toEqual({ entered: { amount: 801.76, currency: 'USD' }, into: { amount: 685.26, currency: 'EUR' } });
|
||||
});
|
||||
|
||||
it('FE-MOB-CMOD-042: the CSV adds what each row counts as in the trip currency', () => {
|
||||
const t = ((key: string) => key) as unknown as Parameters<typeof buildCostsCsv>[1]['t'];
|
||||
const items = [
|
||||
hotel(),
|
||||
expense({ name: 'Old taxi', total_price: 115.51, currency: 'USD', exchange_rate: 1, expense_date: '2026-07-20' }),
|
||||
].map((e, i) => ({ ...e, name: e.name || 'Hotel', expense_date: e.expense_date || '2026-07-19', id: i + 1 }));
|
||||
const inUsd = buildCostsCsv(items, { base: 'USD', ctx: usdCtx, locale: 'en-US', tripTitle: 'Trip', t }).content.split('\r\n');
|
||||
expect(inUsd[0]).toBe('Date;Name;Category;Amount;Currency;Amount (EUR);Amount (USD);Note');
|
||||
expect(inUsd[1]).toMatch(/;801\.76;USD;685\.26;791\.55;$/);
|
||||
// Never booked, so counted at today's rate, as the server counts it.
|
||||
expect(inUsd[2]).toMatch(/;115\.51;USD;100\.00;115\.51;$/);
|
||||
const inEur = buildCostsCsv(items, { base: 'EUR', ctx: { ...usdCtx, displayCurrency: 'EUR' }, locale: 'en-US', tripTitle: 'Trip', t }).content.split('\r\n');
|
||||
expect(inEur[0]).toBe('Date;Name;Category;Amount;Currency;Amount (EUR);Note');
|
||||
});
|
||||
});
|
||||
|
||||
describe('costsModel — ledger grouping (expenses + settlement payments)', () => {
|
||||
it('FE-MOB-CMOD-032: merges expenses and payments into shared day groups, newest first, no-date last', () => {
|
||||
const e = expense({ id: 50, expense_date: '2026-07-02' });
|
||||
|
||||
Reference in New Issue
Block a user