Skip to content

Commit

Permalink
feat(attendee): expose member parameter as a string array
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Steinmetz <[email protected]>
  • Loading branch information
st3iny committed Oct 27, 2023
1 parent 9940802 commit d79a977
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/properties/attendeeProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @copyright Copyright (c) 2019 Georg Ehrke
*
* @author Georg Ehrke <[email protected]>
* @author Richard Steinmetz <[email protected]>
*
* @license AGPL-3.0-or-later
*
Expand Down Expand Up @@ -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)
}

/**
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/properties/attendeeProperty.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @copyright Copyright (c) 2019 Georg Ehrke
*
* @author Georg Ehrke <[email protected]>
* @author Richard Steinmetz <[email protected]>
*
* @license AGPL-3.0-or-later
*
Expand Down Expand Up @@ -265,6 +266,32 @@ it('AttendeeProperty should provide easy getter/setter for email', () => {
expect(property.email).toEqual('mailto:[email protected]')
})

it('AttendeeProperty should provide easy getter/setter for member', () => {
const icalValue = ICAL.Property.fromString('ATTENDEE;MEMBER="mailto:[email protected]","mailto:[email protected]":mailto:[email protected]')
const property = AttendeeProperty.fromICALJs(icalValue)

expect(property.member).toEqual(['mailto:[email protected]', 'mailto:[email protected]'])

property.member = ['[email protected]']
expect(property.member).toEqual(['mailto:[email protected]'])

property.lock()
expect(property.isLocked()).toEqual(true)

expect(() => {
property.member = ['mailto:[email protected]']
}).toThrow(ModificationNotAllowedError)
expect(property.member).toEqual(['mailto:[email protected]'])

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:[email protected]')
const property = AttendeeProperty.fromICALJs(icalValue)
Expand Down

0 comments on commit d79a977

Please sign in to comment.