mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 08:53:13 +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:
@@ -385,6 +385,25 @@ describe('TripsController (parity with the legacy /api/trips route)', async () =
|
||||
});
|
||||
});
|
||||
|
||||
it('the costs mode needs budget_edit and nothing else (#1714)', async () => {
|
||||
const noBudget = svc({ can: vi.fn().mockImplementation((a: string) => a !== 'budget_edit') });
|
||||
expect(await thrownAsync(() => tc(noBudget).update(user, '9', { costs_mode: 'totals' }, req))).toEqual({
|
||||
status: 403,
|
||||
body: { error: 'No permission to change how this trip keeps its costs' },
|
||||
});
|
||||
const update = vi.fn().mockReturnValue({
|
||||
updatedTrip: { id: 9, costs_mode: 'totals' },
|
||||
changes: { costs_mode: 'totals' },
|
||||
newTitle: 'b',
|
||||
newReminder: 0,
|
||||
oldReminder: 0,
|
||||
});
|
||||
const onlyBudget = svc({ update, can: vi.fn().mockImplementation((a: string) => a === 'budget_edit') });
|
||||
expect(await tc(onlyBudget).update(user, '9', { costs_mode: 'totals' }, req)).toEqual({
|
||||
trip: { id: 9, costs_mode: 'totals' },
|
||||
});
|
||||
});
|
||||
|
||||
it('403 on an edit field without trip_edit', async () => {
|
||||
const s = svc({ can: vi.fn().mockImplementation((a: string) => a !== 'trip_edit') });
|
||||
expect(await thrownAsync(() => tc(s).update(user, '9', { title: 'b' }, req))).toEqual({
|
||||
|
||||
Reference in New Issue
Block a user