diff --git a/src/index.js b/src/index.js index fe8f93d..7955e98 100644 --- a/src/index.js +++ b/src/index.js @@ -11,7 +11,7 @@ export function createEvent (attributes, cb) { } if (!cb) { - // No callback, so return a synchronous pattern + // No callback, so return error or value in an object const { error, value } = validateEvent(buildEvent(attributes)) if (error) return { error, value } diff --git a/src/pipeline/format.js b/src/pipeline/format.js index 397a3f1..3d4ed83 100644 --- a/src/pipeline/format.js +++ b/src/pipeline/format.js @@ -37,7 +37,7 @@ export default function formatEvent (attributes = {}) { icsFormat += `SUMMARY:${title}\r\n` icsFormat += `DTSTAMP:${timestamp}\r\n` icsFormat += `DTSTART:${setDate(start, startType)}\r\n` - icsFormat += end ? `DTEND:${end}\r\n` : '' + icsFormat += end ? `DTEND:${setDate(end, startType)}\r\n` : '' icsFormat += description ? `DESCRIPTION:${description}\r\n` : '' icsFormat += url ? `URL:${url}\r\n` : '' icsFormat += geo ? `GEO:${setGeolocation(geo)}\r\n` : '' diff --git a/test/pipeline/build.spec.js b/test/pipeline/build.spec.js index d06f172..8ec4cdf 100644 --- a/test/pipeline/build.spec.js +++ b/test/pipeline/build.spec.js @@ -32,33 +32,20 @@ describe('pipeline.build properties', () => { expect(event.uid).to.equal('myuid') }) }) - describe('start', () => { - xit('defaults to UTC date-time format', () => { - const event = buildEvent({ start: [2017, 1, 19, 1, 30] }) - expect(event.start).to.equal('20170119T083000Z') - expect(event.title).to.equal('Untitled event') - }) - xit('sets local time when specified', () => { + describe('start and end', () => { + it('defaults to UTC date-time format', () => { const event = buildEvent({ start: [2017, 1, 19, 1, 30], - startType: 'local' + end: [2017, 1, 19, 12, 0] }) - console.log(event) - expect(event.start).to.equal('20170119T013000') + expect(event.start).to.be.an('array') + expect(event.end).to.be.an('array') }) }) describe('end', () => { - xit('defaults to UTC date-time format', () => { - const event = buildEvent({ end: [2017, 0, 19, 22, 0] }) - expect(event.end).to.equal('20170120T050000Z') - expect(event.title).to.equal('Untitled event') - }) - xit('sets local time when local start time specified', () => { - const event = buildEvent({ - end: [2017, 0, 19, 1, 30], - startType: 'local' - }) - expect(event.end).to.equal('20170119T013000') + it('defaults to UTC date-time format', () => { + const event = buildEvent({ start: [2017, 1, 19, 1, 30] }) + expect(event.start).to.be.an('array') }) }) describe('description', () => { diff --git a/test/pipeline/format.spec.js b/test/pipeline/format.spec.js index dc15bc6..d262a6a 100644 --- a/test/pipeline/format.spec.js +++ b/test/pipeline/format.spec.js @@ -5,7 +5,7 @@ import { } from '../../src/pipeline' describe('pipeline.formatEvent', () => { - xit('writes default values when no attributes passed', () => { + it('writes default values when no attributes passed', () => { const event = buildEvent() const formattedEvent = formatEvent(event) expect(formattedEvent).to.contain('BEGIN:VCALENDAR') @@ -15,6 +15,7 @@ describe('pipeline.formatEvent', () => { expect(formattedEvent).to.contain('SUMMARY:Untitled event') expect(formattedEvent).to.contain('UID:') expect(formattedEvent).to.contain('DTSTART:') + expect(formattedEvent).to.contain('DURATION:') expect(formattedEvent).to.contain('DTSTAMP:20') expect(formattedEvent).to.contain('END:VEVENT') expect(formattedEvent).to.contain('END:VCALENDAR') @@ -24,6 +25,16 @@ describe('pipeline.formatEvent', () => { const formattedEvent = formatEvent(event) expect(formattedEvent).to.contain('SUMMARY:foo bar') }) + it('writes a start date-time', () => { + const event = buildEvent({ start: [2017, 5, 15, 10, 0] }) + const formattedEvent = formatEvent(event) + expect(formattedEvent).to.contain('DTSTART:2017051') + }) + it('writes an end date-time', () => { + const event = buildEvent({ end: [2017, 5, 15, 11, 0] }) + const formattedEvent = formatEvent(event) + expect(formattedEvent).to.contain('DTEND:2017051') + }) it('writes a description', () => { const event = buildEvent({ description: 'bar baz' }) const formattedEvent = formatEvent(event)