From d79a9778e5a2af5f664cc0043cee96709d5455eb Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Fri, 27 Oct 2023 10:09:52 +0200 Subject: [PATCH] feat(attendee): expose member parameter as a string array Signed-off-by: Richard Steinmetz --- src/properties/attendeeProperty.js | 16 ++++++----- .../unit/properties/attendeeProperty.test.js | 27 +++++++++++++++++++ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/properties/attendeeProperty.js b/src/properties/attendeeProperty.js index ac49ed1c..db6b1bcb 100644 --- a/src/properties/attendeeProperty.js +++ b/src/properties/attendeeProperty.js @@ -2,6 +2,7 @@ * @copyright Copyright (c) 2019 Georg Ehrke * * @author Georg Ehrke + * @author Richard Steinmetz * * @license AGPL-3.0-or-later * @@ -208,21 +209,22 @@ export default class AttendeeProperty extends Property { } /** - * Gets the member address of the attendee + * Gets the email addresses of groups the attendee is a part of * - * @return {string} + * @return {string[]|null} The email addresses of the groups */ get member() { - return this.value + return this.getParameter('MEMBER')?.value ?? null } /** - * Sets the member address of the attendee + * Sets the email addresses of groups the attendee is a part of * - * @param {string} email The member address of the attendee + * @param {string[]} members The email addresses of the groups */ - set member(email) { - this.value = startStringWith(email, 'mailto:') + set member(members) { + members = members.map(member => startStringWith(member, 'mailto:')) + this.updateParameterIfExist('MEMBER', members) } /** diff --git a/tests/unit/properties/attendeeProperty.test.js b/tests/unit/properties/attendeeProperty.test.js index bdd57bf0..04eaece1 100644 --- a/tests/unit/properties/attendeeProperty.test.js +++ b/tests/unit/properties/attendeeProperty.test.js @@ -2,6 +2,7 @@ * @copyright Copyright (c) 2019 Georg Ehrke * * @author Georg Ehrke + * @author Richard Steinmetz * * @license AGPL-3.0-or-later * @@ -265,6 +266,32 @@ it('AttendeeProperty should provide easy getter/setter for email', () => { expect(property.email).toEqual('mailto:bar@example.com') }) +it('AttendeeProperty should provide easy getter/setter for member', () => { + const icalValue = ICAL.Property.fromString('ATTENDEE;MEMBER="mailto:projectA@example.com","mailto:projectB@example.com":mailto:janedoe@example.com') + const property = AttendeeProperty.fromICALJs(icalValue) + + expect(property.member).toEqual(['mailto:projectA@example.com', 'mailto:projectB@example.com']) + + property.member = ['foo@bar.com'] + expect(property.member).toEqual(['mailto:foo@bar.com']) + + property.lock() + expect(property.isLocked()).toEqual(true) + + expect(() => { + property.member = ['mailto:projc@example.com'] + }).toThrow(ModificationNotAllowedError) + expect(property.member).toEqual(['mailto:foo@bar.com']) + + property.unlock() +}) + +it('AttendeeProperty should handle missing member gracefully', () => { + const property = new AttendeeProperty('ATTENDEE') + + expect(property.member).toEqual(null) +}) + it('AttendeeProperty should provide easy getter/setter for commonName', () => { const icalValue = ICAL.Property.fromString('ATTENDEE;CN=Foo;PARTSTAT=DECLINED123;LANGUAGE=EN:mailto:mrbig@example.com') const property = AttendeeProperty.fromICALJs(icalValue)