Skip to content

Commit

Permalink
refactor(yahoo): removes RPAT parameter
Browse files Browse the repository at this point in the history
BREAKING CHANGE: removes the ability to specify recurrences with Yahoo
calendar as this ability has been removed by Yahoo.
  • Loading branch information
jshor committed Aug 28, 2021
1 parent c1eb754 commit 598a53d
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 315 deletions.
4 changes: 4 additions & 0 deletions docs/config/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ The event end timestamp. For all-day events, this field should be omitted.

The specification for when the event should repeat. See [CalendarRecurrence](recurrence.md) for more information.

:::warning Note
This feature is not supported in Yahoo or Outlook online calendars.
:::

## attendees <Badge text="6.2.3" vertical="middle" />

* Type: [`CalendarAttendee[]`](attendees.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/config/recurrence.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The `CalendarRecurrence` object specifies how often the event is supposed to occ
Recurrence is **optional**.

:::warning Note
This feature is not supported in Outlook online calendars.
This feature is not supported in Yahoo or Outlook online calendars.
:::

## frequency
Expand Down
20 changes: 0 additions & 20 deletions src/YahooCalendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import CalendarBase from './CalendarBase'
import { URL, FORMAT } from './constants'
import data from './utils/data'
import time from './utils/time'
import yahooUtils from './utils/yahoo'
import CalendarOptions from './types/CalendarOptions'

/**
Expand All @@ -27,7 +26,6 @@ export default class YahooCalendar extends CalendarBase {
.setParam('in_loc', this.location)

this.setTimeParams()
this.setRecurrenceParams()

if (this.attendees.length > 0) {
this.setParam('inv_list', data.toMailtoList(this.attendees).join(','))
Expand Down Expand Up @@ -55,24 +53,6 @@ export default class YahooCalendar extends CalendarBase {
}
}

/**
* Sets the recurrence parameters, if recurrence is specified.
*/
private setRecurrenceParams = (): void => {
if (this.recurrence) {
this.setParam('RPAT', yahooUtils.getRecurrence(this.recurrence))

if (this.recurrence.end) {
this.setParam('REND', time.formatDateNoUtc(this.recurrence.end, FORMAT.DATE))
} else {
const days = time.getRecurrenceLengthDays(this.recurrence)
const rend = time.incrementDate(this.end, Math.ceil(days))

this.setParam('REND', time.formatDateNoUtc(rend, FORMAT.DATE))
}
}
}

/**
* Generates the Yahoo! Calendar data.
*
Expand Down
142 changes: 40 additions & 102 deletions src/__tests__/YahooCalendar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as queryString from 'query-string'
import { FORMAT, RECURRENCE, URL } from '../constants'
import { FORMAT, URL } from '../constants'
import CalendarBase from '../CalendarBase'
import YahooCalendar from '../YahooCalendar'
import time from '../utils/time'
Expand Down Expand Up @@ -42,37 +42,37 @@ describe('YahooCalendar', () => {
start: new Date('2019-07-04T19:00:00.000')
}

describe('no recurrence', () => {
it('should format the query string without an end time', () => {
const obj = new YahooCalendar(testOpts)
const result = obj.render()
it('should format the query string without an end time', () => {
const obj = new YahooCalendar(testOpts)
const result = obj.render()

const querystring = result.split('?')[1]
const params = queryString.parse(querystring)
const expectedObj = {
v: '60',
title: 'Fun Party',
desc: 'BYOB',
in_loc: 'New York',
dur: 'allday',
st: time.formatDate(testOpts.start, FORMAT.DATE)
}
expect(params).toMatchObject(expectedObj)
expect(expectedObj).toMatchObject(params)
})
const querystring = result.split('?')[1]
const params = queryString.parse(querystring)
const expectedObj = {
v: '60',
title: 'Fun Party',
desc: 'BYOB',
in_loc: 'New York',
dur: 'allday',
st: time.formatDate(testOpts.start, FORMAT.DATE)
}
expect(params).toMatchObject(expectedObj)
expect(expectedObj).toMatchObject(params)
})
})

describe('recurrence', () => {
it('should format the query string with start and end times containing only their dates', () => {
const recurrenceEnd = new Date('2019-07-10T19:00:00.000')
const obj = new YahooCalendar({
...testOpts,
recurrence: {
frequency: RECURRENCE.FREQUENCY.DAILY,
interval: 1,
end: recurrenceEnd
}
})
describe('is not all day event', () => {
const testOpts = {
title: 'Fun Party',
description: 'BYOB',
location: 'New York',
start: new Date('2019-07-04T19:00:00.000'),
end: new Date('2019-07-04T21:00:00.000') // two-hour long event (19h to 21h)
}

describe('when the duration of the event spans 99 hours or fewer', () => {
it('should format the query string with the time parameters with the start time and duration of two hours', () => {
const obj = new YahooCalendar(testOpts)
const result = obj.render()

const querystring = result.split('?')[1]
Expand All @@ -82,81 +82,20 @@ describe('YahooCalendar', () => {
title: 'Fun Party',
desc: 'BYOB',
in_loc: 'New York',
dur: 'allday',
st: time.formatDate(testOpts.start, FORMAT.DATE),
RPAT: '01Dy',
REND: time.formatDate(recurrenceEnd, FORMAT.DATE)
st: time.formatDateNoUtc(testOpts.start, FORMAT.NO_UTC_FULL),
dur: '0200'
}
expect(params).toMatchObject(expectedObj)
expect(expectedObj).toMatchObject(params)
})
})
})

describe('is not all day event', () => {
const testOpts = {
title: 'Fun Party',
description: 'BYOB',
location: 'New York',
start: new Date('2019-07-04T19:00:00.000'),
end: new Date('2019-07-04T21:00:00.000') // two-hour long event (19h to 21h)
}

describe('no recurrence', () => {
describe('when the duration of the event spans 99 hours or fewer', () => {
it('should format the query string with the time parameters with the start time and duration of two hours', () => {
const obj = new YahooCalendar(testOpts)
const result = obj.render()

const querystring = result.split('?')[1]
const params = queryString.parse(querystring)
const expectedObj = {
v: '60',
title: 'Fun Party',
desc: 'BYOB',
in_loc: 'New York',
st: time.formatDateNoUtc(testOpts.start, FORMAT.NO_UTC_FULL),
dur: '0200'
}
expect(params).toMatchObject(expectedObj)
expect(expectedObj).toMatchObject(params)
})
})
describe('when the duration of the event spans longer than 99 hours', () => {
it('should format the query string with the time parameters in start/end timestamps', () => {
const start = new Date('2019-07-04T19:00:00.000')
const end = new Date('2019-07-08T23:00:00.000') // one-hundred-hour long event, (four days, three hours)

describe('when the duration of the event spans longer than 99 hours', () => {
it('should format the query string with the time parameters in start/end timestamps', () => {
const start = new Date('2019-07-04T19:00:00.000')
const end = new Date('2019-07-08T23:00:00.000') // one-hundred-hour long event, (four days, three hours)

const obj = new YahooCalendar({ ...testOpts, start, end })
const result = obj.render()

const querystring = result.split('?')[1]
const params = queryString.parse(querystring)
const expectedObj = {
v: '60',
title: 'Fun Party',
desc: 'BYOB',
in_loc: 'New York',
st: time.formatDateNoUtc(start, FORMAT.NO_UTC_FULL),
et: time.formatDateNoUtc(end, FORMAT.NO_UTC_FULL)
}
expect(params).toMatchObject(expectedObj)
expect(expectedObj).toMatchObject(params)
})
})
})

describe('recurrence', () => {
it('should format the query string with RPAT and REND params', () => {
const recurrenceEnd = new Date('2019-07-10T19:00:00.000')
const obj = new YahooCalendar({
...testOpts,
recurrence: {
frequency: RECURRENCE.FREQUENCY.DAILY,
interval: 1,
end: recurrenceEnd
}
})
const obj = new YahooCalendar({ ...testOpts, start, end })
const result = obj.render()

const querystring = result.split('?')[1]
Expand All @@ -166,12 +105,11 @@ describe('YahooCalendar', () => {
title: 'Fun Party',
desc: 'BYOB',
in_loc: 'New York',
dur: '0200',
st: time.formatDateNoUtc(testOpts.start, FORMAT.NO_UTC_FULL),
RPAT: '01Dy',
REND: time.formatDateNoUtc(recurrenceEnd, FORMAT.DATE)
st: time.formatDateNoUtc(start, FORMAT.NO_UTC_FULL),
et: time.formatDateNoUtc(end, FORMAT.NO_UTC_FULL)
}
expect(params).toMatchObject(expectedObj)
expect(expectedObj).toMatchObject(params)
})
})
})
Expand Down
113 changes: 0 additions & 113 deletions src/utils/__tests__/yahoo.spec.ts

This file was deleted.

Loading

0 comments on commit 598a53d

Please sign in to comment.