-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
transformation: add transformer to keep original event link
Closes #56
- Loading branch information
Showing
7 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package transformation | ||
|
||
import ( | ||
"fmt" | ||
"github.com/inovex/CalendarSync/internal/models" | ||
) | ||
|
||
type AddOriginalLink struct{} | ||
|
||
func (t *AddOriginalLink) Name() string { | ||
return "AddOriginalLink" | ||
} | ||
|
||
func (t *AddOriginalLink) Transform(source models.Event, sink models.Event) (models.Event, error) { | ||
if len(source.HTMLLink) > 0 { | ||
sink.Description = fmt.Sprintf("original event link: %s\n\n############\n%s", source.HTMLLink, sink.Description) | ||
} | ||
return sink, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package transformation | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/inovex/CalendarSync/internal/models" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// verify keep attendees | ||
func TestAddOriginalLink_Transform(t *testing.T) { | ||
source := models.Event{ | ||
ICalUID: "testId", | ||
ID: "testUid", | ||
Title: "foo", | ||
Description: "bar", | ||
HTMLLink: "https://foo.com/bar?calendarId=testId", | ||
} | ||
sink := models.NewSyncEvent(source) | ||
|
||
addOriginalLink := AddOriginalLink{} | ||
|
||
event, err := addOriginalLink.Transform(source, sink) | ||
|
||
assert.Nil(t, err) | ||
expectedEvent := models.Event{ | ||
ICalUID: "testId", | ||
ID: "testUid", | ||
Title: "CalendarSync Event", | ||
Description: "original event link: https://foo.com/bar?calendarId=testId\n\n############\n", | ||
} | ||
|
||
assert.Equal(t, expectedEvent, event) | ||
} | ||
|
||
func TestAddOriginalLink_Transform_WithKeepDescription(t *testing.T) { | ||
source := models.Event{ | ||
ICalUID: "testId", | ||
ID: "testUid", | ||
Title: "foo", | ||
Description: "bar", | ||
HTMLLink: "https://foo.com/bar?calendarId=testId", | ||
} | ||
sink := models.NewSyncEvent(source) | ||
|
||
keepDescription := KeepDescription{} | ||
addOriginalLink := AddOriginalLink{} | ||
|
||
sink, err := keepDescription.Transform(source, sink) | ||
Check failure on line 49 in internal/transformation/addOriginalLink_test.go GitHub Actions / GolangCI
|
||
event, err := addOriginalLink.Transform(source, sink) | ||
|
||
assert.Nil(t, err) | ||
expectedEvent := models.Event{ | ||
ICalUID: "testId", | ||
ID: "testUid", | ||
Title: "CalendarSync Event", | ||
Description: "original event link: https://foo.com/bar?calendarId=testId\n\n############\nbar", | ||
} | ||
|
||
assert.Equal(t, expectedEvent, event) | ||
} | ||
|
||
func TestAddOriginalLink_Transform_WithKeepDescriptionAndKeepMeetingLink(t *testing.T) { | ||
source := models.Event{ | ||
ICalUID: "testId", | ||
ID: "testUid", | ||
Title: "foo", | ||
Description: "bar", | ||
MeetingLink: "https://meetinglink.de", | ||
HTMLLink: "https://foo.com/bar?calendarId=testId", | ||
} | ||
sink := models.NewSyncEvent(source) | ||
|
||
keepDescription := KeepDescription{} | ||
keepMeetingLink := KeepMeetingLink{} | ||
addOriginalLink := AddOriginalLink{} | ||
|
||
sink, _ = keepDescription.Transform(source, sink) | ||
sink, _ = keepMeetingLink.Transform(source, sink) | ||
event, err := addOriginalLink.Transform(source, sink) | ||
|
||
assert.Nil(t, err) | ||
expectedEvent := models.Event{ | ||
ICalUID: "testId", | ||
ID: "testUid", | ||
Title: "CalendarSync Event", | ||
Description: "original event link: https://foo.com/bar?calendarId=testId\n\n############\n" + | ||
"original meeting link: https://meetinglink.de\n\n############\nbar", | ||
} | ||
|
||
assert.Equal(t, expectedEvent, event) | ||
} |