@@ -86,15 +86,15 @@ fn invalid_names() {
86
86
87
87
let bad_name = |name : & str , error_message : & str | {
88
88
let crate_to_publish = PublishBuilder :: new ( name) . version ( "1.0.0" ) ;
89
- let json = token
90
- . enqueue_publish ( crate_to_publish )
91
- . bad_with_status ( StatusCode :: OK ) ;
92
-
93
- assert ! (
94
- json. errors[ 0 ] . detail . contains ( error_message , ) ,
95
- "{:?}" ,
96
- json . errors
97
- ) ;
89
+ let response = token. enqueue_publish ( crate_to_publish ) ;
90
+ response . assert_status ( StatusCode :: OK ) ;
91
+
92
+ let json = response . json ( ) ;
93
+ let json = json . as_object ( ) . unwrap ( ) ;
94
+ let errors = json. get ( " errors" ) . unwrap ( ) . as_array ( ) . unwrap ( ) ;
95
+ let first_error = errors . first ( ) . unwrap ( ) . as_object ( ) . unwrap ( ) ;
96
+ let detail = first_error . get ( "detail" ) . unwrap ( ) . as_str ( ) . unwrap ( ) ;
97
+ assert ! ( detail . contains ( error_message ) , "{:?}" , detail ) ;
98
98
} ;
99
99
100
100
let error_message = "expected a valid crate name" ;
@@ -251,9 +251,13 @@ fn reject_new_krate_with_non_exact_dependency() {
251
251
let crate_to_publish = PublishBuilder :: new ( "new_dep" )
252
252
. version ( "1.0.0" )
253
253
. dependency ( dependency) ;
254
- token
255
- . enqueue_publish ( crate_to_publish)
256
- . bad_with_status ( StatusCode :: OK ) ;
254
+
255
+ let response = token. enqueue_publish ( crate_to_publish) ;
256
+ response. assert_status ( StatusCode :: OK ) ;
257
+ assert_eq ! (
258
+ response. json( ) ,
259
+ json!( { "errors" : [ { "detail" : "no known crate named `foo_dep`" } ] } )
260
+ ) ;
257
261
}
258
262
259
263
#[ test]
@@ -696,19 +700,28 @@ fn bad_keywords() {
696
700
let ( _, _, _, token) = TestApp :: init ( ) . with_token ( ) ;
697
701
let crate_to_publish =
698
702
PublishBuilder :: new ( "foo_bad_key" ) . keyword ( "super-long-keyword-name-oh-no" ) ;
699
- token
700
- . enqueue_publish ( crate_to_publish)
701
- . bad_with_status ( StatusCode :: OK ) ;
703
+ let response = token. enqueue_publish ( crate_to_publish) ;
704
+ response. assert_status ( StatusCode :: OK ) ;
705
+ assert_eq ! (
706
+ response. json( ) ,
707
+ json!( { "errors" : [ { "detail" : "invalid upload request: invalid length 29, expected a keyword with less than 20 characters at line 1 column 221" } ] } )
708
+ ) ;
702
709
703
710
let crate_to_publish = PublishBuilder :: new ( "foo_bad_key" ) . keyword ( "?@?%" ) ;
704
- token
705
- . enqueue_publish ( crate_to_publish)
706
- . bad_with_status ( StatusCode :: OK ) ;
711
+ let response = token. enqueue_publish ( crate_to_publish) ;
712
+ response. assert_status ( StatusCode :: OK ) ;
713
+ assert_eq ! (
714
+ response. json( ) ,
715
+ json!( { "errors" : [ { "detail" : "invalid upload request: invalid value: string \" ?@?%\" , expected a valid keyword specifier at line 1 column 196" } ] } )
716
+ ) ;
707
717
708
718
let crate_to_publish = PublishBuilder :: new ( "foo_bad_key" ) . keyword ( "áccênts" ) ;
709
- token
710
- . enqueue_publish ( crate_to_publish)
711
- . bad_with_status ( StatusCode :: OK ) ;
719
+ let response = token. enqueue_publish ( crate_to_publish) ;
720
+ response. assert_status ( StatusCode :: OK ) ;
721
+ assert_eq ! (
722
+ response. json( ) ,
723
+ json!( { "errors" : [ { "detail" : "invalid upload request: invalid value: string \" áccênts\" , expected a valid keyword specifier at line 1 column 201" } ] } )
724
+ ) ;
712
725
}
713
726
714
727
#[ test]
0 commit comments