Skip to content

Commit

Permalink
fixed tests by changing return values for mock.EXPECT
Browse files Browse the repository at this point in the history
  • Loading branch information
karjo24 committed Sep 30, 2024
1 parent 8295e42 commit aae4370
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions api/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net/http"
"regexp"
"slices"
"strconv"
"strings"
Expand Down Expand Up @@ -368,15 +369,25 @@ func getMeiliSearchMock(t *testing.T, daoWrapper dao.DaoWrapper) *mock_tools.Moc
func(q interface{}, limit interface{}, searchType interface{}, courseFilter string, streamFilter string, subtitleFilter string) *meilisearch.MultiSearchResponse {
streams := make([]model.Stream, 0)
subtitles := make([]tools.MeiliSubtitles, 0)
idsAsStrings := strings.Split(streamFilter[len("courseID IN ["):len(streamFilter)-1], ",")
for _, idString := range idsAsStrings {
id, _ := strconv.Atoi(idString)
for _, stream := range testutils.AllStreamsForSearchTests {
if stream.CourseID == uint(id) {
streams = append(streams, stream)

// find indexes for id arrays
s, _ := regexp.Compile(`\[`)

Check failure on line 374 in api/search_test.go

View workflow job for this annotation

GitHub Actions / lint (./...)

regexpMust: for const patterns like `\[`, use regexp.MustCompile (gocritic)
c, _ := regexp.Compile(`]`)

Check failure on line 375 in api/search_test.go

View workflow job for this annotation

GitHub Actions / lint (./...)

regexpMust: for const patterns like `]`, use regexp.MustCompile (gocritic)
startIndexes := s.FindAllIndex([]byte(streamFilter), -1)
endIndexes := c.FindAllIndex([]byte(streamFilter), -1)

for i, startIndex := range startIndexes {
idsAsStrings := strings.Split(streamFilter[startIndex[1]:endIndexes[i][0]], ",")
for _, idString := range idsAsStrings {
id, _ := strconv.Atoi(idString)
for _, stream := range testutils.AllStreamsForSearchTests {
if stream.CourseID == uint(id) {
streams = append(streams, stream)
}
}
}
}

for _, subtitle := range testutils.AllSubtitlesForSearchTests {
if slices.ContainsFunc(streams, func(stream model.Stream) bool {
return stream.ID == subtitle.StreamID
Expand Down

0 comments on commit aae4370

Please sign in to comment.