Files
workavia-calendar-front/__test__/utils/buildDelegatedEvent.test.ts
T
lethemanh cadfa70e60 #708 apply strictier linting rules (#717)
* #708 apply strictier linting rules and fix simple eslint bugs

* #708 fix eslint errors relate to promise

* #708 fix eslint import/no-extraneous-dependencies

* #708 fix eslint errors of react-hook

* #708 enable eslint check for typescript

---------

Co-authored-by: lethemanh <lethemanh@lethemanhs-MacBook-Pro.local>
2026-04-01 17:15:10 +02:00

52 lines
1.8 KiB
TypeScript

import { Calendar } from '@/features/Calendars/CalendarTypes'
import { buildDelegatedEventURL } from '@/features/Events/utils'
const makeCalendar = (link: string): Calendar =>
({
id: 'user2/cal1',
delegated: true,
link,
owner: { emails: ['owner@example.com'] }
}) as Calendar
describe('buildDelegatedEventURL', () => {
it('rebases event filename onto calendar link base path', () => {
const calendar = makeCalendar('/calendars/user2/cal1.json')
const eventURL = '/calendars/someother/path/event-abc.ics'
expect(buildDelegatedEventURL(calendar, eventURL)).toBe(
'/calendars/user2/cal1/event-abc.ics'
)
})
it('strips .json suffix from calendar link', () => {
const calendar = makeCalendar('/calendars/user2/cal1.json')
const eventURL = '/calendars/user2/cal1/event-abc.ics'
const result = buildDelegatedEventURL(calendar, eventURL)
expect(result).not.toContain('.json')
})
it('preserves the exact filename from the event URL', () => {
const calendar = makeCalendar('/calendars/user2/cal1.json')
const eventURL = '/calendars/user2/cal1/some-uid-with-dashes.ics'
expect(buildDelegatedEventURL(calendar, eventURL)).toBe(
'/calendars/user2/cal1/some-uid-with-dashes.ics'
)
})
it('throws when event URL has no filename', () => {
const calendar = makeCalendar('/calendars/user2/cal1.json')
const eventURL = ''
expect(() => buildDelegatedEventURL(calendar, eventURL)).toThrow(
/Cannot extract filename from event URL/
)
})
it('works with nested calendar link paths', () => {
const calendar = makeCalendar('/dav/calendars/users/user2/cal1.json')
const eventURL = '/other/path/event-xyz.ics'
expect(buildDelegatedEventURL(calendar, eventURL)).toBe(
'/dav/calendars/users/user2/cal1/event-xyz.ics'
)
})
})