Files
Maurice 10a987fec1 fix(files): list a hotel booking's files and files pinned to a stop on the place card
A hotel booking reaches its place through the stay, not its own place_id, so
the card listed the booking but not its confirmation. Links to a stop, which
MCP's link_trip_file and plugins can make, were never returned by the file
list at all; it now carries linked_assignment_ids. Without files the row no
longer opens to nothing.
2026-10-14 13:24:27 +02:00

74 lines
3.6 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { filesForPlace } from '../../../src/utils/placeFiles'
import type { Reservation, TripFile } from '../../../src/types'
// FE-UTIL-PLACEFILES-001 to FE-UTIL-PLACEFILES-008
const file = (over: Partial<TripFile>): TripFile => ({
id: 1, trip_id: 5, original_name: 'a.pdf', url: '/uploads/a.pdf',
place_id: null, reservation_id: null, deleted_at: null,
...over,
} as unknown as TripFile)
const booking = (over: Partial<Reservation>): Reservation => ({
id: 90, trip_id: 5, title: 'Table', type: 'restaurant',
place_id: null, assignment_id: null,
...over,
} as unknown as Reservation)
describe('filesForPlace', () => {
it('FE-UTIL-PLACEFILES-001: keeps the files the place owns, by column and by link', () => {
const own = file({ id: 1, place_id: 7 })
const linked = file({ id: 2, linked_place_ids: [7] })
const other = file({ id: 3, place_id: 8 })
expect(filesForPlace([own, linked, other], 7, []).map(f => f.id)).toEqual([1, 2])
})
it('FE-UTIL-PLACEFILES-002: adds the files of a booking that sits on the place (#2217)', () => {
const files = [file({ id: 4, reservation_id: 90 })]
const bookings = [booking({ id: 90, place_id: 7 })]
expect(filesForPlace(files, 7, bookings).map(f => f.id)).toEqual([4])
})
it('FE-UTIL-PLACEFILES-003: reaches a booking through the stop it hangs on, not only through place_id', () => {
const files = [file({ id: 5, reservation_id: 90 })]
const bookings = [booking({ id: 90, assignment_id: 11 })]
expect(filesForPlace(files, 7, bookings, [11]).map(f => f.id)).toEqual([5])
// Without that stop in the day, the booking is not this place's business.
expect(filesForPlace(files, 7, bookings, [12])).toEqual([])
})
it('FE-UTIL-PLACEFILES-004: a file linked to the booking counts like one stored on it', () => {
const files = [file({ id: 6, linked_reservation_ids: [90] })]
expect(filesForPlace(files, 7, [booking({ id: 90, place_id: 7 })]).map(f => f.id)).toEqual([6])
})
it('FE-UTIL-PLACEFILES-005: lists a file once when it is both the place\'s and the booking\'s', () => {
const both = file({ id: 7, place_id: 7, reservation_id: 90 })
expect(filesForPlace([both], 7, [booking({ id: 90, place_id: 7 })]).map(f => f.id)).toEqual([7])
})
it('FE-UTIL-PLACEFILES-006: drops deleted files and answers empty without a place', () => {
const gone = file({ id: 8, place_id: 7, deleted_at: '2026-09-01' })
const bookingFileGone = file({ id: 9, reservation_id: 90, deleted_at: '2026-09-01' })
expect(filesForPlace([gone, bookingFileGone], 7, [booking({ id: 90, place_id: 7 })])).toEqual([])
expect(filesForPlace([file({ id: 10, place_id: 7 })], undefined, [])).toEqual([])
})
it('FE-UTIL-PLACEFILES-007: reaches a hotel booking through the stay on the place', () => {
// A hotel booking keeps place_id empty; the place is the stay's (#2363).
const stay = booking({ id: 90, place_id: null, assignment_id: null, accommodation_place_id: 7 })
const stored = file({ id: 11, reservation_id: 90 })
const linked = file({ id: 12, linked_reservation_ids: [90] })
expect(filesForPlace([stored, linked], 7, [stay]).map(f => f.id)).toEqual([11, 12])
// A stay on another place lends nothing to this one.
expect(filesForPlace([stored], 7, [{ ...stay, accommodation_place_id: 8 }])).toEqual([])
})
it('FE-UTIL-PLACEFILES-008: keeps a file pinned to one of the place\'s stops', () => {
const pinned = file({ id: 13, linked_assignment_ids: [11] })
expect(filesForPlace([pinned], 7, [], [11]).map(f => f.id)).toEqual([13])
expect(filesForPlace([pinned], 7, [], [12])).toEqual([])
})
})