2020-02-07 17:27:45 +01:00
|
|
|
// Vikunja is a to-do list application to facilitate your life.
|
2020-01-09 18:33:22 +01:00
|
|
|
// Copyright 2018-2020 Vikunja and contributors. All rights reserved.
|
2018-12-16 14:21:32 +01:00
|
|
|
//
|
2019-12-04 20:39:56 +01:00
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2018-12-16 14:21:32 +01:00
|
|
|
//
|
2019-12-04 20:39:56 +01:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
2018-12-16 14:21:32 +01:00
|
|
|
//
|
2019-12-04 20:39:56 +01:00
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-12-16 14:21:32 +01:00
|
|
|
|
|
|
|
package caldav
|
|
|
|
|
2020-06-27 19:04:01 +02:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
2020-10-11 22:10:03 +02:00
|
|
|
|
|
|
|
"code.vikunja.io/api/pkg/config"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-06-27 19:04:01 +02:00
|
|
|
)
|
2018-12-16 14:21:32 +01:00
|
|
|
|
|
|
|
func TestParseEvents(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
config *Config
|
|
|
|
events []*Event
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
wantCaldavevents string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Test caldavparsing without reminders",
|
|
|
|
args: args{
|
|
|
|
config: &Config{
|
|
|
|
Name: "test",
|
|
|
|
ProdID: "RandomProdID which is not random",
|
|
|
|
},
|
|
|
|
events: []*Event{
|
|
|
|
{
|
2020-02-08 13:48:49 +01:00
|
|
|
Summary: "Event #1",
|
|
|
|
Description: "Lorem Ipsum",
|
|
|
|
UID: "randommduid",
|
2020-06-27 19:04:01 +02:00
|
|
|
Timestamp: time.Unix(1543626724, 0).In(config.GetTimeZone()),
|
|
|
|
Start: time.Unix(1543626724, 0).In(config.GetTimeZone()),
|
|
|
|
End: time.Unix(1543627824, 0).In(config.GetTimeZone()),
|
2018-12-16 14:21:32 +01:00
|
|
|
},
|
|
|
|
{
|
2020-02-08 13:48:49 +01:00
|
|
|
Summary: "Event #2",
|
|
|
|
UID: "randommduidd",
|
2020-06-27 19:04:01 +02:00
|
|
|
Timestamp: time.Unix(1543726724, 0).In(config.GetTimeZone()),
|
|
|
|
Start: time.Unix(1543726724, 0).In(config.GetTimeZone()),
|
|
|
|
End: time.Unix(1543738724, 0).In(config.GetTimeZone()),
|
2018-12-16 14:21:32 +01:00
|
|
|
},
|
|
|
|
{
|
2020-02-08 13:48:49 +01:00
|
|
|
Summary: "Event #3 with empty uid",
|
|
|
|
UID: "20181202T0600242aaef4a81d770c1e775e26bc5abebc87f1d3d7bffaa83",
|
2020-06-27 19:04:01 +02:00
|
|
|
Timestamp: time.Unix(1543726824, 0).In(config.GetTimeZone()),
|
|
|
|
Start: time.Unix(1543726824, 0).In(config.GetTimeZone()),
|
|
|
|
End: time.Unix(1543727000, 0).In(config.GetTimeZone()),
|
2018-12-16 14:21:32 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantCaldavevents: `BEGIN:VCALENDAR
|
|
|
|
VERSION:2.0
|
|
|
|
METHOD:PUBLISH
|
|
|
|
X-PUBLISHED-TTL:PT4H
|
|
|
|
X-WR-CALNAME:test
|
|
|
|
PRODID:-//RandomProdID which is not random//EN
|
|
|
|
BEGIN:VEVENT
|
|
|
|
UID:randommduid
|
|
|
|
SUMMARY:Event #1
|
|
|
|
DESCRIPTION:Lorem Ipsum
|
|
|
|
DTSTAMP:20181201T011204
|
|
|
|
DTSTART:20181201T011204
|
|
|
|
DTEND:20181201T013024
|
|
|
|
END:VEVENT
|
|
|
|
BEGIN:VEVENT
|
|
|
|
UID:randommduidd
|
|
|
|
SUMMARY:Event #2
|
|
|
|
DESCRIPTION:
|
|
|
|
DTSTAMP:20181202T045844
|
|
|
|
DTSTART:20181202T045844
|
|
|
|
DTEND:20181202T081844
|
|
|
|
END:VEVENT
|
|
|
|
BEGIN:VEVENT
|
|
|
|
UID:20181202T0600242aaef4a81d770c1e775e26bc5abebc87f1d3d7bffaa83
|
|
|
|
SUMMARY:Event #3 with empty uid
|
|
|
|
DESCRIPTION:
|
|
|
|
DTSTAMP:20181202T050024
|
|
|
|
DTSTART:20181202T050024
|
|
|
|
DTEND:20181202T050320
|
|
|
|
END:VEVENT
|
|
|
|
END:VCALENDAR`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Test caldavparsing with reminders",
|
|
|
|
args: args{
|
|
|
|
config: &Config{
|
|
|
|
Name: "test2",
|
|
|
|
ProdID: "RandomProdID which is not random",
|
|
|
|
},
|
|
|
|
events: []*Event{
|
|
|
|
{
|
2020-02-08 13:48:49 +01:00
|
|
|
Summary: "Event #1",
|
|
|
|
Description: "Lorem Ipsum",
|
|
|
|
UID: "randommduid",
|
2020-06-27 19:04:01 +02:00
|
|
|
Timestamp: time.Unix(1543626724, 0).In(config.GetTimeZone()),
|
|
|
|
Start: time.Unix(1543626724, 0).In(config.GetTimeZone()),
|
|
|
|
End: time.Unix(1543627824, 0).In(config.GetTimeZone()),
|
2018-12-16 14:21:32 +01:00
|
|
|
Alarms: []Alarm{
|
2020-06-27 19:04:01 +02:00
|
|
|
{Time: time.Unix(1543626524, 0).In(config.GetTimeZone())},
|
|
|
|
{Time: time.Unix(1543626224, 0).In(config.GetTimeZone())},
|
|
|
|
{Time: time.Unix(1543626024, 0)},
|
2018-12-16 14:21:32 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-02-08 13:48:49 +01:00
|
|
|
Summary: "Event #2",
|
|
|
|
UID: "randommduidd",
|
2020-06-27 19:04:01 +02:00
|
|
|
Timestamp: time.Unix(1543726724, 0).In(config.GetTimeZone()),
|
|
|
|
Start: time.Unix(1543726724, 0).In(config.GetTimeZone()),
|
|
|
|
End: time.Unix(1543738724, 0).In(config.GetTimeZone()),
|
2018-12-16 14:21:32 +01:00
|
|
|
Alarms: []Alarm{
|
2020-06-27 19:04:01 +02:00
|
|
|
{Time: time.Unix(1543626524, 0).In(config.GetTimeZone())},
|
|
|
|
{Time: time.Unix(1543626224, 0).In(config.GetTimeZone())},
|
|
|
|
{Time: time.Unix(1543626024, 0).In(config.GetTimeZone())},
|
2018-12-16 14:21:32 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-02-08 13:48:49 +01:00
|
|
|
Summary: "Event #3 with empty uid",
|
2020-06-27 19:04:01 +02:00
|
|
|
Timestamp: time.Unix(1543726824, 0).In(config.GetTimeZone()),
|
|
|
|
Start: time.Unix(1543726824, 0).In(config.GetTimeZone()),
|
|
|
|
End: time.Unix(1543727000, 0).In(config.GetTimeZone()),
|
2018-12-16 14:21:32 +01:00
|
|
|
Alarms: []Alarm{
|
2020-06-27 19:04:01 +02:00
|
|
|
{Time: time.Unix(1543626524, 0).In(config.GetTimeZone())},
|
|
|
|
{Time: time.Unix(1543626224, 0).In(config.GetTimeZone())},
|
|
|
|
{Time: time.Unix(1543626024, 0).In(config.GetTimeZone())},
|
|
|
|
{Time: time.Unix(1543826824, 0).In(config.GetTimeZone())},
|
2018-12-16 14:21:32 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-02-08 13:48:49 +01:00
|
|
|
Summary: "Event #4 without any",
|
2020-06-27 19:04:01 +02:00
|
|
|
Timestamp: time.Unix(1543726824, 0),
|
|
|
|
Start: time.Unix(1543726824, 0),
|
|
|
|
End: time.Unix(1543727000, 0),
|
2018-12-16 14:21:32 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantCaldavevents: `BEGIN:VCALENDAR
|
|
|
|
VERSION:2.0
|
|
|
|
METHOD:PUBLISH
|
|
|
|
X-PUBLISHED-TTL:PT4H
|
|
|
|
X-WR-CALNAME:test2
|
|
|
|
PRODID:-//RandomProdID which is not random//EN
|
|
|
|
BEGIN:VEVENT
|
|
|
|
UID:randommduid
|
|
|
|
SUMMARY:Event #1
|
|
|
|
DESCRIPTION:Lorem Ipsum
|
|
|
|
DTSTAMP:20181201T011204
|
|
|
|
DTSTART:20181201T011204
|
|
|
|
DTEND:20181201T013024
|
|
|
|
BEGIN:VALARM
|
2020-06-27 19:04:01 +02:00
|
|
|
TRIGGER:-PT3M20S
|
2018-12-16 14:21:32 +01:00
|
|
|
ACTION:DISPLAY
|
|
|
|
DESCRIPTION:Event #1
|
|
|
|
END:VALARM
|
|
|
|
BEGIN:VALARM
|
2020-06-27 19:04:01 +02:00
|
|
|
TRIGGER:-PT8M20S
|
2018-12-16 14:21:32 +01:00
|
|
|
ACTION:DISPLAY
|
|
|
|
DESCRIPTION:Event #1
|
|
|
|
END:VALARM
|
|
|
|
BEGIN:VALARM
|
2020-06-27 19:04:01 +02:00
|
|
|
TRIGGER:-PT11M40S
|
2018-12-16 14:21:32 +01:00
|
|
|
ACTION:DISPLAY
|
|
|
|
DESCRIPTION:Event #1
|
|
|
|
END:VALARM
|
|
|
|
END:VEVENT
|
|
|
|
BEGIN:VEVENT
|
|
|
|
UID:randommduidd
|
|
|
|
SUMMARY:Event #2
|
|
|
|
DESCRIPTION:
|
|
|
|
DTSTAMP:20181202T045844
|
|
|
|
DTSTART:20181202T045844
|
|
|
|
DTEND:20181202T081844
|
|
|
|
BEGIN:VALARM
|
2020-06-27 19:04:01 +02:00
|
|
|
TRIGGER:-PT27H50M0S
|
2018-12-16 14:21:32 +01:00
|
|
|
ACTION:DISPLAY
|
|
|
|
DESCRIPTION:Event #2
|
|
|
|
END:VALARM
|
|
|
|
BEGIN:VALARM
|
2020-06-27 19:04:01 +02:00
|
|
|
TRIGGER:-PT27H55M0S
|
2018-12-16 14:21:32 +01:00
|
|
|
ACTION:DISPLAY
|
|
|
|
DESCRIPTION:Event #2
|
|
|
|
END:VALARM
|
|
|
|
BEGIN:VALARM
|
2020-06-27 19:04:01 +02:00
|
|
|
TRIGGER:-PT27H58M20S
|
2018-12-16 14:21:32 +01:00
|
|
|
ACTION:DISPLAY
|
|
|
|
DESCRIPTION:Event #2
|
|
|
|
END:VALARM
|
|
|
|
END:VEVENT
|
|
|
|
BEGIN:VEVENT
|
|
|
|
UID:20181202T0500242aaef4a81d770c1e775e26bc5abebc87f1d3d7bffaa83
|
|
|
|
SUMMARY:Event #3 with empty uid
|
|
|
|
DESCRIPTION:
|
|
|
|
DTSTAMP:20181202T050024
|
|
|
|
DTSTART:20181202T050024
|
|
|
|
DTEND:20181202T050320
|
|
|
|
BEGIN:VALARM
|
2020-06-27 19:04:01 +02:00
|
|
|
TRIGGER:-PT27H51M40S
|
2018-12-16 14:21:32 +01:00
|
|
|
ACTION:DISPLAY
|
|
|
|
DESCRIPTION:Event #3 with empty uid
|
|
|
|
END:VALARM
|
|
|
|
BEGIN:VALARM
|
2020-06-27 19:04:01 +02:00
|
|
|
TRIGGER:-PT27H56M40S
|
2018-12-16 14:21:32 +01:00
|
|
|
ACTION:DISPLAY
|
|
|
|
DESCRIPTION:Event #3 with empty uid
|
|
|
|
END:VALARM
|
|
|
|
BEGIN:VALARM
|
2020-06-27 19:04:01 +02:00
|
|
|
TRIGGER:-PT28H0M0S
|
2018-12-16 14:21:32 +01:00
|
|
|
ACTION:DISPLAY
|
|
|
|
DESCRIPTION:Event #3 with empty uid
|
|
|
|
END:VALARM
|
|
|
|
BEGIN:VALARM
|
2020-06-27 19:04:01 +02:00
|
|
|
TRIGGER:PT27H46M40S
|
2018-12-16 14:21:32 +01:00
|
|
|
ACTION:DISPLAY
|
|
|
|
DESCRIPTION:Event #3 with empty uid
|
|
|
|
END:VALARM
|
|
|
|
END:VEVENT
|
|
|
|
BEGIN:VEVENT
|
|
|
|
UID:20181202T050024ae7548ce9556df85038abe90dc674d4741a61ce74d1cf
|
|
|
|
SUMMARY:Event #4 without any
|
|
|
|
DESCRIPTION:
|
|
|
|
DTSTAMP:20181202T050024
|
|
|
|
DTSTART:20181202T050024
|
|
|
|
DTEND:20181202T050320
|
|
|
|
END:VEVENT
|
|
|
|
END:VCALENDAR`,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2020-06-27 19:04:01 +02:00
|
|
|
gotCaldavevents := ParseEvents(tt.args.config, tt.args.events)
|
|
|
|
assert.Equal(t, gotCaldavevents, tt.wantCaldavevents)
|
2018-12-16 14:21:32 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|