Skip to content

Commit a165de5

Browse files
authored
fix: rsvp template add (#7)
1 parent 3097f3c commit a165de5

File tree

3 files changed

+62
-6
lines changed

3 files changed

+62
-6
lines changed

generator_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,59 @@ END:VCALENDAR`
269269
t.Errorf("Generate() = %v, want %v", gotIcs, expectedIcs)
270270
}
271271
}
272+
273+
func TestGenerateWithRSVP(t *testing.T) {
274+
event := &Event{
275+
Class: Classification_PUBLIC,
276+
Summary: "Event Name",
277+
Description: "Event Description",
278+
Status: EventStatus_CONFIRMED,
279+
Location: "location",
280+
DtStart: time.Date(2019, time.January, 1, 9, 0, 0, 0, time.UTC),
281+
DtEnd: time.Date(2019, time.January, 1, 9, 30, 0, 0, time.UTC),
282+
Transparency: OPAQUE,
283+
Attendees: []Attendee{{
284+
CommonName: "John Wick",
285+
EmailAddress: "john.wick@gmail.com",
286+
Role: REQUIRED,
287+
PartStatus: AttendeeStatus_ACCEPTED,
288+
CuType: INDIVIDUAL,
289+
Rsvp: Rsvp_True,
290+
}},
291+
Organizer: Attendee{
292+
CommonName: "My Calendar",
293+
EmailAddress: "my@calendar.com",
294+
},
295+
UID: "123123123",
296+
}
297+
298+
gotIcs, err := Generate("com.calendar.my", event)
299+
if err != nil {
300+
t.Errorf("Generate() error = %v", err)
301+
return
302+
}
303+
304+
expectedIcs := `BEGIN:VCALENDAR
305+
PRODID:com.calendar.my
306+
METHOD:REQUEST
307+
VERSION:2.0
308+
BEGIN:VEVENT
309+
ORGANIZER;CN="My Calendar":mailto:my@calendar.com
310+
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;CN="John Wick";RSVP=TRUE:mailto:john.wick@gmail.com
311+
LOCATION:location
312+
DTSTAMP:` + event.dtStamp + `
313+
DTSTART:20190101T090000Z
314+
DTEND:20190101T093000Z
315+
SUMMARY:Event Name
316+
DESCRIPTION:Event Description
317+
CLASS:PUBLIC
318+
UID:313233313233313233
319+
STATUS:CONFIRMED
320+
END:VEVENT
321+
END:VCALENDAR`
322+
323+
if gotIcs != expectedIcs {
324+
t.Errorf("Generate() = %v, want %v", gotIcs, expectedIcs)
325+
}
326+
327+
}

objects.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type Attendee struct {
5959
PartStatus AttendeeStatus
6060
//RSVP is by default NO
6161
CuType CalendarUserType
62-
Rsvp RSVP
62+
Rsvp Rsvp
6363
}
6464

6565
type Role string
@@ -71,7 +71,7 @@ const (
7171
type AttendeeStatus string
7272

7373
const (
74-
AttendeeStatus_NeedAction AttendeeStatus = "NEEDS-ACTION"
74+
AttendeeStatus_NEEDACTION AttendeeStatus = "NEEDS-ACTION"
7575
AttendeeStatus_TENTATIVE AttendeeStatus = "TENTATIVE"
7676
AttendeeStatus_ACCEPTED AttendeeStatus = "ACCEPTED"
7777
AttendeeStatus_DECLINED AttendeeStatus = "DECLINED"
@@ -86,9 +86,9 @@ const (
8686
// This is related to PartStat
8787
// https://datatracker.ietf.org/doc/html/rfc5545#section-3.2.12
8888
// https://datatracker.ietf.org/doc/html/rfc5545#section-3.2.17
89-
type RSVP string
89+
type Rsvp string
9090

9191
const (
92-
Rsvp_False RSVP = "FALSE"
93-
Rsvp_True RSVP = "TRUE"
92+
Rsvp_False Rsvp = "FALSE"
93+
Rsvp_True Rsvp = "TRUE"
9494
)

templates.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ VERSION:2.0
99

1010
const vevent = `BEGIN:VEVENT
1111
ORGANIZER;CN="{{.Organizer.CommonName}}":mailto:{{.Organizer.EmailAddress}}
12-
{{range $at := .Attendees}}ATTENDEE;CUTYPE={{$at.CuType}};ROLE={{$at.Role}};PARTSTAT={{$at.PartStatus}};CN="{{$at.CommonName}}";RSVP=FALSE:mailto:{{$at.EmailAddress}}
12+
{{range $at := .Attendees}}ATTENDEE;CUTYPE={{$at.CuType}};ROLE={{$at.Role}};PARTSTAT={{$at.PartStatus}};CN="{{$at.CommonName}}";RSVP={{$at.Rsvp}}:mailto:{{$at.EmailAddress}}
1313
{{end}}LOCATION:{{.Location}}
1414
DTSTAMP:{{.DtStamp}}
1515
DTSTART:{{.DtStart}}

0 commit comments

Comments
 (0)