Skip to content

Commit

Permalink
createEvents: return iCal string with 0 events (adamgibbons#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst authored Feb 5, 2023
1 parent df7392c commit 683b258
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ export function createEvents (events, cb) {
return { error: Error('one argument is required'), value: null }
}

if (events.length === 0) {
const {error, value: dummy} = createEvent({
start: [2000, 10, 5, 5, 0],
duration: { hours: 1 }
})
if (error) return {error, value: null}

return {
error: null,
value: (
dummy.slice(0, dummy.indexOf('BEGIN:VEVENT')) +
dummy.slice(dummy.indexOf('END:VEVENT') + 10 + 2)
)
}
}

if (events.length === 1) {
return createEvent(events[0], cb)
}
Expand Down
14 changes: 14 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ describe('ics', () => {
expect(error).to.exist
expect(value).not.to.exist
})

it('returns an iCal string when passed 0 events', () => {
const { error, value } = createEvents([])
expect(error).to.be.null
expect(value).to.contain('BEGIN:VCALENDAR')
})
})

describe('when a callback is provided', () => {
Expand All @@ -87,6 +93,14 @@ describe('ics', () => {
done()
})
})

it('returns an iCal string when passed 0 events', () => {
createEvents([], (error, value) => {
expect(error).to.be.null
expect(value).to.contain('BEGIN:VCALENDAR')
done()
})
})
})
})
})

0 comments on commit 683b258

Please sign in to comment.