Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions apps/dav/src/service/CalendarService.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { afterEach, describe, expect, it, vi } from 'vitest'
import { getEmptySlots, saveScheduleInboxAvailability } from './CalendarService.ts'

const customRequest = vi.fn()
vi.mock('../dav/client.ts', () => ({
getClient: () => ({ customRequest }),
}))

afterEach(() => {
customRequest.mockReset()
})

describe('saveScheduleInboxAvailability', () => {
it('removes the availability property when there are no slots', async () => {
await saveScheduleInboxAvailability(getEmptySlots(), 'UTC')

expect(customRequest).toHaveBeenCalledOnce()
const [path, { method, data }] = customRequest.mock.calls[0]
expect(path).toBe('inbox')
expect(method).toBe('PROPPATCH')
expect(data).toContain('<x0:remove>')
expect(data).not.toContain('<x0:set>')
expect(data).not.toContain('VAVAILABILITY')
})

it('sets the availability property when there are slots', async () => {
const slots = getEmptySlots()
slots.MO = [{
start: new Date('2026-10-12T09:00:00Z').getTime() / 1000,
end: new Date('2026-10-12T17:00:00Z').getTime() / 1000,
}]

await saveScheduleInboxAvailability(slots, 'UTC')

expect(customRequest).toHaveBeenCalledOnce()
const [path, { method, data }] = customRequest.mock.calls[0]
expect(path).toBe('inbox')
expect(method).toBe('PROPPATCH')
expect(data).toContain('<x0:set>')
expect(data).toContain('BEGIN:VAVAILABILITY')
expect(data).toContain('BEGIN:AVAILABLE')
})
})
18 changes: 18 additions & 0 deletions apps/dav/src/service/CalendarService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ export async function saveScheduleInboxAvailability(slots, timezoneId) {
day: dayId,
})))]

// An empty VAVAILABILITY means unavailable at all times (RFC 7953), so remove the property instead
if (all.length === 0) {
logger.debug('No availability slots, removing availability')

await getClient().customRequest('inbox', {
method: 'PROPPATCH',
data: `<?xml version="1.0"?>
<x0:propertyupdate xmlns:x0="DAV:">
<x0:remove>
<x0:prop>
<x1:calendar-availability xmlns:x1="urn:ietf:params:xml:ns:caldav"/>
</x0:prop>
</x0:remove>
</x0:propertyupdate>`,
})
return
}

const vavailability = slotsToVavailability(all, timezoneId)

logger.debug('New availability ical created', {
Expand Down
Loading