Commit 71111249 authored by Sebastian Pekarek's avatar Sebastian Pekarek
Browse files

Repeat by: tests

parent 05514359
......@@ -227,7 +227,7 @@ var ICalEvent = function(_data) {
if(repeating.byDay) {
if(!Array.isArray(repeating.byDay)){
throw '`repeating.byDay` must be an Array of day symbols!';
repeating.byDay = [repeating.byDay];
}
data.repeating.byDay = [];
......@@ -243,7 +243,7 @@ var ICalEvent = function(_data) {
if(repeating.byMonth) {
if(!Array.isArray(repeating.byMonth)){
throw '`repeating.byMonth` must be an Array of numbers!';
repeating.byMonth = [repeating.byMonth];
}
data.repeating.byMonth = [];
......@@ -258,7 +258,7 @@ var ICalEvent = function(_data) {
if(repeating.byMonthDay) {
if(!Array.isArray(repeating.byMonthDay)){
throw '`repeating.byMonthDay` must be an Array of numbers!';
repeating.byMonthDay = [repeating.byMonthDay];
}
data.repeating.byMonthDay = [];
......
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//sebbo.net//ical-generator.tests//EN
BEGIN:VEVENT
UID:20131004T223930Z-1@sebbo.net
DTSTAMP:20131004T233453Z
DTSTART:20131004T223930Z
DTEND:20131006T231500Z
RRULE:FREQ=MONTHLY;BYMONTH=1,4,7,10
SUMMARY:repeating by month
END:VEVENT
BEGIN:VEVENT
UID:20131004T223930Z-2@sebbo.net
DTSTAMP:20131004T233453Z
DTSTART:20131004T223930Z
DTEND:20131006T231500Z
RRULE:FREQ=DAILY;COUNT=2;BYDAY=MO,WE,FR
SUMMARY:repeating on Mo/We/Fr\, twice
END:VEVENT
BEGIN:VEVENT
UID:20131004T223930Z-3@sebbo.net
DTSTAMP:20131004T233453Z
DTSTART:20131004T223930Z
DTEND:20131006T231500Z
RRULE:FREQ=DAILY;INTERVAL=1;BYMONTHDAY=1,15
SUMMARY:repeating on 1st and 15th
END:VEVENT
END:VCALENDAR
\ No newline at end of file
......@@ -625,6 +625,93 @@ describe('ical-generator 0.2.x / ICalCalendar', function() {
});
}, /`repeating\.until` must be a Date Object/);
});
it('should throw error when repeating.byDay is not valid', function() {
var cal = ical();
assert.throws(function() {
cal.createEvent({
start: new Date(),
end: new Date(),
summary: 'test',
repeating: {
freq: 'DAILY',
interval: 2,
byDay: 'FOO'
}
});
}, /`repeating\.byDay` contains invalid value `FOO`/);
assert.throws(function() {
cal.createEvent({
start: new Date(),
end: new Date(),
summary: 'test',
repeating: {
freq: 'DAILY',
interval: 2,
byDay: ['SU', 'BAR', 'th']
}
});
}, /`repeating\.byDay` contains invalid value `BAR`/);
});
it('should throw error when repeating.byMonth is not valid', function() {
var cal = ical();
assert.throws(function() {
cal.createEvent({
start: new Date(),
end: new Date(),
summary: 'test',
repeating: {
freq: 'DAILY',
interval: 2,
byMonth: 'FOO'
}
});
}, /`repeating\.byMonth` contains invalid value `FOO`/);
assert.throws(function() {
cal.createEvent({
start: new Date(),
end: new Date(),
summary: 'test',
repeating: {
freq: 'DAILY',
interval: 2,
byMonth: [1, 14, 7]
}
});
}, /`repeating\.byMonth` contains invalid value `14`/);
});
it('should throw error when repeating.byMonthDay is not valid', function() {
var cal = ical();
assert.throws(function() {
cal.createEvent({
start: new Date(),
end: new Date(),
summary: 'test',
repeating: {
freq: 'DAILY',
interval: 2,
byMonthDay: 'FOO'
}
});
}, /`repeating\.byMonthDay` contains invalid value `FOO`/);
assert.throws(function() {
cal.createEvent({
start: new Date(),
end: new Date(),
summary: 'test',
repeating: {
freq: 'DAILY',
interval: 2,
byMonthDay: [1, 32, 15]
}
});
}, /`repeating\.byMonthDay` contains invalid value `32`/);
});
});
describe('summary()', function() {
......@@ -1008,7 +1095,7 @@ describe('ical-generator 0.2.x / ICalCalendar', function() {
assert.equal(cal.toString(), fs.readFileSync(__dirname + '/results/generate_03.ics', 'utf8'));
});
it('case #4 (repeating)', function() {
it('case #7 (repeating: byDay, byMonth, byMonthDay)', function() {
var cal = ical({domain: 'sebbo.net', prodId: '//sebbo.net//ical-generator.tests//EN'});
cal.events([
{
......@@ -1018,7 +1105,8 @@ describe('ical-generator 0.2.x / ICalCalendar', function() {
stamp: new Date('Fr Oct 04 2013 23:34:53 UTC'),
summary: 'repeating by month',
repeating: {
freq: 'monthly'
freq: 'monthly',
byMonth: [1, 4, 7, 10]
}
},
{
......@@ -1026,10 +1114,11 @@ describe('ical-generator 0.2.x / ICalCalendar', function() {
start: new Date('Fr Oct 04 2013 22:39:30 UTC'),
end: new Date('Fr Oct 06 2013 23:15:00 UTC'),
stamp: new Date('Fr Oct 04 2013 23:34:53 UTC'),
summary: 'repeating by day, twice',
summary: 'repeating on Mo/We/Fr, twice',
repeating: {
freq: 'DAILY',
count: 2
count: 2,
byDay: ['mo', 'we', 'fr']
}
},
{
......@@ -1037,17 +1126,17 @@ describe('ical-generator 0.2.x / ICalCalendar', function() {
start: new Date('Fr Oct 04 2013 22:39:30 UTC'),
end: new Date('Fr Oct 06 2013 23:15:00 UTC'),
stamp: new Date('Fr Oct 04 2013 23:34:53 UTC'),
summary: 'repeating by 3 weeks, until 2014',
summary: 'repeating on 1st and 15th',
repeating: {
freq: 'WEEKLY',
interval: 3,
until: new Date('We Jan 01 2014 00:00:00 UTC')
freq: 'DAILY',
interval: 1,
byMonthDay: [1, 15]
}
}
]);
/*jslint stupid: true */
assert.equal(cal.toString(), fs.readFileSync(__dirname + '/results/generate_04.ics', 'utf8'));
assert.equal(cal.toString(), fs.readFileSync(__dirname + '/results/generate_07.ics', 'utf8'));
});
it('case #5 (floating)', function() {
......@@ -1107,6 +1196,48 @@ describe('ical-generator 0.2.x / ICalCalendar', function() {
/*jslint stupid: true */
assert.equal(cal.toString(), fs.readFileSync(__dirname + '/results/generate_06.ics', 'utf8'));
});
it('case #4 (repeating)', function() {
var cal = ical({domain: 'sebbo.net', prodId: '//sebbo.net//ical-generator.tests//EN'});
cal.events([
{
id: '1',
start: new Date('Fr Oct 04 2013 22:39:30 UTC'),
end: new Date('Fr Oct 06 2013 23:15:00 UTC'),
stamp: new Date('Fr Oct 04 2013 23:34:53 UTC'),
summary: 'repeating by month',
repeating: {
freq: 'monthly'
}
},
{
id: '2',
start: new Date('Fr Oct 04 2013 22:39:30 UTC'),
end: new Date('Fr Oct 06 2013 23:15:00 UTC'),
stamp: new Date('Fr Oct 04 2013 23:34:53 UTC'),
summary: 'repeating by day, twice',
repeating: {
freq: 'DAILY',
count: 2
}
},
{
id: '3',
start: new Date('Fr Oct 04 2013 22:39:30 UTC'),
end: new Date('Fr Oct 06 2013 23:15:00 UTC'),
stamp: new Date('Fr Oct 04 2013 23:34:53 UTC'),
summary: 'repeating by 3 weeks, until 2014',
repeating: {
freq: 'WEEKLY',
interval: 3,
until: new Date('We Jan 01 2014 00:00:00 UTC')
}
}
]);
/*jslint stupid: true */
assert.equal(cal.toString(), fs.readFileSync(__dirname + '/results/generate_04.ics', 'utf8'));
});
});
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment