Skip to content

Commit

Permalink
Support X-WR-CALNAME (adamgibbons#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
ykzts authored Jun 7, 2020
1 parent 6af0631 commit 4d1c976
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ The following properties are accepted:
| busyStatus | Used to specify busy status for Microsoft applications, like Outlook. See [Microsoft spec](https://docs.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxcical/cd68eae7-ed65-4dd3-8ea7-ad585c76c736). | `'BUSY'` OR `'FREE'` OR `'TENTATIVE`' OR `'OOF'`
| created | Date-time representing event's creation date. Provide a date-time in UTC | [2000, 1, 5, 10, 0] (January 5, 2000 GMT +00:00)
| lastModified | Date-time representing date when event was last modified. Provide a date-time in UTC | [2000, 1, 5, 10, 0] (January 5, 2000 GMT +00:00)
| calName | Name of calendar | `'Example Calendar'` |

To create an **all-day** event, pass only three values (`year`, `month`, and `date`) to the `start` and `end` properties.
The date of the `end` property should be the day *after* your all-day event.
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export type EventAttributes = {
method?: string;
recurrenceRule?: string;
sequence?: number;
calName?: string;
} & ({ end: DateArray } | { duration: DurationObject });

export type ReturnObject = { error?: Error; value?: string };
Expand Down
3 changes: 2 additions & 1 deletion src/pipeline/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export default function buildEvent(attributes = {}) {
alarms,
recurrenceRule,
created,
lastModified
lastModified,
calName
} = attributes;

// fill in default values where necessary
Expand Down
4 changes: 3 additions & 1 deletion src/pipeline/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export default function formatEvent(attributes = {}) {
recurrenceRule,
busyStatus,
created,
lastModified
lastModified,
calName
} = attributes

let icsFormat = ''
Expand All @@ -48,6 +49,7 @@ export default function formatEvent(attributes = {}) {
icsFormat += 'CALSCALE:GREGORIAN\r\n'
icsFormat += foldLine(`PRODID:${productId}`) + '\r\n'
icsFormat += foldLine(`METHOD:${method}`) + '\r\n'
icsFormat += calName ? (foldLine(`X-WR-CALNAME:${calName}`) + '\r\n') : ''
icsFormat += `X-PUBLISHED-TTL:PT1H\r\n`
icsFormat += 'BEGIN:VEVENT\r\n'
icsFormat += `UID:${uid}\r\n`
Expand Down
3 changes: 2 additions & 1 deletion src/schema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ const schema = Joi.object().keys({
recurrenceRule: Joi.string(),
busyStatus: Joi.string().regex(/TENTATIVE|FREE|BUSY|OOF/),
created: dateTimeSchema,
lastModified: dateTimeSchema
lastModified: dateTimeSchema,
calName: Joi.string()
}).xor('end', 'duration')

export default function validateEvent(candidate) {
Expand Down
6 changes: 6 additions & 0 deletions test/pipeline/build.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ describe('pipeline.build properties', () => {
expect(event.lastModified).to.be.an('array')
})
})
describe('calName', () => {
it('sets a cal name', () => {
const event = buildEvent({ calName: 'John\'s Calendar' })
expect(event.calName).to.equal('John\'s Calendar')
})
})
describe('description', () => {
it('removes a falsey value', () => {
const event = buildEvent()
Expand Down
5 changes: 5 additions & 0 deletions test/pipeline/format.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ describe('pipeline.formatEvent', () => {
const formattedEvent = formatEvent(event)
expect(formattedEvent).to.contain('LAST-MODIFIED:20170515')
})
it('writes a cal name', () => {
const event = buildEvent({ calName: 'John\'s Calendar' })
const formattedEvent = formatEvent(event)
expect(formattedEvent).to.contain('X-WR-CALNAME:John\'s Calendar')
})
it('writes a sequence', () => {
const event = buildEvent({ sequence: 8 })
const formattedEvent = formatEvent(event)
Expand Down
8 changes: 8 additions & 0 deletions test/schema/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,14 @@ describe('.validateEvent', () => {
lastModified: [2018, 12, 1, 9, 30]
}).value.lastModified).to.exist
})

it('calName', () => {
expect(validateEvent({
title: 'foo',
uid: 'foo',
calName: 'John\'s Calendar'
}).value.calName).to.exist
})
})

describe('may have one or more occurances of', () => {
Expand Down

0 comments on commit 4d1c976

Please sign in to comment.