@@ -127,6 +127,47 @@ fn index_queries() {
127
127
assert_eq ! ( :: json:: <CrateList >( & mut response) . crates. len( ) , 0 ) ;
128
128
}
129
129
130
+ #[ test]
131
+ fn exact_match_first_on_queries ( ) {
132
+ let ( _b, app, middle) = :: app ( ) ;
133
+
134
+ let mut req = :: req ( app, Method :: Get , "/api/v1/crates" ) ;
135
+ let _ = :: mock_user ( & mut req, :: user ( "foo" ) ) ;
136
+ let mut krate = :: krate ( "foo" ) ;
137
+ krate. description = Some ( "bar baz" . to_string ( ) ) ;
138
+ let ( _, _) = :: mock_crate ( & mut req, krate. clone ( ) ) ;
139
+ let mut krate2 = :: krate ( "bar" ) ;
140
+ krate2. description = Some ( "foo baz foo baz" . to_string ( ) ) ;
141
+ let ( _, _) = :: mock_crate ( & mut req, krate2. clone ( ) ) ;
142
+ let mut krate3 = :: krate ( "baz" ) ;
143
+ krate3. description = Some ( "foo bar foo bar foo bar" . to_string ( ) ) ;
144
+ let ( _, _) = :: mock_crate ( & mut req, krate3. clone ( ) ) ;
145
+ let mut krate4 = :: krate ( "other" ) ;
146
+ krate4. description = Some ( "other" . to_string ( ) ) ;
147
+ let ( _, _) = :: mock_crate ( & mut req, krate4. clone ( ) ) ;
148
+
149
+ let mut response = ok_resp ! ( middle. call( req. with_query( "q=foo" ) ) ) ;
150
+ let json: CrateList = :: json ( & mut response) ;
151
+ assert_eq ! ( json. meta. total, 3 ) ;
152
+ assert_eq ! ( json. crates[ 0 ] . name, "foo" ) ;
153
+ assert_eq ! ( json. crates[ 1 ] . name, "baz" ) ;
154
+ assert_eq ! ( json. crates[ 2 ] . name, "bar" ) ;
155
+
156
+ let mut response = ok_resp ! ( middle. call( req. with_query( "q=bar" ) ) ) ;
157
+ let json: CrateList = :: json ( & mut response) ;
158
+ assert_eq ! ( json. meta. total, 3 ) ;
159
+ assert_eq ! ( json. crates[ 0 ] . name, "bar" ) ;
160
+ assert_eq ! ( json. crates[ 1 ] . name, "baz" ) ;
161
+ assert_eq ! ( json. crates[ 2 ] . name, "foo" ) ;
162
+
163
+ let mut response = ok_resp ! ( middle. call( req. with_query( "q=baz" ) ) ) ;
164
+ let json: CrateList = :: json ( & mut response) ;
165
+ assert_eq ! ( json. meta. total, 3 ) ;
166
+ assert_eq ! ( json. crates[ 0 ] . name, "baz" ) ;
167
+ assert_eq ! ( json. crates[ 1 ] . name, "bar" ) ;
168
+ assert_eq ! ( json. crates[ 2 ] . name, "foo" ) ;
169
+ }
170
+
130
171
#[ test]
131
172
fn show ( ) {
132
173
let ( _b, app, middle) = :: app ( ) ;
0 commit comments