Skip to content

Commit

Permalink
feat: add timeFrame filter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Huck committed Apr 20, 2024
1 parent 6789b65 commit 314fc84
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions internal/filter/timeFrame_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package filter_test

import (
"testing"
"time"

"github.com/inovex/CalendarSync/internal/filter"
"github.com/inovex/CalendarSync/internal/models"
)

const timeFormat string = "2006-01-02T15:04"

// Events which match the start and end hour should be kept
func TestTimeFrameEventsFilter(t *testing.T) {
t1, err := time.Parse(timeFormat, "2024-01-01T13:00")
if err != nil {
t.Error(err)
}

t2, err := time.Parse(timeFormat, "2024-01-01T18:00")
if err != nil {
t.Error(err)
}

sourceEvents := []models.Event{
// Should be kept
{
ICalUID: "testId",
ID: "testUid",
Title: "test",
Description: "bar",
AllDay: true,
StartTime: t1,
},
// Should be filtered
{
ICalUID: "testId2",
ID: "testUid2",
Title: "Test 2",
Description: "bar",
AllDay: false,
StartTime: t2,
},
// Should be kept
{
ICalUID: "testId3",
ID: "testUid2",
Title: "foo",
Description: "bar",
StartTime: t1,
},
}

expectedSinkEvents := []models.Event{sourceEvents[0], sourceEvents[2]}

eventFilter := filter.TimeFrameEvents{
// Events outside 8 am and 5 pm will be filtered.
HourStart: 8,
HourEnd: 17,
}
checkEventFilter(t, eventFilter, sourceEvents, expectedSinkEvents)
}

0 comments on commit 314fc84

Please sign in to comment.