fix(client): stop shared items counting towards the recipient bag weight

An item shared through the sharing tier is visible to its recipients but
carried by its owner. The bag totals filtered on bag_id alone, so every
recipient saw the owner's weight added to their own load — which is exactly
the situation that tier exists for (one person brings the first-aid kit).

Filtering by owner_id, as the issue suggests, would have broken more than it
fixed: owner_id is stamped on every item including Common ones, so the group
pool would have shrunk to "only what I entered myself" even on trips where
nobody shares anything. The predicate keeps the Common pool intact and drops
only private items owned by someone else.

Closes #1767
This commit is contained in:
Maurice
2026-08-03 21:47:45 +02:00
committed by Maurice
parent d7d7fac339
commit 446bbdc38f
7 changed files with 111 additions and 19 deletions
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
import { katColor, itemWeight, bagFillPct, parseCsvLine, parseImportLines } from './packingListPanel.helpers'
import { katColor, itemWeight, bagFillPct, countsTowardsMyLoad, parseCsvLine, parseImportLines } from './packingListPanel.helpers'
import { KAT_COLORS } from './packingListPanel.constants'
describe('packingListPanel.helpers', () => {
@@ -46,6 +46,31 @@ describe('packingListPanel.helpers', () => {
})
})
describe('countsTowardsMyLoad', () => {
it('counts the common pool for everyone', () => {
// owner_id is stamped on every item, common ones included — filtering by it alone
// would shrink the group total to "only what I entered myself".
expect(countsTowardsMyLoad({ is_private: 0, owner_id: 2 }, 1)).toBe(true)
})
it('counts my own private items', () => {
expect(countsTowardsMyLoad({ is_private: 1, owner_id: 1 }, 1)).toBe(true)
})
it('leaves out an item somebody else shared with me', () => {
expect(countsTowardsMyLoad({ is_private: 1, owner_id: 2 }, 1)).toBe(false)
})
it('counts unowned legacy rows', () => {
expect(countsTowardsMyLoad({ is_private: 1, owner_id: null }, 1)).toBe(true)
})
it('filters nothing when the viewer is unknown', () => {
expect(countsTowardsMyLoad({ is_private: 1, owner_id: 2 }, null)).toBe(true)
expect(countsTowardsMyLoad({ is_private: 1, owner_id: 2 }, undefined)).toBe(true)
})
})
describe('bagFillPct', () => {
it('measures against the bag limit when there is one', () => {
expect(bagFillPct(5000, 20000, 99999)).toBe(25)