Skip to content

Commit

Permalink
fix DTEND formatting, loosen some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgibbons committed Oct 1, 2017
1 parent a5a4d12 commit 6f596f4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion src/pipeline/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -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` : ''
Expand Down
29 changes: 8 additions & 21 deletions test/pipeline/build.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
13 changes: 12 additions & 1 deletion test/pipeline/format.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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)
Expand Down

0 comments on commit 6f596f4

Please sign in to comment.