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
12 changes: 12 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
*
*/
export default class DavClient {

Check warning on line 26 in src/index.js

View workflow job for this annotation

GitHub Actions / NPM lint

Missing JSDoc @PARAM "options" description
/**

Check warning on line 27 in src/index.js

View workflow job for this annotation

GitHub Actions / NPM lint

Missing JSDoc @PARAM "options.rootUrl" description
* @param {object} options

Check warning on line 28 in src/index.js

View workflow job for this annotation

GitHub Actions / NPM lint

Prefer a more specific type to `any`
* @param {string} options.rootUrl

Check warning on line 29 in src/index.js

View workflow job for this annotation

GitHub Actions / NPM lint

Missing JSDoc @PARAM "factories" description
* @param {{[name: string]: any}} [options.defaultHeaders] A dictionary of default headers to apply to each request.
* @param {object} factories
*/
Expand Down Expand Up @@ -111,7 +111,7 @@

/**
* initializes the DAVClient
* @param {object} options

Check warning on line 114 in src/index.js

View workflow job for this annotation

GitHub Actions / NPM lint

Missing JSDoc @PARAM "options" description
* @return {Promise<DavClient>}
*/
async connect(options = { enableCalDAV: false, enableCardDAV: false }) {
Expand Down Expand Up @@ -176,7 +176,7 @@
/**
* performs a principal property search based on a principal's displayname
*
* @param {string} name

Check warning on line 179 in src/index.js

View workflow job for this annotation

GitHub Actions / NPM lint

Missing JSDoc @PARAM "name" description
* @return {Promise<Principal[]>}
*/
async principalPropertySearchByDisplayname(name) {
Expand All @@ -188,7 +188,7 @@
/**
* performs a principal property search based on a principal's displayname OR email address
*
* @param {string} value

Check warning on line 191 in src/index.js

View workflow job for this annotation

GitHub Actions / NPM lint

Missing JSDoc @PARAM "value" description
* @return {Promise<Principal[]>}
*/
async principalPropertySearchByDisplaynameOrEmail(value) {
Expand All @@ -198,6 +198,18 @@
], value, 'anyof')
}

/**
* Performs a principal property based on the building name of a room
*
* @param {string} name Name of the building the room is in
* @return {Promise<Principal[]>}
*/
async principalPropertySearchByBuildingName(name) {
return this.principalPropertySearch([
{ name: [NS.NEXTCLOUD, 'room-building-name'] },
], name)
}

/**
* Performs a principal property based on the address of a room
*
Expand Down
2 changes: 2 additions & 0 deletions src/models/principal.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class Principal extends DavObject {
// Room and resource booking related
this._exposeProperty('roomType', NS.NEXTCLOUD, 'room-type')
this._exposeProperty('roomSeatingCapacity', NS.NEXTCLOUD, 'room-seating-capacity')
this._exposeProperty('roomBuildingName', NS.NEXTCLOUD, 'room-building-name')
this._exposeProperty('roomBuildingAddress', NS.NEXTCLOUD, 'room-building-address')
this._exposeProperty('roomBuildingStory', NS.NEXTCLOUD, 'room-building-story')
this._exposeProperty('roomBuildingRoomNumber', NS.NEXTCLOUD, 'room-building-room-number')
Expand Down Expand Up @@ -206,6 +207,7 @@ export class Principal extends DavObject {
[NS.NEXTCLOUD, 'resource-contact-person-vcard'],
[NS.NEXTCLOUD, 'room-type'],
[NS.NEXTCLOUD, 'room-seating-capacity'],
[NS.NEXTCLOUD, 'room-building-name'],
[NS.NEXTCLOUD, 'room-building-address'],
[NS.NEXTCLOUD, 'room-building-story'],
[NS.NEXTCLOUD, 'room-building-room-number'],
Expand Down
1 change: 1 addition & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export default class Parser {
this.registerParser('{http://nextcloud.com/ns}language', Parser.text)
this.registerParser('{http://nextcloud.com/ns}room-type', Parser.text)
this.registerParser('{http://nextcloud.com/ns}room-seating-capacity', Parser.decInt)
this.registerParser('{http://nextcloud.com/ns}room-building-name', Parser.text)
this.registerParser('{http://nextcloud.com/ns}room-building-address', Parser.text)
this.registerParser('{http://nextcloud.com/ns}room-building-story', Parser.text)
this.registerParser('{http://nextcloud.com/ns}room-building-room-number', Parser.text)
Expand Down
26 changes: 26 additions & 0 deletions test/unit/clientTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,29 @@ describe('calendar home helpers', () => {
await expect(client.getCalendarHomeUrlForPrincipal('https://cloud.example.com/remote.php/dav/principals/users/bob/')).resolves.toBeNull()
})
})

describe('principalPropertySearchByBuildingName', () => {
it('searches by the room-building-name property and returns matching principals', async () => {
const client = new Client({ rootUrl: 'https://cloud.example.com/remote.php/dav/' })
const reportSpy = vi.spyOn(client._request, 'report').mockResolvedValue({
body: {
'/remote.php/dav/principals/rooms/room1/': {
[`{${NS.NEXTCLOUD}}room-building-name`]: 'Headquarters',
},
},
})
vi.spyOn(client._request, 'pathname').mockImplementation((path) => path)

const result = await client.principalPropertySearchByBuildingName('Headquarters')

expect(reportSpy).toHaveBeenCalledOnce()
const [url, headers, xml] = reportSpy.mock.calls[0]
expect(url).toBe(client.rootUrl)
expect(headers).toEqual({ Depth: 0 })
expect(xml).toContain('room-building-name')
expect(xml).toContain('Headquarters')

expect(result).toHaveLength(1)
expect(result[0].url).toBe('/remote.php/dav/principals/rooms/room1/')
})
})
1 change: 1 addition & 0 deletions test/unit/models/principalTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ describe('Principal model', () => {
['http://nextcloud.com/ns', 'resource-contact-person-vcard'],
['http://nextcloud.com/ns', 'room-type'],
['http://nextcloud.com/ns', 'room-seating-capacity'],
['http://nextcloud.com/ns', 'room-building-name'],
['http://nextcloud.com/ns', 'room-building-address'],
['http://nextcloud.com/ns', 'room-building-story'],
['http://nextcloud.com/ns', 'room-building-room-number'],
Expand Down
Loading