From cc19cca6b5a1a1c5e6ee231a371371bb8e8979bc Mon Sep 17 00:00:00 2001 From: SebastianKrupinski Date: Thu, 20 Aug 2026 08:48:42 -0400 Subject: [PATCH] feat: add building name Signed-off-by: SebastianKrupinski --- src/index.js | 12 ++++++++++++ src/models/principal.js | 2 ++ src/parser.js | 1 + test/unit/clientTest.js | 26 ++++++++++++++++++++++++++ test/unit/models/principalTest.js | 1 + 5 files changed, 42 insertions(+) diff --git a/src/index.js b/src/index.js index 81d0d1f4..09661ab6 100644 --- a/src/index.js +++ b/src/index.js @@ -198,6 +198,18 @@ export default class DavClient { ], 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} + */ + async principalPropertySearchByBuildingName(name) { + return this.principalPropertySearch([ + { name: [NS.NEXTCLOUD, 'room-building-name'] }, + ], name) + } + /** * Performs a principal property based on the address of a room * diff --git a/src/models/principal.js b/src/models/principal.js index b2032c3b..e9f0f52f 100644 --- a/src/models/principal.js +++ b/src/models/principal.js @@ -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') @@ -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'], diff --git a/src/parser.js b/src/parser.js index 149d174a..f0171244 100644 --- a/src/parser.js +++ b/src/parser.js @@ -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) diff --git a/test/unit/clientTest.js b/test/unit/clientTest.js index 7d1d6342..7d954db5 100644 --- a/test/unit/clientTest.js +++ b/test/unit/clientTest.js @@ -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/') + }) +}) diff --git a/test/unit/models/principalTest.js b/test/unit/models/principalTest.js index f436b20f..f0a6866d 100644 --- a/test/unit/models/principalTest.js +++ b/test/unit/models/principalTest.js @@ -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'],