From 683b25803cdc98e05534a4e273f77c9ae9fcdd9b Mon Sep 17 00:00:00 2001 From: Jannis R Date: Sun, 5 Feb 2023 20:06:04 +0100 Subject: [PATCH] createEvents: return iCal string with 0 events (#148) --- src/index.js | 16 ++++++++++++++++ test/index.spec.js | 14 ++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/index.js b/src/index.js index 5bd09cf..8462e4f 100644 --- a/src/index.js +++ b/src/index.js @@ -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) } diff --git a/test/index.spec.js b/test/index.spec.js index 9d62da2..2738a46 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -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', () => { @@ -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() + }) + }) }) }) }) \ No newline at end of file