mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
feat(costs): let a trip keep its costs as totals only (#1714)
Travellers who track what a trip costs but never split it saw an Unfinished warning on every expense and a settle-up they had no use for. A trip now has a costs mode (appended migration, trips.costs_mode, split by default); totals leaves payers, shares and settling up out of Costs on desktop and phone through the same gate as a trip of one, and saves new expenses without a payer. PUT /api/trips/:id and update_trip take it on budget_edit. The split chips move into their own component.
This commit is contained in:
@@ -18,7 +18,7 @@ import {
|
||||
type CostsSettlement,
|
||||
} from './costsModel';
|
||||
|
||||
// FE-BUDGET-COSTSMODEL-001 to FE-BUDGET-COSTSMODEL-013
|
||||
// FE-BUDGET-COSTSMODEL-001 to FE-BUDGET-COSTSMODEL-014
|
||||
// The pieces both ledgers share since the desktop panel runs on this model too;
|
||||
// the rest of the model is pinned in tests/unit/mobile/trip/costsModel.test.ts.
|
||||
|
||||
@@ -148,20 +148,20 @@ describe('costsModel: the currency picker options', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('costsModel: when Costs shows who paid and the shares (#2689)', () => {
|
||||
describe('costsModel: when Costs shows who paid and the shares (#2689, #1714)', () => {
|
||||
const settled = { flows: [], balances: [] };
|
||||
|
||||
it('FE-BUDGET-COSTSMODEL-012: a trip of one has nothing to split, unless the ledger still names someone else', () => {
|
||||
const mine = expense({ payers: [payer(1, 20)], members: [member(1)] });
|
||||
expect(showsSplitting(2, [], null, 1)).toBe(true);
|
||||
expect(showsSplitting(1, [mine], settled, 1)).toBe(false);
|
||||
expect(showsSplitting(0, [], null, 1)).toBe(false);
|
||||
expect(showsSplitting('split', 2, [], null, 1)).toBe(true);
|
||||
expect(showsSplitting(undefined, 1, [mine], settled, 1)).toBe(false);
|
||||
expect(showsSplitting('split', 0, [], null, 1)).toBe(false);
|
||||
// Someone who left: named on an expense, owed money, or still in a transfer.
|
||||
expect(showsSplitting(1, [expense({ members: [member(1), member(9)] })], settled, 1)).toBe(true);
|
||||
expect(showsSplitting('split', 1, [expense({ members: [member(1), member(9)] })], settled, 1)).toBe(true);
|
||||
const owed = { flows: [], balances: [{ user_id: 9, username: 'u9', avatar_url: null, balance: 5 }] };
|
||||
expect(showsSplitting(1, [mine], owed, 1)).toBe(true);
|
||||
expect(showsSplitting('split', 1, [mine], owed, 1)).toBe(true);
|
||||
const flow = { from: { user_id: 9, username: 'u9' }, to: { user_id: 1, username: 'u1' }, amount: 5 };
|
||||
expect(showsSplitting(1, [mine], { flows: [flow], balances: [] }, 1)).toBe(true);
|
||||
expect(showsSplitting('split', 1, [mine], { flows: [flow], balances: [] }, 1)).toBe(true);
|
||||
});
|
||||
|
||||
it('FE-BUDGET-COSTSMODEL-013: a split is plain with one payer, equal shares, no receipt lines and only current members', () => {
|
||||
@@ -172,4 +172,11 @@ describe('costsModel: when Costs shows who paid and the shares (#2689)', () => {
|
||||
expect(isPlainSplit(expense({ ticket_json: '{"items":[]}', members: [member(1)] }), [1])).toBe(false);
|
||||
expect(isPlainSplit(expense({ payers: [payer(9, 20)], members: [] }), [1])).toBe(false);
|
||||
});
|
||||
|
||||
it('FE-BUDGET-COSTSMODEL-014: a trip that keeps totals only splits nothing, however many share it (#1714)', () => {
|
||||
const shared = expense({ payers: [payer(1, 20)], members: [member(1), member(2)] });
|
||||
const flow = { from: { user_id: 2, username: 'u2' }, to: { user_id: 1, username: 'u1' }, amount: 10 };
|
||||
expect(showsSplitting('totals', 3, [shared], { flows: [flow], balances: [] }, 1)).toBe(false);
|
||||
expect(showsSplitting('split', 3, [shared], { flows: [flow], balances: [] }, 1)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user