@@ -86,15 +86,15 @@ fn invalid_names() {
8686
8787 let bad_name = |name : & str , error_message : & str | {
8888 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 ) ;
9898 } ;
9999
100100 let error_message = "expected a valid crate name" ;
@@ -251,9 +251,13 @@ fn reject_new_krate_with_non_exact_dependency() {
251251 let crate_to_publish = PublishBuilder :: new ( "new_dep" )
252252 . version ( "1.0.0" )
253253 . 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+ ) ;
257261}
258262
259263#[ test]
@@ -696,19 +700,28 @@ fn bad_keywords() {
696700 let ( _, _, _, token) = TestApp :: init ( ) . with_token ( ) ;
697701 let crate_to_publish =
698702 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+ ) ;
702709
703710 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+ ) ;
707717
708718 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+ ) ;
712725}
713726
714727#[ test]
0 commit comments