@@ -691,4 +691,61 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
691691 expect ( response . data ) . toEqual ( "ok" ) ;
692692 } ) ;
693693 } ) ;
694+
695+ it ( "@octokit/rest.js/issues/1497/error-messages-on-validation-error" , function ( ) {
696+ const mock = fetchMock . sandbox ( ) . mock (
697+ "https://request-errors-test.com/repos/gr2m/sandbox/branches/gr2m-patch-1/protection" ,
698+ {
699+ status : 400 ,
700+ body : {
701+ message : "Validation failed" ,
702+ errors : [
703+ "Only organization repositories can have users and team restrictions" ,
704+ { resource : "Search" , field : "q" , code : "invalid" }
705+ ] ,
706+ documentation_url :
707+ "https://developer.github.com/v3/repos/branches/#update-branch-protection"
708+ }
709+ } ,
710+ {
711+ method : "PUT" ,
712+ headers : {
713+ accept : "application/vnd.github.luke-cage-preview+json" ,
714+ authorization : "token secret123"
715+ }
716+ }
717+ ) ;
718+
719+ return request ( "PUT /repos/:owner/:repo/branches/:branch/protection" , {
720+ baseUrl : "https://request-errors-test.com" ,
721+ mediaType : { previews : [ "luke-cage" ] } ,
722+ headers : {
723+ authorization : "token secret123"
724+ } ,
725+ owner : "gr2m" ,
726+ repo : "sandbox" ,
727+ branch : "gr2m-patch-1" ,
728+ required_status_checks : { strict : true , contexts : [ "wip" ] } ,
729+ enforce_admins : true ,
730+ required_pull_request_reviews : {
731+ required_approving_review_count : 1 ,
732+ dismiss_stale_reviews : true ,
733+ require_code_owner_reviews : true ,
734+ dismissal_restrictions : { users : [ ] , teams : [ ] }
735+ } ,
736+ restrictions : { users : [ ] , teams : [ ] } ,
737+ request : {
738+ fetch : mock
739+ }
740+ } )
741+ . then ( ( ) => {
742+ fail ( "This should return error." ) ;
743+ } )
744+ . catch ( error => {
745+ expect ( error ) . toHaveProperty (
746+ "message" ,
747+ `Validation failed: "Only organization repositories can have users and team restrictions", {"resource":"Search","field":"q","code":"invalid"}`
748+ ) ;
749+ } ) ;
750+ } ) ;
694751} ) ;
0 commit comments