Monorepo for Tangled
tangled.org
1package models
2
3import (
4 "testing"
5)
6
7func TestIssueSearchOptions_HasSearchFilters(t *testing.T) {
8 tests := []struct {
9 name string
10 opts IssueSearchOptions
11 want bool
12 }{
13 {
14 name: "zero value returns false",
15 opts: IssueSearchOptions{},
16 want: false,
17 },
18 {
19 name: "non-filter fields only (RepoDid, IsOpen, Page) return false",
20 opts: IssueSearchOptions{RepoDid: "did:plc:abc"},
21 want: false,
22 },
23 {
24 name: "keyword set",
25 opts: IssueSearchOptions{Keywords: []string{"bug"}},
26 want: true,
27 },
28 {
29 name: "phrase set",
30 opts: IssueSearchOptions{Phrases: []string{"null pointer"}},
31 want: true,
32 },
33 {
34 name: "author did set",
35 opts: IssueSearchOptions{AuthorDid: "did:plc:abc"},
36 want: true,
37 },
38 {
39 name: "label set",
40 opts: IssueSearchOptions{Labels: []string{"bug"}},
41 want: true,
42 },
43 {
44 name: "label value set",
45 opts: IssueSearchOptions{LabelValues: []string{"priority:high"}},
46 want: true,
47 },
48 {
49 name: "negated keyword set",
50 opts: IssueSearchOptions{NegatedKeywords: []string{"wontfix"}},
51 want: true,
52 },
53 {
54 name: "negated phrase set",
55 opts: IssueSearchOptions{NegatedPhrases: []string{"not a bug"}},
56 want: true,
57 },
58 {
59 name: "negated label set",
60 opts: IssueSearchOptions{NegatedLabels: []string{"duplicate"}},
61 want: true,
62 },
63 {
64 name: "negated label value set",
65 opts: IssueSearchOptions{NegatedLabelValues: []string{"priority:low"}},
66 want: true,
67 },
68 {
69 name: "negated author did set",
70 opts: IssueSearchOptions{NegatedAuthorDids: []string{"did:plc:xyz"}},
71 want: true,
72 },
73 }
74
75 for _, tt := range tests {
76 t.Run(tt.name, func(t *testing.T) {
77 if got := tt.opts.HasSearchFilters(); got != tt.want {
78 t.Errorf("HasSearchFilters() = %v, want %v", got, tt.want)
79 }
80 })
81 }
82}
83
84func TestPullSearchOptions_HasSearchFilters(t *testing.T) {
85 tests := []struct {
86 name string
87 opts PullSearchOptions
88 want bool
89 }{
90 {
91 name: "zero value returns false",
92 opts: PullSearchOptions{},
93 want: false,
94 },
95 {
96 name: "non-filter fields only (RepoDid, State, Page) return false",
97 opts: PullSearchOptions{RepoDid: "did:plc:abc"},
98 want: false,
99 },
100 {
101 name: "keyword set",
102 opts: PullSearchOptions{Keywords: []string{"refactor"}},
103 want: true,
104 },
105 {
106 name: "phrase set",
107 opts: PullSearchOptions{Phrases: []string{"breaking change"}},
108 want: true,
109 },
110 {
111 name: "author did set",
112 opts: PullSearchOptions{AuthorDid: "did:plc:abc"},
113 want: true,
114 },
115 {
116 name: "label set",
117 opts: PullSearchOptions{Labels: []string{"enhancement"}},
118 want: true,
119 },
120 {
121 name: "label value set",
122 opts: PullSearchOptions{LabelValues: []string{"size:large"}},
123 want: true,
124 },
125 {
126 name: "negated keyword set",
127 opts: PullSearchOptions{NegatedKeywords: []string{"wip"}},
128 want: true,
129 },
130 {
131 name: "negated phrase set",
132 opts: PullSearchOptions{NegatedPhrases: []string{"do not merge"}},
133 want: true,
134 },
135 {
136 name: "negated label set",
137 opts: PullSearchOptions{NegatedLabels: []string{"blocked"}},
138 want: true,
139 },
140 {
141 name: "negated label value set",
142 opts: PullSearchOptions{NegatedLabelValues: []string{"size:small"}},
143 want: true,
144 },
145 {
146 name: "negated author did set",
147 opts: PullSearchOptions{NegatedAuthorDids: []string{"did:plc:xyz"}},
148 want: true,
149 },
150 }
151
152 for _, tt := range tests {
153 t.Run(tt.name, func(t *testing.T) {
154 if got := tt.opts.HasSearchFilters(); got != tt.want {
155 t.Errorf("HasSearchFilters() = %v, want %v", got, tt.want)
156 }
157 })
158 }
159}
160
161func TestRepoSearchOptions_HasSearchFilters(t *testing.T) {
162 tests := []struct {
163 name string
164 opts RepoSearchOptions
165 want bool
166 }{
167 {
168 name: "zero value returns false",
169 opts: RepoSearchOptions{},
170 want: false,
171 },
172 {
173 name: "non-filter fields only (Knot, Did, Page) return false",
174 opts: RepoSearchOptions{
175 Knot: "knot.example.com",
176 Did: "did:plc:abc",
177 },
178 want: false,
179 },
180 {
181 name: "keyword set",
182 opts: RepoSearchOptions{Keywords: []string{"parser"}},
183 want: true,
184 },
185 {
186 name: "phrase set",
187 opts: RepoSearchOptions{Phrases: []string{"http client"}},
188 want: true,
189 },
190 {
191 name: "language set",
192 opts: RepoSearchOptions{Language: "Go"},
193 want: true,
194 },
195 {
196 name: "topic set",
197 opts: RepoSearchOptions{Topics: []string{"networking"}},
198 want: true,
199 },
200 {
201 name: "negated keyword set",
202 opts: RepoSearchOptions{NegatedKeywords: []string{"deprecated"}},
203 want: true,
204 },
205 {
206 name: "negated phrase set",
207 opts: RepoSearchOptions{NegatedPhrases: []string{"work in progress"}},
208 want: true,
209 },
210 {
211 name: "negated topic set",
212 opts: RepoSearchOptions{NegatedTopics: []string{"archived"}},
213 want: true,
214 },
215 }
216
217 for _, tt := range tests {
218 t.Run(tt.name, func(t *testing.T) {
219 if got := tt.opts.HasSearchFilters(); got != tt.want {
220 t.Errorf("HasSearchFilters() = %v, want %v", got, tt.want)
221 }
222 })
223 }
224}