Skip to content
Merged
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
2 changes: 1 addition & 1 deletion docs/docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ const calendarObjects = await client.fetchCalendarObjects({
```ts
const calendarObjects = await client.fetchCalendarObjects({
calendar: myCalendar,
calendarObjectUrls: urlArray,
objectUrls: urlArray,
});
```

Expand Down
12 changes: 1 addition & 11 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,5 @@
"docusaurus-plugin-llms": "^0.6.0",
"typescript": "7.0.2"
},
"packageManager": "pnpm@10.34.4",
"pnpm": {
"overrides": {
"docusaurus-plugin-llms>minimatch": "9.0.7",
"docusaurus-plugin-llms>yaml": "2.8.3",
"qs@>=6.14.2 <6.16.0": "6.16.0",
"sockjs>uuid": "11.1.1",
"serialize-javascript@<7.0.5": "7.0.5",
"image-size": "npm:image-size-next@2.1.1"
}
}
"packageManager": "pnpm@10.34.4"
}
2 changes: 2 additions & 0 deletions docs/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions docs/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ packages:
overrides:
serialize-javascript: 7.0.6
'uuid@<11.1.1': 11.1.1
docusaurus-plugin-llms>minimatch: "9.0.7"
docusaurus-plugin-llms>yaml: "2.8.3"
qs@>=6.14.2 <6.16.0: "6.16.0"
sockjs>uuid: "11.1.1"
serialize-javascript@<7.0.5: "7.0.5"
image-size: "npm:image-size-next@2.1.1"
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,5 @@
"packageManager": "pnpm@10.34.4",
"engines": {
"node": ">=18"
},
"pnpm": {
"overrides": {
"vite>postcss": "8.5.28"
}
}
}
18 changes: 8 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ overrides:
postcss: 8.5.15
serialize-javascript: 7.0.6
vite: 6.4.3
vite>postcss: "8.5.28"
36 changes: 36 additions & 0 deletions src/__tests__/unit/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,4 +606,40 @@ describe('fetchHomeUrl', () => {
}),
).rejects.toThrow('cannot find homeUrl');
});

it('should handle calendar-home-set with multiple hrefs by selecting the first', async () => {
const mockFetch = vi.fn().mockResolvedValue(
buildResponse({
status: 207,
body: `<?xml version="1.0" encoding="utf-8"?>
<d:multistatus xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
<d:response>
<d:href>/principals/user1/</d:href>
<d:propstat>
<d:prop>
<c:calendar-home-set>
<d:href>/calendars/user1/</d:href>
<d:href>/calendars/shared/</d:href>
</c:calendar-home-set>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
</d:multistatus>`,
headers: { 'content-type': 'application/xml' },
}),
);

const result = await fetchHomeUrl({
account: {
serverUrl: 'https://example.com/',
rootUrl: 'https://example.com/',
principalUrl: 'https://example.com/principals/user1/',
accountType: 'caldav',
},
fetch: mockFetch,
});

expect(result).toBe('https://example.com/calendars/user1/');
});
});
65 changes: 65 additions & 0 deletions src/__tests__/unit/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,3 +852,68 @@ describe('DAVClient empty sync response', () => {
expect(await client.calendarQuery({ url: 'http://example.com/col/', props: {} })).toEqual([]);
});
});

describe('client freeBusyQuery', () => {
it('should expose freeBusyQuery on DAVClient', async () => {
const mockFetch = buildMockFetch(
`<?xml version="1.0" encoding="utf-8"?>
<d:multistatus xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
<d:response>
<d:href>/cal/</d:href>
<d:propstat>
<d:prop><c:calendar-data>BEGIN:VCALENDAR...END:VCALENDAR</c:calendar-data></d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
</d:multistatus>`,
207,
);
const client = new DAVClient({
serverUrl: 'http://example.com/',
credentials: { username: 'u', password: 'p' },
fetch: mockFetch,
});
client.authHeaders = { authorization: 'Basic dTpw' };

const res = await client.freeBusyQuery({
url: 'http://example.com/cal/',
timeRange: { start: '2026-01-01T00:00:00Z', end: '2026-01-02T00:00:00Z' },
});

expect(res).toBeDefined();
expect(mockFetch).toHaveBeenCalled();
const lastCall = mockFetch.mock.calls[mockFetch.mock.calls.length - 1];
expect(lastCall[1].body).toContain('free-busy-query');
});

it('should expose freeBusyQuery on createDAVClient', async () => {
const mockFetch = buildMockFetch(
`<?xml version="1.0" encoding="utf-8"?>
<d:multistatus xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
<d:response>
<d:href>/cal/</d:href>
<d:propstat>
<d:prop><c:calendar-data>BEGIN:VCALENDAR...END:VCALENDAR</c:calendar-data></d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
</d:multistatus>`,
207,
);
const client = await createDAVClient({
serverUrl: 'http://example.com/',
credentials: { username: 'u', password: 'p' },
fetch: mockFetch,
});

const res = await client.freeBusyQuery({
url: 'http://example.com/cal/',
timeRange: { start: '2026-01-01T00:00:00Z', end: '2026-01-02T00:00:00Z' },
});

expect(res).toBeDefined();
expect(mockFetch).toHaveBeenCalled();
const lastCall = mockFetch.mock.calls[mockFetch.mock.calls.length - 1];
expect(lastCall[1].body).toContain('free-busy-query');
});
});
1 change: 1 addition & 0 deletions src/__tests__/unit/collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ describe('makeCollection', () => {
expect(mockedDavRequest.mock.calls[0][0].init.method).toBe('MKCOL');
const body = mockedDavRequest.mock.calls[0][0].init.body as any;
expect(body.mkcol.set.prop).toEqual({ 'd:displayname': 'New Collection' });
expect(body.mkcol._attributes).toHaveProperty('xmlns:d', 'DAV:');
expect(result).toHaveLength(1);
});

Expand Down
75 changes: 75 additions & 0 deletions src/__tests__/unit/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { describe, it, expect } from 'vitest';
import * as tsdav from '../../index';

describe('tsdav public exports', () => {
it('should export all public client, request, and collection functions', () => {
expect(typeof tsdav.DAVClient).toBe('function');
expect(typeof tsdav.createDAVClient).toBe('function');
expect(typeof tsdav.davRequest).toBe('function');
expect(typeof tsdav.propfind).toBe('function');
expect(typeof tsdav.createObject).toBe('function');
expect(typeof tsdav.updateObject).toBe('function');
expect(typeof tsdav.deleteObject).toBe('function');
expect(typeof tsdav.collectionQuery).toBe('function');
expect(typeof tsdav.supportedReportSet).toBe('function');
expect(typeof tsdav.isCollectionDirty).toBe('function');
expect(typeof tsdav.syncCollection).toBe('function');
expect(typeof tsdav.smartCollectionSync).toBe('function');
expect(typeof tsdav.smartCollectionSyncDetailed).toBe('function');
});

it('should export all public account functions including discovery', () => {
expect(typeof tsdav.createAccount).toBe('function');
expect(typeof tsdav.serviceDiscovery).toBe('function');
expect(typeof tsdav.fetchPrincipalUrl).toBe('function');
expect(typeof tsdav.fetchHomeUrl).toBe('function');
});

it('should export all public calendar and addressbook functions', () => {
expect(typeof tsdav.calendarQuery).toBe('function');
expect(typeof tsdav.calendarMultiGet).toBe('function');
expect(typeof tsdav.makeCalendar).toBe('function');
expect(typeof tsdav.fetchCalendars).toBe('function');
expect(typeof tsdav.fetchCalendarUserAddresses).toBe('function');
expect(typeof tsdav.fetchCalendarObjects).toBe('function');
expect(typeof tsdav.createCalendarObject).toBe('function');
expect(typeof tsdav.updateCalendarObject).toBe('function');
expect(typeof tsdav.deleteCalendarObject).toBe('function');
expect(typeof tsdav.syncCalendars).toBe('function');
expect(typeof tsdav.syncCalendarsDetailed).toBe('function');
expect(typeof tsdav.freeBusyQuery).toBe('function');

expect(typeof tsdav.addressBookQuery).toBe('function');
expect(typeof tsdav.addressBookMultiGet).toBe('function');
expect(typeof tsdav.fetchAddressBooks).toBe('function');
expect(typeof tsdav.fetchVCards).toBe('function');
expect(typeof tsdav.createVCard).toBe('function');
expect(typeof tsdav.updateVCard).toBe('function');
expect(typeof tsdav.deleteVCard).toBe('function');
});

it('should export auth and request helpers', () => {
expect(typeof tsdav.getBasicAuthHeaders).toBe('function');
expect(typeof tsdav.getBearerAuthHeaders).toBe('function');
expect(typeof tsdav.getOauthHeaders).toBe('function');
expect(typeof tsdav.fetchOauthTokens).toBe('function');
expect(typeof tsdav.refreshAccessToken).toBe('function');

expect(typeof tsdav.urlContains).toBe('function');
expect(typeof tsdav.urlEquals).toBe('function');
expect(typeof tsdav.urlMatches).toBe('function');
expect(typeof tsdav.ensureTrailingSlash).toBe('function');
expect(typeof tsdav.getDAVAttribute).toBe('function');
expect(typeof tsdav.cleanupFalsy).toBe('function');
expect(typeof tsdav.excludeHeaders).toBe('function');
expect(typeof tsdav.mergeHeaders).toBe('function');
});

it('should export constants', () => {
expect(tsdav.DAVNamespace).toBeDefined();
expect(tsdav.DAVAttributeMap).toBeDefined();
expect(tsdav.DAVNamespaceShort).toBeDefined();
expect(tsdav.ICALObjects).toBeDefined();
expect(tsdav.ICALObjects.VEVENT).toBe('VEVENT');
});
});
37 changes: 37 additions & 0 deletions src/__tests__/unit/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,43 @@ describe('davRequest', () => {
expect(callArgs.credentials).toBe('include');
expect(callArgs.headers['X-Extra']).toBe('yes');
});

it.each([null, undefined])(
'should send a %s body with attributes without conversion',
async (body) => {
const mockFetch = buildMockFetch({ text: '' });
await davRequest({
url: 'http://example.com/',
init: { method: 'OPTIONS', body, attributes: { 'xmlns:d': 'DAV:' } },
fetch: mockFetch,
});
expect(mockFetch).toHaveBeenCalledOnce();
expect(mockFetch.mock.calls[0][1].body).toBe(body);
},
);

it('should propagate init.attributes to the root XML element', async () => {
const mockFetch = buildMockFetch({ text: '' });

await davRequest({
url: 'http://example.com/',
init: {
method: 'REPORT',
body: {
'custom-report': {
prop: {},
},
},
attributes: {
'xmlns:custom': 'http://example.com/ns',
},
},
fetch: mockFetch,
});

const callArgs = mockFetch.mock.calls[0][1];
expect(callArgs.body).toContain('xmlns:custom="http://example.com/ns"');
});
});

describe('propfind', () => {
Expand Down
Loading
Loading