Skip to content

Commit

Permalink
refactor: filter: deduplicate filter asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelEischer committed Nov 6, 2023
1 parent 5bac9e0 commit e8700ff
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
6 changes: 1 addition & 5 deletions internal/filter/allDayEvents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/inovex/CalendarSync/internal/filter"
"github.com/inovex/CalendarSync/internal/models"
"github.com/stretchr/testify/assert"
)

// All Day Events should be filtered
Expand Down Expand Up @@ -36,8 +35,5 @@ func TestAllDayEventsFilter(t *testing.T) {
expectedSinkEvents := []models.Event{sourceEvents[1], sourceEvents[2]}

eventFilter := filter.AllDayEvents{}

filteredEvents := FilterEvents(sourceEvents, eventFilter)

assert.Equal(t, expectedSinkEvents, filteredEvents)
checkEventFilter(t, eventFilter, sourceEvents, expectedSinkEvents)
}
5 changes: 1 addition & 4 deletions internal/filter/declinedEvents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/inovex/CalendarSync/internal/filter"
"github.com/inovex/CalendarSync/internal/models"
"github.com/stretchr/testify/assert"
)

// Declined Events should be filtered
Expand Down Expand Up @@ -37,7 +36,5 @@ func TestDeclinedEventsFilter(t *testing.T) {
expectedSinkEvents := []models.Event{sourceEvents[1], sourceEvents[2]}

eventFilter := filter.DeclinedEvents{}
filteredEvents := FilterEvents(sourceEvents, eventFilter)

assert.Equal(t, expectedSinkEvents, filteredEvents)
checkEventFilter(t, eventFilter, sourceEvents, expectedSinkEvents)
}
11 changes: 2 additions & 9 deletions internal/filter/regexTitle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/inovex/CalendarSync/internal/filter"
"github.com/inovex/CalendarSync/internal/models"
"github.com/stretchr/testify/assert"
)

var sourceEvents = []models.Event{
Expand Down Expand Up @@ -37,10 +36,7 @@ func TestRegexTitleFilter(t *testing.T) {
eventFilter := filter.RegexTitle{
ExludeRegexp: ".*test",
}

filteredEvents := FilterEvents(sourceEvents, eventFilter)

assert.Equal(t, expectedSinkEvents, filteredEvents)
checkEventFilter(t, eventFilter, sourceEvents, expectedSinkEvents)
}

// All Events should be there
Expand All @@ -50,8 +46,5 @@ func TestRegexTitleFilterEmptyRegex(t *testing.T) {
eventFilter := filter.RegexTitle{
ExludeRegexp: "",
}

filteredEvents := FilterEvents(sourceEvents, eventFilter)

assert.Equal(t, expectedSinkEvents, filteredEvents)
checkEventFilter(t, eventFilter, sourceEvents, expectedSinkEvents)
}
6 changes: 6 additions & 0 deletions internal/filter/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package filter_test
import (
"github.com/inovex/CalendarSync/internal/models"
"github.com/inovex/CalendarSync/internal/sync"
"github.com/stretchr/testify/assert"
)

// FilterEvents takes an array of events and a filter and executes the .Filter Method on each of the sourceEvents
Expand All @@ -15,3 +16,8 @@ func FilterEvents(sourceEvents []models.Event, filter sync.Filter) (filteredEven
}
return filteredEvents
}

func checkEventFilter(t assert.TestingT, filter sync.Filter, sourceEvents []models.Event, expectedEvents []models.Event) {
filteredEvents := FilterEvents(sourceEvents, filter)
assert.Equal(t, expectedEvents, filteredEvents)
}

0 comments on commit e8700ff

Please sign in to comment.