-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathhelpers_test.go
95 lines (74 loc) · 2.37 KB
/
helpers_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package dao
import (
"github.com/content-services/content-sources-backend/pkg/api"
"github.com/content-services/content-sources-backend/pkg/utils"
"github.com/stretchr/testify/assert"
)
func (s *RepositorySuite) TestConvertSortByToSQL() {
t := s.T()
sortMap := map[string]string{
"name": "name",
"url": "url",
"package_count": "banana",
"status": "status",
}
asc := ":asc"
desc := ":desc"
result := convertSortByToSQL("name", sortMap, "name asc")
assert.Equal(t, "name asc", result)
result = convertSortByToSQL("notInSortMap", sortMap, "name asc")
assert.Equal(t, "name asc", result)
result = convertSortByToSQL("url"+asc, sortMap, "name asc")
assert.Equal(t, "url asc", result)
result = convertSortByToSQL("package_count", sortMap, "name asc")
assert.Equal(t, "banana asc", result)
result = convertSortByToSQL("status"+desc, sortMap, "name asc")
assert.Equal(t, "status desc", result)
result = convertSortByToSQL(" status , name:desc", sortMap, "name asc")
assert.Equal(t, "status asc, name desc", result)
}
func (s *RepositorySuite) TestCheckRequestUrlAndUuids() {
t := s.T()
urls := make([]string, 0)
uuids := make([]string, 0)
request := api.ContentUnitSearchRequest{
URLs: urls,
UUIDs: uuids,
Search: "test",
Limit: utils.Ptr(1),
}
result := checkRequestUrlAndUuids(request)
assert.Error(t, result)
request.UUIDs = []string{"aaaa-bbbb-cccc"}
result = checkRequestUrlAndUuids(request)
assert.NoError(t, result)
request.UUIDs = []string{}
request.URLs = []string{"http://example.com"}
result = checkRequestUrlAndUuids(request)
assert.NoError(t, result)
}
func (s *RepositorySuite) TestCheckRequestLimit() {
t := s.T()
request := api.ContentUnitSearchRequest{
URLs: []string{"http://example.com"},
UUIDs: []string{"aaaa-bbbb-cccc"},
Search: "test",
Limit: nil,
}
result := checkRequestLimit(request)
assert.Equal(t, utils.Ptr(100), result.Limit)
request.Limit = utils.Ptr(501)
result = checkRequestLimit(request)
assert.Equal(t, utils.Ptr(500), result.Limit)
}
func (s *RepositorySuite) TestHandleTailChars() {
t := s.T()
request := api.ContentUnitSearchRequest{
URLs: []string{"http://example.com"},
UUIDs: []string{"aaaa-bbbb-cccc"},
Search: "test",
Limit: nil,
}
result := handleTailChars(request)
assert.Equal(t, []string{"http://example.com", "http://example.com/"}, result)
}